go.fuchsia.dev/infra@v0.0.0-20240507153436-9b593402251b/buildbucket/builds.go (about) 1 // Copyright 2019 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package buildbucket 6 7 import ( 8 "context" 9 "fmt" 10 11 "go.chromium.org/luci/auth" 12 buildbucketpb "go.chromium.org/luci/buildbucket/proto" 13 "go.chromium.org/luci/grpc/prpc" 14 ) 15 16 // DefaultHost is the default Buildbucket server. 17 const DefaultHost = "cr-buildbucket.appspot.com" 18 19 // NewBuildsClient returns a new BuildsClient. 20 func NewBuildsClient(ctx context.Context, host string, opts auth.Options) (buildbucketpb.BuildsClient, error) { 21 authenticator := auth.NewAuthenticator(ctx, auth.SilentLogin, opts) 22 httpClient, err := authenticator.Client() 23 if err != nil { 24 return nil, fmt.Errorf("failed to get authenticated http client: %w", err) 25 } 26 27 return buildbucketpb.NewBuildsPRPCClient(&prpc.Client{ 28 C: httpClient, 29 Host: host, 30 }), nil 31 }