Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: client/cmd/buildbucket/base_command.go

Issue 2104013002: buildbucket: use OptionalLogin if service account is not passed (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698