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

Unified Diff: client/cmd/buildbucket/base_command.go

Issue 2227113002: Update bulidbucket client (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: rebase Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « buildbucket/client/cmd/buildbucket/put.go ('k') | client/cmd/buildbucket/cancel.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/cmd/buildbucket/base_command.go
diff --git a/client/cmd/buildbucket/base_command.go b/client/cmd/buildbucket/base_command.go
deleted file mode 100644
index 22d9788972ebd0080e999c721ec78746ea548c77..0000000000000000000000000000000000000000
--- a/client/cmd/buildbucket/base_command.go
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2016 The LUCI Authors. All rights reserved.
-// Use of this source code is governed under the Apache License, Version 2.0
-// that can be found in the LICENSE file.
-
-package main
-
-import (
- "errors"
- "fmt"
- "strings"
-
- "github.com/maruel/subcommands"
- "golang.org/x/net/context"
-
- "github.com/luci/luci-go/common/api/buildbucket/buildbucket/v1"
- "github.com/luci/luci-go/common/auth"
- "github.com/luci/luci-go/common/logging"
-)
-
-type baseCommandRun struct {
- subcommands.CommandRunBase
- serviceAccountJSONPath string
- host string
-}
-
-func (r *baseCommandRun) SetDefaultFlags() {
- r.Flags.StringVar(&r.serviceAccountJSONPath, "service-account-json",
- "",
- "path to service account json file.")
- r.Flags.StringVar(&r.host, "host",
- "cr-buildbucket.appspot.com",
- "host for the buildbucket service instance.")
-}
-
-func (r *baseCommandRun) makeService(ctx context.Context, a subcommands.Application) (*buildbucket.Service, error) {
- if r.host == "" {
- return nil, errors.New("a host for the buildbucket service must be provided")
- }
-
- loginMode := auth.OptionalLogin
- if r.serviceAccountJSONPath != "" {
- // if service account is specified, the request MUST be authenticated
- // otherwise it is optional.
- loginMode = auth.SilentLogin
- }
- authenticator := auth.NewAuthenticator(ctx, loginMode, auth.Options{ServiceAccountJSONPath: r.serviceAccountJSONPath})
-
- client, err := authenticator.Client()
- if err != nil {
- logging.Errorf(ctx, "could not create client: %s", err)
- return nil, err
- }
- logging.Debugf(ctx, "client created")
-
- service, err := buildbucket.New(client)
- if err != nil {
- logging.Errorf(ctx, "could not create service: %s", err)
- return nil, err
- }
-
- protocol := "https"
- if isLocalHost(r.host) {
- protocol = "http"
- }
-
- service.BasePath = fmt.Sprintf("%s://%s/api/buildbucket/v1/", protocol, r.host)
- return service, nil
-}
-
-// TODO(robertocn): Dedup this code copied from grpc/cmd/rpc
-func isLocalHost(host string) bool {
- switch {
- case host == "localhost", strings.HasPrefix(host, "localhost:"):
- case host == "127.0.0.1", strings.HasPrefix(host, "127.0.0.1:"):
- case host == "[::1]", strings.HasPrefix(host, "[::1]:"):
- case strings.HasPrefix(host, ":"):
-
- default:
- return false
- }
- return true
-}
« no previous file with comments | « buildbucket/client/cmd/buildbucket/put.go ('k') | client/cmd/buildbucket/cancel.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698