14712: Adds arv-git-httpd to cluster config loading
[arvados.git] / lib / config / load.go
index 63b6ac7d986543304a0c156003dd64227ac4168c..7e48493939cd67a8322e67fe9f14bf357f26cd76 100644 (file)
@@ -26,12 +26,16 @@ var ErrNoClustersDefined = errors.New("config does not define any clusters")
 type Loader struct {
        Stdin          io.Reader
        Logger         logrus.FieldLogger
-       SkipDeprecated bool // Don't load legacy/deprecated config keys/files
+       SkipDeprecated bool // Don't load deprecated config keys
+       SkipLegacy     bool // Don't load legacy config files
 
        Path                    string
        KeepstorePath           string
+       KeepWebPath             string
        CrunchDispatchSlurmPath string
-       WebsocketsPath          string
+       WebsocketPath           string
+       KeepproxyPath           string
+       GitHttpdPath            string
 
        configdata []byte
 }
@@ -59,8 +63,12 @@ func NewLoader(stdin io.Reader, logger logrus.FieldLogger) *Loader {
 func (ldr *Loader) SetupFlags(flagset *flag.FlagSet) {
        flagset.StringVar(&ldr.Path, "config", arvados.DefaultConfigFile, "Site configuration `file` (default may be overridden by setting an ARVADOS_CONFIG environment variable)")
        flagset.StringVar(&ldr.KeepstorePath, "legacy-keepstore-config", defaultKeepstoreConfigPath, "Legacy keepstore configuration `file`")
+       flagset.StringVar(&ldr.KeepWebPath, "legacy-keepweb-config", defaultKeepWebConfigPath, "Legacy keep-web configuration `file`")
        flagset.StringVar(&ldr.CrunchDispatchSlurmPath, "legacy-crunch-dispatch-slurm-config", defaultCrunchDispatchSlurmConfigPath, "Legacy crunch-dispatch-slurm configuration `file`")
-       flagset.StringVar(&ldr.WebsocketsPath, "legacy-ws-config", defaultWebsocketsConfigPath, "Legacy arvados-ws configuration `file`")
+       flagset.StringVar(&ldr.WebsocketPath, "legacy-ws-config", defaultWebsocketConfigPath, "Legacy arvados-ws configuration `file`")
+       flagset.StringVar(&ldr.KeepproxyPath, "legacy-keepproxy-config", defaultKeepproxyConfigPath, "Legacy keepproxy configuration `file`")
+       flagset.StringVar(&ldr.GitHttpdPath, "legacy-git-httpd-config", defaultGitHttpdConfigPath, "Legacy arv-git-httpd configuration `file`")
+       flagset.BoolVar(&ldr.SkipLegacy, "skip-legacy", false, "Don't load legacy config files")
 }
 
 // MungeLegacyConfigArgs checks args for a -config flag whose argument
@@ -119,6 +127,28 @@ func (ldr *Loader) MungeLegacyConfigArgs(lgr logrus.FieldLogger, args []string,
                        }
                }
        }
+
+       // Disable legacy config loading for components other than the
+       // one that was specified
+       if legacyConfigArg != "-legacy-keepstore-config" {
+               ldr.KeepstorePath = ""
+       }
+       if legacyConfigArg != "-legacy-crunch-dispatch-slurm-config" {
+               ldr.CrunchDispatchSlurmPath = ""
+       }
+       if legacyConfigArg != "-legacy-ws-config" {
+               ldr.WebsocketPath = ""
+       }
+       if legacyConfigArg != "-legacy-keepweb-config" {
+               ldr.KeepWebPath = ""
+       }
+       if legacyConfigArg != "-legacy-keepproxy-config" {
+               ldr.KeepproxyPath = ""
+       }
+       if legacyConfigArg != "-legacy-git-httpd-config" {
+               ldr.GitHttpdPath = ""
+       }
+
        return munged
 }
 
@@ -134,12 +164,6 @@ func (ldr *Loader) loadBytes(path string) ([]byte, error) {
        return ioutil.ReadAll(f)
 }
 
-func (ldr *Loader) LoadDefaults() (*arvados.Config, error) {
-       ldr.configdata = []byte(`Clusters: {zzzzz: {}}`)
-       defer func() { ldr.configdata = nil }()
-       return ldr.Load()
-}
-
 func (ldr *Loader) Load() (*arvados.Config, error) {
        if ldr.configdata == nil {
                buf, err := ldr.loadBytes(ldr.Path)
@@ -213,10 +237,19 @@ func (ldr *Loader) Load() (*arvados.Config, error) {
                if err != nil {
                        return nil, err
                }
+       }
+       if !ldr.SkipLegacy {
+               // legacy file is required when either:
+               // * a non-default location was specified
+               // * no primary config was loaded, and this is the
+               // legacy config file for the current component
                for _, err := range []error{
                        ldr.loadOldKeepstoreConfig(&cfg),
+                       ldr.loadOldKeepWebConfig(&cfg),
                        ldr.loadOldCrunchDispatchSlurmConfig(&cfg),
-                       ldr.loadOldWebsocketsConfig(&cfg),
+                       ldr.loadOldWebsocketConfig(&cfg),
+                       ldr.loadOldKeepproxyConfig(&cfg),
+                       ldr.loadOldGitHttpdConfig(&cfg),
                } {
                        if err != nil {
                                return nil, err