16212: Tombstone commit - this branch won't be needed.
[arvados.git] / lib / config / load.go
index 86a8f7df6d2cd4ccfdb68beec66f71dd7204f4cc..c4a9483e99ed58ea5d92edca757e0242a4e29fbe 100644 (file)
@@ -265,10 +265,17 @@ func (ldr *Loader) Load() (*arvados.Config, error) {
                }
        }
 
-       // Check for known mistakes
        for id, cc := range cfg.Clusters {
+               ldr.Logger.Infof(">>>>> Cluster %s", id)
+               if id == "xxxxx" {
+                       continue
+               }
+               // Check for known mistakes
                for _, err = range []error{
                        checkKeyConflict(fmt.Sprintf("Clusters.%s.PostgreSQL.Connection", id), cc.PostgreSQL.Connection),
+                       checkMutuallyExclusiveConfigs(
+                               fmt.Sprintf("Clusters.%s configuration problem: exactly one of Login.GoogleClientID, Login.ProviderAppID, or Login.PAM must be configured", id),
+                               []bool{cc.Login.PAM, cc.Login.GoogleClientID != "", cc.Login.ProviderAppID != ""}),
                        ldr.checkEmptyKeepstores(cc),
                        ldr.checkUnlistedKeepstores(cc),
                } {
@@ -276,6 +283,12 @@ func (ldr *Loader) Load() (*arvados.Config, error) {
                                return nil, err
                        }
                }
+               // Compute derived configs
+               if cc.Login.PAM {
+                       cc.Login.Endpoint = "authenticate"
+               } else {
+                       cc.Login.Endpoint = "login"
+               }
        }
        return &cfg, nil
 }
@@ -292,6 +305,19 @@ func checkKeyConflict(label string, m map[string]string) error {
        return nil
 }
 
+func checkMutuallyExclusiveConfigs(msg string, cfgs []bool) error {
+       activeCfgs := 0
+       for _, isActive := range cfgs {
+               if isActive {
+                       activeCfgs++
+               }
+       }
+       if activeCfgs != 1 {
+               return fmt.Errorf("%s: %d", msg, activeCfgs)
+       }
+       return nil
+}
+
 func removeSampleKeys(m map[string]interface{}) {
        delete(m, "SAMPLE")
        for _, v := range m {