| Index: server/internal/logdog/config/flag.go
|
| diff --git a/server/internal/logdog/config/flag.go b/server/internal/logdog/config/flag.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..04984d5159c4aef9573b8edc9edf3a8ffae4bd52
|
| --- /dev/null
|
| +++ b/server/internal/logdog/config/flag.go
|
| @@ -0,0 +1,96 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package config
|
| +
|
| +import (
|
| + "errors"
|
| + "flag"
|
| + "net/http"
|
| + "time"
|
| +
|
| + "github.com/luci/luci-go/common/clock/clockflag"
|
| + "github.com/luci/luci-go/common/config"
|
| + "github.com/luci/luci-go/common/config/impl/remote"
|
| + "github.com/luci/luci-go/common/transport"
|
| + cc "github.com/luci/luci-go/server/internal/logdog/coordinatorClient"
|
| + "golang.org/x/net/context"
|
| +)
|
| +
|
| +// CoordinatorConfigGetter is an interface to fetch the Coordinator's service
|
| +// configuration.
|
| +//
|
| +// coordinatorClient.Client is an implementation of this functionality.
|
| +type CoordinatorConfigGetter interface {
|
| + // GetConfig returns the Coordinator's service configuration.
|
| + GetConfig(c context.Context) (*cc.ServiceConfig, error)
|
| +}
|
| +
|
| +// Flags is a set of command-line flags used to set up the process'
|
| +// configuration.
|
| +type Flags struct {
|
| + // ConfigPath is the path within the ConfigSet of the configuration.
|
| + //
|
| + // If ConfigURL is empty, this will be interpreted as a local filesystem path
|
| + // from which the configuration should be loaded.
|
| + ConfigFilePath string
|
| +
|
| + // KillCheckInterval, if >0, starts a goroutine that polls every interval to
|
| + // see if the configuration has changed.
|
| + KillCheckInterval clockflag.Duration
|
| +
|
| + // RoundTripper, if not nil, is the http.RoundTripper that will be used to
|
| + // fetch remote configurations.
|
| + RoundTripper http.RoundTripper
|
| +}
|
| +
|
| +// AddToFlagSet augments the supplied FlagSet with values for Flags.
|
| +func (f *Flags) AddToFlagSet(fs *flag.FlagSet) {
|
| + fs.StringVar(&f.ConfigFilePath, "config-file-path", "",
|
| + "If set, load the configuration protobuf from this path instead of the configuration service.")
|
| + fs.Var(&f.KillCheckInterval, "config-kill-interval",
|
| + "If non-zero, poll for configuration changes and kill the application if one is detected.")
|
| +}
|
| +
|
| +// CoordinatorOptions returns an Options instance loaded from the supplied flags
|
| +// and Coordinator instance.
|
| +func (f *Flags) CoordinatorOptions(c context.Context, cc CoordinatorConfigGetter) (*Options, error) {
|
| + ccfg, err := cc.GetConfig(c)
|
| + if err != nil {
|
| + return nil, err
|
| + }
|
| +
|
| + // If a ConfigFilePath was specified, use a mock configuration service that
|
| + // loads from a local file.
|
| + var ci config.Interface
|
| + if f.ConfigFilePath != "" {
|
| + ci = &fileConfig{
|
| + path: f.ConfigFilePath,
|
| + configSet: ccfg.ConfigSet,
|
| + configPath: ccfg.ConfigPath,
|
| + }
|
| + } else {
|
| + if ccfg.ConfigService == "" {
|
| + return nil, errors.New("coordinator does not specify a config service")
|
| + }
|
| + if ccfg.ConfigSet == "" {
|
| + return nil, errors.New("coordinator does not specify a config set")
|
| + }
|
| + if ccfg.ConfigPath == "" {
|
| + return nil, errors.New("coordinator does not specify a config path")
|
| + }
|
| +
|
| + if f.RoundTripper != nil {
|
| + c = transport.Set(c, f.RoundTripper)
|
| + }
|
| + ci = remote.New(c, ccfg.ConfigService)
|
| + }
|
| +
|
| + return &Options{
|
| + Config: ci,
|
| + ConfigSet: ccfg.ConfigSet,
|
| + ConfigPath: ccfg.ConfigPath,
|
| + KillCheckInterval: time.Duration(f.KillCheckInterval),
|
| + }, nil
|
| +}
|
|
|