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

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

Issue 2626433004: Move "common/config" common types into cfgtypes. (Closed)
Patch Set: Created 3 years, 11 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 | « logdog/client/butler/output/logdog/output.go ('k') | logdog/client/cli/main.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "fmt" 8 "fmt"
9 9
10 "github.com/luci/luci-go/client/environ" 10 "github.com/luci/luci-go/client/environ"
11 "github.com/luci/luci-go/common/config"
12 "github.com/luci/luci-go/common/errors" 11 "github.com/luci/luci-go/common/errors"
13 "github.com/luci/luci-go/logdog/client/butlerlib/streamclient" 12 "github.com/luci/luci-go/logdog/client/butlerlib/streamclient"
14 "github.com/luci/luci-go/logdog/common/types" 13 "github.com/luci/luci-go/logdog/common/types"
15 "github.com/luci/luci-go/logdog/common/viewer" 14 "github.com/luci/luci-go/logdog/common/viewer"
15 "github.com/luci/luci-go/luci_config/common/cfgtypes"
16 ) 16 )
17 17
18 // ErrNotBootstrapped is returned by Get when the current process is not 18 // ErrNotBootstrapped is returned by Get when the current process is not
19 // bootstrapped. 19 // bootstrapped.
20 var ErrNotBootstrapped = errors.New("not bootstrapped") 20 var ErrNotBootstrapped = errors.New("not bootstrapped")
21 21
22 // Bootstrap contains information about the configured bootstrap environment. 22 // Bootstrap contains information about the configured bootstrap environment.
23 // 23 //
24 // The bootstrap environment is loaded by probing the local application 24 // The bootstrap environment is loaded by probing the local application
25 // environment for variables emitted by a bootstrapping Butler. 25 // environment for variables emitted by a bootstrapping Butler.
26 type Bootstrap struct { 26 type Bootstrap struct {
27 // CoordinatorHost is the name of the upstream Coordinator host. 27 // CoordinatorHost is the name of the upstream Coordinator host.
28 // 28 //
29 // This is just the host name ("example.appspot.com"), not a full URL. 29 // This is just the host name ("example.appspot.com"), not a full URL.
30 // 30 //
31 // If this instance is not configured using a production Coordinator Out put, 31 // If this instance is not configured using a production Coordinator Out put,
32 // this will be empty. 32 // this will be empty.
33 CoordinatorHost string 33 CoordinatorHost string
34 34
35 // Project is the Butler instance project name. 35 // Project is the Butler instance project name.
36 » Project config.ProjectName 36 » Project cfgtypes.ProjectName
37 // Prefix is the Butler instance prefix. 37 // Prefix is the Butler instance prefix.
38 Prefix types.StreamName 38 Prefix types.StreamName
39 39
40 // Client is the streamclient for this instance, or nil if the Butler ha s no 40 // Client is the streamclient for this instance, or nil if the Butler ha s no
41 // streamserver. 41 // streamserver.
42 Client streamclient.Client 42 Client streamclient.Client
43 } 43 }
44 44
45 func getFromEnv(env environ.Environment, reg *streamclient.Registry) (*Bootstrap , error) { 45 func getFromEnv(env environ.Environment, reg *streamclient.Registry) (*Bootstrap , error) {
46 // Detect Butler by looking for EnvStreamPrefix in the envrironent. 46 // Detect Butler by looking for EnvStreamPrefix in the envrironent.
47 prefix, ok := env[EnvStreamPrefix] 47 prefix, ok := env[EnvStreamPrefix]
48 if !ok { 48 if !ok {
49 return nil, ErrNotBootstrapped 49 return nil, ErrNotBootstrapped
50 } 50 }
51 51
52 bs := &Bootstrap{ 52 bs := &Bootstrap{
53 CoordinatorHost: env[EnvCoordinatorHost], 53 CoordinatorHost: env[EnvCoordinatorHost],
54 Prefix: types.StreamName(prefix), 54 Prefix: types.StreamName(prefix),
55 » » Project: config.ProjectName(env[EnvStreamProject]), 55 » » Project: cfgtypes.ProjectName(env[EnvStreamProject]),
56 } 56 }
57 if err := bs.Prefix.Validate(); err != nil { 57 if err := bs.Prefix.Validate(); err != nil {
58 return nil, fmt.Errorf("bootstrap: failed to validate prefix %q: %s", prefix, err) 58 return nil, fmt.Errorf("bootstrap: failed to validate prefix %q: %s", prefix, err)
59 } 59 }
60 if err := bs.Project.Validate(); err != nil { 60 if err := bs.Project.Validate(); err != nil {
61 return nil, fmt.Errorf("bootstrap: failed to validate project %q : %s", bs.Project, err) 61 return nil, fmt.Errorf("bootstrap: failed to validate project %q : %s", bs.Project, err)
62 } 62 }
63 63
64 // If we have a stream server attached; instantiate a stream Client. 64 // If we have a stream server attached; instantiate a stream Client.
65 if p, ok := env[EnvStreamServerPath]; ok { 65 if p, ok := env[EnvStreamServerPath]; ok {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 if bs.Prefix == "" { 111 if bs.Prefix == "" {
112 return "", errors.New("no prefix is configured") 112 return "", errors.New("no prefix is configured")
113 } 113 }
114 114
115 paths := make([]types.StreamPath, len(streams)) 115 paths := make([]types.StreamPath, len(streams))
116 for i, s := range streams { 116 for i, s := range streams {
117 paths[i] = bs.Prefix.Join(types.StreamName(s.Properties().Name)) 117 paths[i] = bs.Prefix.Join(types.StreamName(s.Properties().Name))
118 } 118 }
119 return bs.GetViewerURL(paths...) 119 return bs.GetViewerURL(paths...)
120 } 120 }
OLDNEW
« no previous file with comments | « logdog/client/butler/output/logdog/output.go ('k') | logdog/client/cli/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698