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

Side by Side Diff: client/cmd/logdog_cat/main.go

Issue 1916013002: LogDog: Add project namespacing to `logdog_cat` (Closed) Base URL: https://github.com/luci/luci-go@logdog-project-collector-butler
Patch Set: Rebase, project UI. Created 4 years, 7 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 | « no previous file | common/logdog/coordinator/client.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 Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "flag" 9 "flag"
10 "fmt"
10 "os" 11 "os"
11 "os/signal" 12 "os/signal"
12 13
13 "github.com/maruel/subcommands" 14 "github.com/maruel/subcommands"
14 "golang.org/x/net/context" 15 "golang.org/x/net/context"
15 16
16 "github.com/luci/luci-go/client/authcli" 17 "github.com/luci/luci-go/client/authcli"
17 "github.com/luci/luci-go/common/auth" 18 "github.com/luci/luci-go/common/auth"
18 "github.com/luci/luci-go/common/cli" 19 "github.com/luci/luci-go/common/cli"
20 "github.com/luci/luci-go/common/config"
19 "github.com/luci/luci-go/common/logdog/coordinator" 21 "github.com/luci/luci-go/common/logdog/coordinator"
20 log "github.com/luci/luci-go/common/logging" 22 log "github.com/luci/luci-go/common/logging"
21 "github.com/luci/luci-go/common/logging/gologger" 23 "github.com/luci/luci-go/common/logging/gologger"
22 "github.com/luci/luci-go/common/prpc" 24 "github.com/luci/luci-go/common/prpc"
23 ) 25 )
24 26
25 func init() { 27 func init() {
26 prpc.DefaultUserAgent = "logdog_cat" 28 prpc.DefaultUserAgent = "logdog_cat"
27 } 29 }
28 30
29 type application struct { 31 type application struct {
30 cli.Application 32 cli.Application
31 context.Context 33 context.Context
32 34
35 project config.ProjectName
33 authFlags authcli.Flags 36 authFlags authcli.Flags
34 coordinator string 37 coordinator string
35 insecure bool 38 insecure bool
36 39
37 coord *coordinator.Client 40 coord *coordinator.Client
38 } 41 }
39 42
40 func (a *application) addToFlagSet(ctx context.Context, fs *flag.FlagSet) { 43 func (a *application) addToFlagSet(ctx context.Context, fs *flag.FlagSet) {
41 fs.StringVar(&a.coordinator, "host", "", 44 fs.StringVar(&a.coordinator, "host", "",
42 "The LogDog Coordinator [host][:port].") 45 "The LogDog Coordinator [host][:port].")
43 fs.BoolVar(&a.insecure, "insecure", false, 46 fs.BoolVar(&a.insecure, "insecure", false,
44 "Use insecure transport for RPC.") 47 "Use insecure transport for RPC.")
48 fs.Var(&a.project, "project",
49 "The log stream's project.")
45 } 50 }
46 51
47 func (a *application) validate() error { 52 func (a *application) validate() error {
48 if a.coordinator == "" { 53 if a.coordinator == "" {
49 return errors.New("main: missing coordinator URL (-url)") 54 return errors.New("main: missing coordinator URL (-url)")
50 } 55 }
56 // TODO(dnj): Error on empty project once that's disallowed.
57 if a.project != "" {
58 if err := a.project.Validate(); err != nil {
59 return fmt.Errorf("main: invalid project name (-project) : %s", err)
60 }
61 }
51 return nil 62 return nil
52 } 63 }
53 64
54 func mainImpl() int { 65 func mainImpl() int {
55 ctx := context.Background() 66 ctx := context.Background()
56 ctx = gologger.StdConfig.Use(ctx) 67 ctx = gologger.StdConfig.Use(ctx)
57 68
58 authOptions := auth.Options{ 69 authOptions := auth.Options{
59 Scopes: coordinator.Scopes, 70 Scopes: coordinator.Scopes,
60 } 71 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 signal.Stop(signalC) 132 signal.Stop(signalC)
122 close(signalC) 133 close(signalC)
123 }() 134 }()
124 135
125 // Instantiate our authenticated HTTP client. 136 // Instantiate our authenticated HTTP client.
126 authOpts, err := a.authFlags.Options() 137 authOpts, err := a.authFlags.Options()
127 if err != nil { 138 if err != nil {
128 log.Errorf(log.SetError(ctx, err), "Failed to create auth option s.") 139 log.Errorf(log.SetError(ctx, err), "Failed to create auth option s.")
129 return 1 140 return 1
130 } 141 }
131 » httpClient, err := auth.NewAuthenticator(ctx, auth.SilentLogin, authOpts ).Client() 142 » httpClient, err := auth.NewAuthenticator(ctx, auth.OptionalLogin, authOp ts).Client()
132 if err != nil { 143 if err != nil {
133 log.Errorf(log.SetError(ctx, err), "Failed to create authenticat ed client.") 144 log.Errorf(log.SetError(ctx, err), "Failed to create authenticat ed client.")
134 return 1 145 return 1
135 } 146 }
136 147
137 // Get our Coordinator client instance. 148 // Get our Coordinator client instance.
138 prpcClient := &prpc.Client{ 149 prpcClient := &prpc.Client{
139 C: httpClient, 150 C: httpClient,
140 Host: a.coordinator, 151 Host: a.coordinator,
141 Options: prpc.DefaultOptions(), 152 Options: prpc.DefaultOptions(),
142 } 153 }
143 prpcClient.Options.Insecure = a.insecure 154 prpcClient.Options.Insecure = a.insecure
144 155
145 » a.coord = coordinator.NewClient(prpcClient) 156 » a.coord = coordinator.NewClient(prpcClient, a.project)
146 a.Context = ctx 157 a.Context = ctx
147 return subcommands.Run(&a, flags.Args()) 158 return subcommands.Run(&a, flags.Args())
148 } 159 }
149 160
150 func main() { 161 func main() {
151 os.Exit(mainImpl()) 162 os.Exit(mainImpl())
152 } 163 }
OLDNEW
« no previous file with comments | « no previous file | common/logdog/coordinator/client.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698