зеркало из https://github.com/mozilla/mig.git
[minor] capture client version in API logs
This commit is contained in:
Родитель
cd27108a5b
Коммит
2b46b3d207
|
@ -18,6 +18,9 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// build version
|
||||
var version string
|
||||
|
||||
var ctx Context
|
||||
|
||||
func main() {
|
||||
|
@ -27,8 +30,14 @@ func main() {
|
|||
|
||||
// command line options
|
||||
var config = flag.String("c", "/etc/mig/api.cfg", "Load configuration from file")
|
||||
var showversion = flag.Bool("V", false, "Show build version and exit")
|
||||
flag.Parse()
|
||||
|
||||
if *showversion {
|
||||
fmt.Println(version)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// The context initialization takes care of parsing the configuration,
|
||||
// and creating connections to database, syslog, ...
|
||||
fmt.Fprintf(os.Stderr, "Initializing API context...")
|
||||
|
@ -215,9 +224,9 @@ func respond(code int, response interface{}, respWriter http.ResponseWriter, r *
|
|||
|
||||
ctx.Channels.Log <- mig.Log{
|
||||
OpID: getOpID(r),
|
||||
Desc: fmt.Sprintf("src=%s auth=[%s %.0f] %s %s %s resp_code=%d resp_size=%d",
|
||||
Desc: fmt.Sprintf("src=%s auth=[%s %.0f] %s %s %s resp_code=%d resp_size=%d user-agent=%s",
|
||||
remoteAddresses(r), getInvName(r), getInvID(r), r.Method, r.Proto,
|
||||
r.URL.String(), code, len(body)),
|
||||
r.URL.String(), code, len(body), r.UserAgent()),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -31,16 +31,17 @@ var version string
|
|||
// A Client provides all the needed functionalities to interact with the MIG API.
|
||||
// It should be initialized with a proper configuration file.
|
||||
type Client struct {
|
||||
API *http.Client
|
||||
Token string
|
||||
Conf Configuration
|
||||
API *http.Client
|
||||
Token string
|
||||
Conf Configuration
|
||||
Version string
|
||||
}
|
||||
|
||||
// Configuration stores the live configuration and global parameters of a client
|
||||
type Configuration struct {
|
||||
API ApiConf
|
||||
Homedir string
|
||||
GPG GpgConf
|
||||
API ApiConf // location of the MIG API
|
||||
Homedir string // location of the user's home directory
|
||||
GPG GpgConf // location of the user's secring
|
||||
}
|
||||
|
||||
type ApiConf struct {
|
||||
|
@ -54,8 +55,9 @@ type GpgConf struct {
|
|||
}
|
||||
|
||||
// NewClient initiates a new instance of a Client
|
||||
func NewClient(conf Configuration) Client {
|
||||
func NewClient(conf Configuration, version string) Client {
|
||||
var cli Client
|
||||
cli.Version = version
|
||||
cli.Conf = conf
|
||||
tr := &http.Transport{
|
||||
DisableCompression: false,
|
||||
|
@ -140,7 +142,7 @@ func (cli Client) Do(r *http.Request) (resp *http.Response, err error) {
|
|||
err = fmt.Errorf("Do() -> %v", e)
|
||||
}
|
||||
}()
|
||||
r.Header.Set("User-Agent", "MIG Client v"+version)
|
||||
r.Header.Set("User-Agent", "MIG Client "+cli.Version)
|
||||
if cli.Token == "" {
|
||||
cli.Token, err = cli.MakeSignedToken()
|
||||
if err != nil {
|
||||
|
|
|
@ -15,6 +15,9 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// build version
|
||||
var version string
|
||||
|
||||
func usage() {
|
||||
fmt.Printf(`%s - Mozilla InvestiGator command line client
|
||||
usage: %s <module> <global options> <module parameters>
|
||||
|
@ -87,6 +90,11 @@ func main() {
|
|||
usage()
|
||||
}
|
||||
|
||||
if len(os.Args) < 2 || os.Args[1] == "-V" {
|
||||
fmt.Println(version)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// when reading the action from a file, go directly to launch
|
||||
if os.Args[1] == "-i" {
|
||||
err = fs.Parse(os.Args[1:])
|
||||
|
@ -162,7 +170,7 @@ readytolaunch:
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cli = client.NewClient(conf)
|
||||
cli = client.NewClient(conf, "cmd-"+version)
|
||||
|
||||
// set the validity 60 second in the past to deal with clock skew
|
||||
a.ValidFrom = time.Now().Add(-60 * time.Second).UTC()
|
||||
|
|
|
@ -19,7 +19,8 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var useShortNames bool
|
||||
// build version
|
||||
var version string
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
|
@ -32,8 +33,14 @@ func main() {
|
|||
// command line options
|
||||
var config = flag.String("c", homedir+"/.migrc", "Load configuration from file")
|
||||
var quiet = flag.Bool("q", false, "don't display banners and prompts")
|
||||
var showversion = flag.Bool("V", false, "show build version and exit")
|
||||
flag.Parse()
|
||||
|
||||
if *showversion {
|
||||
fmt.Println(version)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// silence extra output
|
||||
out := os.Stdout
|
||||
if *quiet {
|
||||
|
@ -63,7 +70,7 @@ func main() {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cli := client.NewClient(conf)
|
||||
cli := client.NewClient(conf, "console-"+version)
|
||||
// print platform status
|
||||
err = printStatus(cli)
|
||||
if err != nil {
|
||||
|
|
|
@ -17,6 +17,9 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// build version
|
||||
var version string
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
defer func() {
|
||||
|
@ -45,8 +48,14 @@ func main() {
|
|||
var validfrom = flag.String("validfrom", "now", "(optional) set an ISO8601 date the action will be valid from. If unset, use 'now'.")
|
||||
var expireafter = flag.String("expireafter", "30m", "(optional) set a validity duration for the action. If unset, use '30m'.")
|
||||
var nolaunch = flag.Bool("nolaunch", false, "Don't launch the action. Print it and exit. (implies '-p')")
|
||||
var showversion = flag.Bool("V", false, "Show build version and exit")
|
||||
flag.Parse()
|
||||
|
||||
if *showversion {
|
||||
fmt.Println(version)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if *nolaunch {
|
||||
*pretty = true
|
||||
}
|
||||
|
@ -56,7 +65,7 @@ func main() {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cli := client.NewClient(conf)
|
||||
cli := client.NewClient(conf, "generator-"+version)
|
||||
|
||||
// We need a file to load the action from
|
||||
if *file == "/path/to/file" {
|
||||
|
|
Загрузка…
Ссылка в новой задаче