Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "flag" | 9 "flag" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 "github.com/luci/luci-go/common/auth" | 22 "github.com/luci/luci-go/common/auth" |
| 23 "github.com/luci/luci-go/common/clock/clockflag" | 23 "github.com/luci/luci-go/common/clock/clockflag" |
| 24 "github.com/luci/luci-go/common/flag/multiflag" | 24 "github.com/luci/luci-go/common/flag/multiflag" |
| 25 "github.com/luci/luci-go/common/gcloud/pubsub" | 25 "github.com/luci/luci-go/common/gcloud/pubsub" |
| 26 "github.com/luci/luci-go/common/logdog/types" | 26 "github.com/luci/luci-go/common/logdog/types" |
| 27 log "github.com/luci/luci-go/common/logging" | 27 log "github.com/luci/luci-go/common/logging" |
| 28 "github.com/luci/luci-go/common/logging/gologger" | 28 "github.com/luci/luci-go/common/logging/gologger" |
| 29 "github.com/luci/luci-go/common/paniccatcher" | 29 "github.com/luci/luci-go/common/paniccatcher" |
| 30 "github.com/maruel/subcommands" | 30 "github.com/maruel/subcommands" |
| 31 "golang.org/x/net/context" | 31 "golang.org/x/net/context" |
| 32 "golang.org/x/oauth2" | |
| 32 ) | 33 ) |
| 33 | 34 |
| 34 const ( | 35 const ( |
| 35 // flagErrorReturnCode is returned when there is an error with the Butle r's | 36 // flagErrorReturnCode is returned when there is an error with the Butle r's |
| 36 // command-line configuration. | 37 // command-line configuration. |
| 37 configErrorReturnCode = 2 | 38 configErrorReturnCode = 2 |
| 38 | 39 |
| 39 // runtimeErrorReturnCode is returned when the execution fails due to a Butler | 40 // runtimeErrorReturnCode is returned when the execution fails due to a Butler |
| 40 // error. This is intended to help differentiate Butler errors from | 41 // error. This is intended to help differentiate Butler errors from |
| 41 // passthrough bootstrapped subprocess errors. | 42 // passthrough bootstrapped subprocess errors. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 "cpuprofile", "", "If specified, enables CPU profiling and profi les to the specified path.") | 111 "cpuprofile", "", "If specified, enables CPU profiling and profi les to the specified path.") |
| 111 fs.IntVar(&a.butler.OutputWorkers, "output-workers", butler.DefaultOutpu tWorkers, | 112 fs.IntVar(&a.butler.OutputWorkers, "output-workers", butler.DefaultOutpu tWorkers, |
| 112 "The maximum number of parallel output dispatches.") | 113 "The maximum number of parallel output dispatches.") |
| 113 fs.Var(&a.maxBufferAge, "output-max-buffer-age", | 114 fs.Var(&a.maxBufferAge, "output-max-buffer-age", |
| 114 "Send buffered messages if they've been held for longer than thi s period.") | 115 "Send buffered messages if they've been held for longer than thi s period.") |
| 115 fs.BoolVar(&a.noBufferLogs, "output-no-buffer", false, | 116 fs.BoolVar(&a.noBufferLogs, "output-no-buffer", false, |
| 116 "If true, dispatch logs immediately. Setting this flag simplifie s output at the expense "+ | 117 "If true, dispatch logs immediately. Setting this flag simplifie s output at the expense "+ |
| 117 "of wire-format efficiency.") | 118 "of wire-format efficiency.") |
| 118 } | 119 } |
| 119 | 120 |
| 121 func (a *application) authenticator(ctx context.Context) (*auth.Authenticator, e rror) { | |
| 122 opts, err := a.authFlags.Options() | |
| 123 if err != nil { | |
| 124 return nil, err | |
| 125 } | |
| 126 opts.Context = ctx | |
| 127 return auth.NewAuthenticator(auth.SilentLogin, opts), nil | |
| 128 } | |
| 129 | |
| 120 func (a *application) authenticatedClient(ctx context.Context) (*http.Client, er ror) { | 130 func (a *application) authenticatedClient(ctx context.Context) (*http.Client, er ror) { |
| 121 if a.client == nil { | 131 if a.client == nil { |
| 122 » » opts, err := a.authFlags.Options() | 132 » » authenticator, err := a.authenticator(ctx) |
| 123 if err != nil { | 133 if err != nil { |
| 124 return nil, err | 134 return nil, err |
| 125 } | 135 } |
| 126 opts.Context = ctx | |
| 127 | 136 |
| 128 » » client, err := auth.NewAuthenticator(auth.SilentLogin, opts).Cli ent() | 137 » » client, err := authenticator.Client() |
| 129 if err != nil { | 138 if err != nil { |
| 130 return nil, err | 139 return nil, err |
| 131 } | 140 } |
| 132 a.client = client | 141 a.client = client |
| 133 } | 142 } |
| 134 return a.client, nil | 143 return a.client, nil |
| 135 } | 144 } |
| 136 | 145 |
| 146 func (a *application) authenticatedTokenSource(ctx context.Context) (oauth2.Toke nSource, error) { | |
|
Vadim Sh.
2016/03/29 19:02:37
nit: just tokenSource(). It can't be "unauthentica
dnj
2016/03/29 19:27:20
Done.
| |
| 147 authenticator, err := a.authenticator(ctx) | |
| 148 if err != nil { | |
| 149 return nil, err | |
| 150 } | |
| 151 return authenticator.TokenSource(), nil | |
| 152 } | |
| 153 | |
| 137 func (a *application) configOutput() (output.Output, error) { | 154 func (a *application) configOutput() (output.Output, error) { |
| 138 factory := a.outputConfig.getFactory() | 155 factory := a.outputConfig.getFactory() |
| 139 if factory == nil { | 156 if factory == nil { |
| 140 return nil, errors.New("main: No output is configured") | 157 return nil, errors.New("main: No output is configured") |
| 141 } | 158 } |
| 142 | 159 |
| 143 output, err := factory.configOutput(a) | 160 output, err := factory.configOutput(a) |
| 144 if err != nil { | 161 if err != nil { |
| 145 return nil, err | 162 return nil, err |
| 146 } | 163 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 | 355 |
| 339 paniccatcher.Do(func() { | 356 paniccatcher.Do(func() { |
| 340 rc = mainImpl(ctx, os.Args[1:]) | 357 rc = mainImpl(ctx, os.Args[1:]) |
| 341 }, func(p *paniccatcher.Panic) { | 358 }, func(p *paniccatcher.Panic) { |
| 342 log.Fields{ | 359 log.Fields{ |
| 343 "panic.error": p.Reason, | 360 "panic.error": p.Reason, |
| 344 }.Errorf(ctx, "Panic caught in main:\n%s", p.Stack) | 361 }.Errorf(ctx, "Panic caught in main:\n%s", p.Stack) |
| 345 rc = runtimeErrorReturnCode | 362 rc = runtimeErrorReturnCode |
| 346 }) | 363 }) |
| 347 } | 364 } |
| OLD | NEW |