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

Side by Side Diff: logdog/client/butlerlib/bootstrap/bootstrap.go

Issue 2456673003: Butler: export Coordinator host in environment. (Closed)
Patch Set: Relieve suspense. Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 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 bootstrap 5 package bootstrap
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "fmt" 9 "fmt"
10 10
11 "github.com/luci/luci-go/client/environ" 11 "github.com/luci/luci-go/client/environ"
12 "github.com/luci/luci-go/common/config" 12 "github.com/luci/luci-go/common/config"
13 "github.com/luci/luci-go/logdog/client/butlerlib/streamclient" 13 "github.com/luci/luci-go/logdog/client/butlerlib/streamclient"
14 "github.com/luci/luci-go/logdog/common/types" 14 "github.com/luci/luci-go/logdog/common/types"
15 ) 15 )
16 16
17 // ErrNotBootstrapped is returned by Get when the current process is not 17 // ErrNotBootstrapped is returned by Get when the current process is not
18 // bootstrapped. 18 // bootstrapped.
19 var ErrNotBootstrapped = errors.New("not bootstrapped") 19 var ErrNotBootstrapped = errors.New("not bootstrapped")
20 20
21 // Bootstrap contains information about the 21 // Bootstrap contains information about the configured bootstrap environment.
22 //
23 // The bootstrap environment is loaded by probing the local application
24 // environment for variables emitted by a bootstrapping Butler.
22 type Bootstrap struct { 25 type Bootstrap struct {
26 // CoordinatorHost is the name of the upstream Coordinator host.
27 //
28 // This is just the host name ("example.appspot.com"), not a full URL.
29 //
30 // If this instance is not configured using a production Coordinator Out put,
31 // this will be empty.
32 CoordinatorHost string
33
23 // Project is the Butler instance project name. 34 // Project is the Butler instance project name.
24 Project config.ProjectName 35 Project config.ProjectName
25 // Prefix is the Butler instance prefix. 36 // Prefix is the Butler instance prefix.
26 Prefix types.StreamName 37 Prefix types.StreamName
27 38
28 // Client is the streamclient for this instance, or nil if the Butler ha s no 39 // Client is the streamclient for this instance, or nil if the Butler ha s no
29 // streamserver. 40 // streamserver.
30 Client streamclient.Client 41 Client streamclient.Client
31 } 42 }
32 43
33 func getFromEnv(env environ.Environment, reg *streamclient.Registry) (*Bootstrap , error) { 44 func getFromEnv(env environ.Environment, reg *streamclient.Registry) (*Bootstrap , error) {
34 // Detect Butler by looking for EnvStreamPrefix in the envrironent. 45 // Detect Butler by looking for EnvStreamPrefix in the envrironent.
35 prefix, ok := env[EnvStreamPrefix] 46 prefix, ok := env[EnvStreamPrefix]
36 if !ok { 47 if !ok {
37 return nil, ErrNotBootstrapped 48 return nil, ErrNotBootstrapped
38 } 49 }
39 50
40 bs := &Bootstrap{ 51 bs := &Bootstrap{
41 » » Prefix: types.StreamName(prefix), 52 » » CoordinatorHost: env[EnvCoordinatorHost],
42 » » Project: config.ProjectName(env[EnvStreamProject]), 53 » » Prefix: types.StreamName(prefix),
54 » » Project: config.ProjectName(env[EnvStreamProject]),
43 } 55 }
44 if err := bs.Prefix.Validate(); err != nil { 56 if err := bs.Prefix.Validate(); err != nil {
45 return nil, fmt.Errorf("bootstrap: failed to validate prefix %q: %s", prefix, err) 57 return nil, fmt.Errorf("bootstrap: failed to validate prefix %q: %s", prefix, err)
46 } 58 }
47 if err := bs.Project.Validate(); err != nil { 59 if err := bs.Project.Validate(); err != nil {
48 return nil, fmt.Errorf("bootstrap: failed to validate project %q : %s", bs.Project, err) 60 return nil, fmt.Errorf("bootstrap: failed to validate project %q : %s", bs.Project, err)
49 } 61 }
50 62
51 // If we have a stream server attached; instantiate a stream Client. 63 // If we have a stream server attached; instantiate a stream Client.
52 if p, ok := env[EnvStreamServerPath]; ok { 64 if p, ok := env[EnvStreamServerPath]; ok {
53 c, err := reg.NewClient(p) 65 c, err := reg.NewClient(p)
54 if err != nil { 66 if err != nil {
55 return nil, fmt.Errorf("bootstrap: failed to create stre am client [%s]: %s", p, err) 67 return nil, fmt.Errorf("bootstrap: failed to create stre am client [%s]: %s", p, err)
56 } 68 }
57 bs.Client = c 69 bs.Client = c
58 } 70 }
59 71
60 return bs, nil 72 return bs, nil
61 } 73 }
62 74
63 // Get loads a Bootstrap instance from the environment. It will return an error 75 // Get loads a Bootstrap instance from the environment. It will return an error
64 // if the bootstrap data is invalid, and will return ErrNotBootstrapped if the 76 // if the bootstrap data is invalid, and will return ErrNotBootstrapped if the
65 // current process is not bootstrapped. 77 // current process is not bootstrapped.
66 func Get() (*Bootstrap, error) { 78 func Get() (*Bootstrap, error) {
67 return getFromEnv(environ.Get(), streamclient.DefaultRegistry) 79 return getFromEnv(environ.Get(), streamclient.DefaultRegistry)
68 } 80 }
OLDNEW
« no previous file with comments | « logdog/client/butler/bootstrap/env.go ('k') | logdog/client/butlerlib/bootstrap/bootstrap_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698