Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package config | |
| 6 | |
| 7 import ( | |
| 8 "errors" | |
| 9 "flag" | |
| 10 "net/http" | |
| 11 "time" | |
| 12 | |
| 13 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1" | |
| 14 "github.com/luci/luci-go/common/clock/clockflag" | |
| 15 "github.com/luci/luci-go/common/config" | |
| 16 "github.com/luci/luci-go/common/config/impl/remote" | |
| 17 "github.com/luci/luci-go/common/transport" | |
| 18 "golang.org/x/net/context" | |
| 19 ) | |
| 20 | |
| 21 // Flags is a set of command-line flags used to set up the process' | |
| 22 // configuration. | |
| 23 type Flags struct { | |
| 24 // ConfigPath is the path within the ConfigSet of the configuration. | |
| 25 // | |
| 26 // If ConfigURL is empty, this will be interpreted as a local filesystem path | |
| 27 // from which the configuration should be loaded. | |
| 28 ConfigFilePath string | |
| 29 | |
| 30 // KillCheckInterval, if >0, starts a goroutine that polls every interva l to | |
| 31 // see if the configuration has changed. | |
| 32 KillCheckInterval clockflag.Duration | |
| 33 | |
| 34 // RoundTripper, if not nil, is the http.RoundTripper that will be used to | |
| 35 // fetch remote configurations. | |
| 36 RoundTripper http.RoundTripper | |
| 37 } | |
| 38 | |
| 39 // AddToFlagSet augments the supplied FlagSet with values for Flags. | |
| 40 func (f *Flags) AddToFlagSet(fs *flag.FlagSet) { | |
| 41 fs.StringVar(&f.ConfigFilePath, "config-file-path", "", | |
| 42 "If set, load the configuration protobuf from this path instead of the configuration service.") | |
| 43 fs.Var(&f.KillCheckInterval, "config-kill-interval", | |
| 44 "If non-zero, poll for configuration changes and kill the applic ation if one is detected.") | |
| 45 } | |
| 46 | |
| 47 // CoordinatorOptions returns an Options instance loaded from the supplied flags | |
| 48 // and Coordinator instance. | |
| 49 func (f *Flags) CoordinatorOptions(c context.Context, client services.ServicesCl ient) (*Options, error) { | |
| 50 ccfg, err := client.GetConfig(c, &services.Void{}) | |
|
iannucci
2016/02/05 23:41:01
Empty message?
actually you could probably pass n
dnj (Google)
2016/02/06 04:10:37
That's not how g/pRPC works, unfortunately. It exp
| |
| 51 if err != nil { | |
| 52 return nil, err | |
| 53 } | |
| 54 | |
| 55 // If a ConfigFilePath was specified, use a mock configuration service t hat | |
| 56 // loads from a local file. | |
| 57 var ci config.Interface | |
| 58 if f.ConfigFilePath != "" { | |
| 59 ci = &fileConfig{ | |
| 60 path: f.ConfigFilePath, | |
| 61 configSet: ccfg.ConfigSet, | |
| 62 configPath: ccfg.ConfigPath, | |
| 63 } | |
| 64 } else { | |
| 65 if ccfg.ConfigServiceUrl == "" { | |
| 66 return nil, errors.New("coordinator does not specify a c onfig service") | |
| 67 } | |
| 68 if ccfg.ConfigSet == "" { | |
| 69 return nil, errors.New("coordinator does not specify a c onfig set") | |
| 70 } | |
| 71 if ccfg.ConfigPath == "" { | |
| 72 return nil, errors.New("coordinator does not specify a c onfig path") | |
| 73 } | |
| 74 | |
| 75 if f.RoundTripper != nil { | |
| 76 c = transport.Set(c, f.RoundTripper) | |
| 77 } | |
| 78 ci = remote.New(c, ccfg.ConfigServiceUrl) | |
| 79 } | |
| 80 | |
| 81 return &Options{ | |
| 82 Config: ci, | |
| 83 ConfigSet: ccfg.ConfigSet, | |
| 84 ConfigPath: ccfg.ConfigPath, | |
| 85 KillCheckInterval: time.Duration(f.KillCheckInterval), | |
| 86 }, nil | |
| 87 } | |
| OLD | NEW |