| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "strings" | 10 "strings" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 "path to service account json file.") | 29 "path to service account json file.") |
| 30 r.Flags.StringVar(&r.host, "host", | 30 r.Flags.StringVar(&r.host, "host", |
| 31 "cr-buildbucket.appspot.com", | 31 "cr-buildbucket.appspot.com", |
| 32 "host for the buildbucket service instance.") | 32 "host for the buildbucket service instance.") |
| 33 } | 33 } |
| 34 | 34 |
| 35 func (r *baseCommandRun) makeService(ctx context.Context, a subcommands.Applicat
ion) (*buildbucket.Service, error) { | 35 func (r *baseCommandRun) makeService(ctx context.Context, a subcommands.Applicat
ion) (*buildbucket.Service, error) { |
| 36 if r.host == "" { | 36 if r.host == "" { |
| 37 return nil, errors.New("a host for the buildbucket service must
be provided") | 37 return nil, errors.New("a host for the buildbucket service must
be provided") |
| 38 } | 38 } |
| 39 » authenticator := auth.NewAuthenticator(ctx, auth.SilentLogin, auth.Optio
ns{ServiceAccountJSONPath: r.serviceAccountJSONPath}) | 39 |
| 40 » loginMode := auth.OptionalLogin |
| 41 » if r.serviceAccountJSONPath != "" { |
| 42 » » // if service account is specified, the request MUST be authenti
cated |
| 43 » » // otherwise it is optional. |
| 44 » » loginMode = auth.SilentLogin |
| 45 » } |
| 46 » authenticator := auth.NewAuthenticator(ctx, loginMode, auth.Options{Serv
iceAccountJSONPath: r.serviceAccountJSONPath}) |
| 40 | 47 |
| 41 client, err := authenticator.Client() | 48 client, err := authenticator.Client() |
| 42 if err != nil { | 49 if err != nil { |
| 43 logging.Errorf(ctx, "could not create client: %s", err) | 50 logging.Errorf(ctx, "could not create client: %s", err) |
| 44 return nil, err | 51 return nil, err |
| 45 } | 52 } |
| 46 logging.Debugf(ctx, "client created") | 53 logging.Debugf(ctx, "client created") |
| 47 | 54 |
| 48 service, err := buildbucket.New(client) | 55 service, err := buildbucket.New(client) |
| 49 if err != nil { | 56 if err != nil { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 66 case host == "localhost", strings.HasPrefix(host, "localhost:"): | 73 case host == "localhost", strings.HasPrefix(host, "localhost:"): |
| 67 case host == "127.0.0.1", strings.HasPrefix(host, "127.0.0.1:"): | 74 case host == "127.0.0.1", strings.HasPrefix(host, "127.0.0.1:"): |
| 68 case host == "[::1]", strings.HasPrefix(host, "[::1]:"): | 75 case host == "[::1]", strings.HasPrefix(host, "[::1]:"): |
| 69 case strings.HasPrefix(host, ":"): | 76 case strings.HasPrefix(host, ":"): |
| 70 | 77 |
| 71 default: | 78 default: |
| 72 return false | 79 return false |
| 73 } | 80 } |
| 74 return true | 81 return true |
| 75 } | 82 } |
| OLD | NEW |