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

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

Issue 2456673003: Butler: export Coordinator host in environment. (Closed)
Patch Set: 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
Vadim Sh. 2016/10/27 04:48:05 about the what?
22 type Bootstrap struct { 22 type Bootstrap struct {
23 // CoordinatorHost is the name of the upstream Coordinator host.
24 //
25 // This is just the host name ("example.appspot.com"), not a full URL.
26 //
27 // If this instance is not configured using a production Coordinator Out put,
28 // this will be empty.
29 CoordinatorHost string
30
23 // Project is the Butler instance project name. 31 // Project is the Butler instance project name.
24 Project config.ProjectName 32 Project config.ProjectName
25 // Prefix is the Butler instance prefix. 33 // Prefix is the Butler instance prefix.
26 Prefix types.StreamName 34 Prefix types.StreamName
27 35
28 // Client is the streamclient for this instance, or nil if the Butler ha s no 36 // Client is the streamclient for this instance, or nil if the Butler ha s no
29 // streamserver. 37 // streamserver.
30 Client streamclient.Client 38 Client streamclient.Client
31 } 39 }
32 40
33 func getFromEnv(env environ.Environment, reg *streamclient.Registry) (*Bootstrap , error) { 41 func getFromEnv(env environ.Environment, reg *streamclient.Registry) (*Bootstrap , error) {
34 // Detect Butler by looking for EnvStreamPrefix in the envrironent. 42 // Detect Butler by looking for EnvStreamPrefix in the envrironent.
35 prefix, ok := env[EnvStreamPrefix] 43 prefix, ok := env[EnvStreamPrefix]
36 if !ok { 44 if !ok {
37 return nil, ErrNotBootstrapped 45 return nil, ErrNotBootstrapped
38 } 46 }
39 47
40 bs := &Bootstrap{ 48 bs := &Bootstrap{
41 » » Prefix: types.StreamName(prefix), 49 » » CoordinatorHost: env[EnvCoordinatorHost],
42 » » Project: config.ProjectName(env[EnvStreamProject]), 50 » » Prefix: types.StreamName(prefix),
51 » » Project: config.ProjectName(env[EnvStreamProject]),
43 } 52 }
44 if err := bs.Prefix.Validate(); err != nil { 53 if err := bs.Prefix.Validate(); err != nil {
45 return nil, fmt.Errorf("bootstrap: failed to validate prefix %q: %s", prefix, err) 54 return nil, fmt.Errorf("bootstrap: failed to validate prefix %q: %s", prefix, err)
46 } 55 }
47 if err := bs.Project.Validate(); err != nil { 56 if err := bs.Project.Validate(); err != nil {
48 return nil, fmt.Errorf("bootstrap: failed to validate project %q : %s", bs.Project, err) 57 return nil, fmt.Errorf("bootstrap: failed to validate project %q : %s", bs.Project, err)
49 } 58 }
50 59
51 // If we have a stream server attached; instantiate a stream Client. 60 // If we have a stream server attached; instantiate a stream Client.
52 if p, ok := env[EnvStreamServerPath]; ok { 61 if p, ok := env[EnvStreamServerPath]; ok {
53 c, err := reg.NewClient(p) 62 c, err := reg.NewClient(p)
54 if err != nil { 63 if err != nil {
55 return nil, fmt.Errorf("bootstrap: failed to create stre am client [%s]: %s", p, err) 64 return nil, fmt.Errorf("bootstrap: failed to create stre am client [%s]: %s", p, err)
56 } 65 }
57 bs.Client = c 66 bs.Client = c
58 } 67 }
59 68
60 return bs, nil 69 return bs, nil
61 } 70 }
62 71
63 // Get loads a Bootstrap instance from the environment. It will return an error 72 // 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 73 // if the bootstrap data is invalid, and will return ErrNotBootstrapped if the
65 // current process is not bootstrapped. 74 // current process is not bootstrapped.
66 func Get() (*Bootstrap, error) { 75 func Get() (*Bootstrap, error) {
67 return getFromEnv(environ.Get(), streamclient.DefaultRegistry) 76 return getFromEnv(environ.Get(), streamclient.DefaultRegistry)
68 } 77 }
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