| OLD | NEW | 
|     1 // Copyright 2014 The LUCI Authors. All rights reserved. |     1 // Copyright 2014 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 cipd implements a client of for Chrome Infra Package Deployer. |     5 // Package cipd implements a client of for Chrome Infra Package Deployer. | 
|     6 // |     6 // | 
|     7 // Subcommand starting with 'pkg-' are low level commands operating on package |     7 // Subcommand starting with 'pkg-' are low level commands operating on package | 
|     8 // files on disk. |     8 // files on disk. | 
|     9 package main |     9 package main | 
|    10  |    10  | 
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   228  |   228  | 
|   229 //////////////////////////////////////////////////////////////////////////////// |   229 //////////////////////////////////////////////////////////////////////////////// | 
|   230 // ClientOptions mixin. |   230 // ClientOptions mixin. | 
|   231  |   231  | 
|   232 // ClientOptions defines command line arguments related to CIPD client creation. |   232 // ClientOptions defines command line arguments related to CIPD client creation. | 
|   233 // Subcommands that need a CIPD client embed it. |   233 // Subcommands that need a CIPD client embed it. | 
|   234 type ClientOptions struct { |   234 type ClientOptions struct { | 
|   235         authFlags  authcli.Flags |   235         authFlags  authcli.Flags | 
|   236         serviceURL string |   236         serviceURL string | 
|   237         cacheDir   string |   237         cacheDir   string | 
|   238         userAgent  string |  | 
|   239 } |   238 } | 
|   240  |   239  | 
|   241 func (opts *ClientOptions) registerFlags(f *flag.FlagSet) { |   240 func (opts *ClientOptions) registerFlags(f *flag.FlagSet) { | 
|   242         f.StringVar(&opts.serviceURL, "service-url", "", "URL of a backend to us
      e instead of the default one.") |   241         f.StringVar(&opts.serviceURL, "service-url", "", "URL of a backend to us
      e instead of the default one.") | 
|   243         f.StringVar(&opts.userAgent, "http-user-agent", "", |  | 
|   244                 "User Agent text to add. If specified, the UA will be '<this_opt
      ion>/"+cipd.UserAgent+"'.") |  | 
|   245         f.StringVar(&opts.cacheDir, "cache-dir", "", "Directory for shared cache
      ") |   242         f.StringVar(&opts.cacheDir, "cache-dir", "", "Directory for shared cache
      ") | 
|   246         opts.authFlags.Register(f, auth.Options{}) |   243         opts.authFlags.Register(f, auth.Options{}) | 
|   247 } |   244 } | 
|   248  |   245  | 
|   249 func (opts *ClientOptions) makeCipdClient(ctx context.Context, root string) (cip
      d.Client, error) { |   246 func (opts *ClientOptions) makeCipdClient(ctx context.Context, root string) (cip
      d.Client, error) { | 
|   250         authOpts, err := opts.authFlags.Options() |   247         authOpts, err := opts.authFlags.Options() | 
|   251         if err != nil { |   248         if err != nil { | 
|   252                 return nil, err |   249                 return nil, err | 
|   253         } |   250         } | 
|   254         client, err := auth.NewAuthenticator(ctx, auth.OptionalLogin, authOpts).
      Client() |   251         client, err := auth.NewAuthenticator(ctx, auth.OptionalLogin, authOpts).
      Client() | 
|   255         if err != nil { |   252         if err != nil { | 
|   256                 return nil, err |   253                 return nil, err | 
|   257         } |   254         } | 
|   258         ua := cipd.UserAgent |   255         ua := cipd.UserAgent | 
|   259 »       if opts.userAgent != "" { |   256 »       if prefix := os.Getenv("CIPD_HTTP_USER_AGENT_PREFIX"); prefix != "" { | 
|   260 »       »       ua = fmt.Sprintf("%s/%s", opts.userAgent, ua) |   257 »       »       ua = fmt.Sprintf("%s/%s", prefix, ua) | 
|   261         } |   258         } | 
|   262         return cipd.NewClient(cipd.ClientOptions{ |   259         return cipd.NewClient(cipd.ClientOptions{ | 
|   263                 ServiceURL:          opts.serviceURL, |   260                 ServiceURL:          opts.serviceURL, | 
|   264                 Root:                root, |   261                 Root:                root, | 
|   265                 UserAgent:           ua, |   262                 UserAgent:           ua, | 
|   266                 CacheDir:            opts.cacheDir, |   263                 CacheDir:            opts.cacheDir, | 
|   267                 AuthenticatedClient: client, |   264                 AuthenticatedClient: client, | 
|   268                 AnonymousClient:     http.DefaultClient, |   265                 AnonymousClient:     http.DefaultClient, | 
|   269         }), nil |   266         }), nil | 
|   270 } |   267 } | 
| (...skipping 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2078  |  2075  | 
|  2079 func main() { |  2076 func main() { | 
|  2080         var seed int64 |  2077         var seed int64 | 
|  2081         if err := binary.Read(cryptorand.Reader, binary.LittleEndian, &seed); er
      r != nil { |  2078         if err := binary.Read(cryptorand.Reader, binary.LittleEndian, &seed); er
      r != nil { | 
|  2082                 panic(err) |  2079                 panic(err) | 
|  2083         } |  2080         } | 
|  2084         rand.Seed(seed) |  2081         rand.Seed(seed) | 
|  2085  |  2082  | 
|  2086         os.Exit(subcommands.Run(application, fixFlagsPosition(os.Args[1:]))) |  2083         os.Exit(subcommands.Run(application, fixFlagsPosition(os.Args[1:]))) | 
|  2087 } |  2084 } | 
| OLD | NEW |