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

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

Issue 2456953003: LogDog: Update client/bootstrap to generate URLs. (Closed)
Patch Set: Winders 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"
9 "fmt" 8 "fmt"
10 9
11 "github.com/luci/luci-go/client/environ" 10 "github.com/luci/luci-go/client/environ"
12 "github.com/luci/luci-go/common/config" 11 "github.com/luci/luci-go/common/config"
12 "github.com/luci/luci-go/common/errors"
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 "github.com/luci/luci-go/logdog/common/viewer"
15 ) 16 )
16 17
17 // ErrNotBootstrapped is returned by Get when the current process is not 18 // ErrNotBootstrapped is returned by Get when the current process is not
18 // bootstrapped. 19 // bootstrapped.
19 var ErrNotBootstrapped = errors.New("not bootstrapped") 20 var ErrNotBootstrapped = errors.New("not bootstrapped")
20 21
21 // Bootstrap contains information about the configured bootstrap environment. 22 // Bootstrap contains information about the configured bootstrap environment.
22 // 23 //
23 // The bootstrap environment is loaded by probing the local application 24 // The bootstrap environment is loaded by probing the local application
24 // environment for variables emitted by a bootstrapping Butler. 25 // environment for variables emitted by a bootstrapping Butler.
(...skipping 30 matching lines...) Expand all
55 } 56 }
56 if err := bs.Prefix.Validate(); err != nil { 57 if err := bs.Prefix.Validate(); err != nil {
57 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)
58 } 59 }
59 if err := bs.Project.Validate(); err != nil { 60 if err := bs.Project.Validate(); err != nil {
60 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)
61 } 62 }
62 63
63 // If we have a stream server attached; instantiate a stream Client. 64 // If we have a stream server attached; instantiate a stream Client.
64 if p, ok := env[EnvStreamServerPath]; ok { 65 if p, ok := env[EnvStreamServerPath]; ok {
65 » » c, err := reg.NewClient(p) 66 » » if err := bs.initializeClient(p, reg); err != nil {
66 » » if err != nil {
67 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)
68 } 68 }
69 bs.Client = c
70 } 69 }
71 70
72 return bs, nil 71 return bs, nil
73 } 72 }
74 73
74 func (bs *Bootstrap) initializeClient(v string, reg *streamclient.Registry) erro r {
75 c, err := reg.NewClient(v)
76 if err != nil {
77 return errors.Annotate(err).Reason("bootstrap: failed to create stream client [%(config)s]").D("config", v).Err()
78 }
79 bs.Client = c
80 return nil
81 }
82
75 // Get loads a Bootstrap instance from the environment. It will return an error 83 // Get loads a Bootstrap instance from the environment. It will return an error
76 // if the bootstrap data is invalid, and will return ErrNotBootstrapped if the 84 // if the bootstrap data is invalid, and will return ErrNotBootstrapped if the
77 // current process is not bootstrapped. 85 // current process is not bootstrapped.
78 func Get() (*Bootstrap, error) { 86 func Get() (*Bootstrap, error) {
79 » return getFromEnv(environ.Get(), streamclient.DefaultRegistry) 87 » return getFromEnv(environ.Get(), streamclient.GetDefaultRegistry())
80 } 88 }
89
90 // GetViewerURL returns a log stream viewer URL to the aggregate set of supplied
91 // stream paths.
92 //
93 // If both the Project and CoordinatorHost values are not populated, an error
94 // will be returned.
95 func (bs *Bootstrap) GetViewerURL(paths ...types.StreamPath) (string, error) {
96 if bs.Project == "" {
97 return "", errors.New("no project is configured")
98 }
99 if bs.CoordinatorHost == "" {
100 return "", errors.New("no coordinator host is configured")
101 }
102 return viewer.GetURL(bs.CoordinatorHost, bs.Project, paths...), nil
103 }
104
105 // GetViewerURLForStreams returns a log stream viewer URL to the aggregate set
106 // of supplied streams.
107 //
108 // If the any of the Prefix, Project, or CoordinatorHost values is not
109 // populated, an error will be returned.
110 func (bs *Bootstrap) GetViewerURLForStreams(streams ...streamclient.Stream) (str ing, error) {
111 if bs.Prefix == "" {
112 return "", errors.New("no prefix is configured")
113 }
114
115 paths := make([]types.StreamPath, len(streams))
116 for i, s := range streams {
117 paths[i] = bs.Prefix.Join(types.StreamName(s.Properties().Name))
118 }
119 return bs.GetViewerURL(paths...)
120 }
OLDNEW
« no previous file with comments | « logdog/client/butler/streamserver/handshake_test.go ('k') | logdog/client/butlerlib/bootstrap/bootstrap_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698