Explorar el Código

add existence check

Ajay Tripathy hace 5 años
padre
commit
8bfce69c27
Se han modificado 1 ficheros con 23 adiciones y 15 borrados
  1. 23 15
      pkg/cloud/awsprovider.go

+ 23 - 15
pkg/cloud/awsprovider.go

@@ -395,7 +395,6 @@ func (aws *AWS) UpdateConfig(r io.Reader, updateType string) (*CustomPricing, er
 				return err
 			}
 		}
-
 		return nil
 	})
 }
@@ -1097,18 +1096,41 @@ func (awsProvider *AWS) ClusterInfo() (map[string]string, error) {
 
 // Gets the aws key id and secret
 func (aws *AWS) getAWSAuth(forceReload bool, cp *CustomPricing) (string, string) {
+	if aws.ServiceAccountChecks == nil { // safety in case checks don't exist
+		aws.ServiceAccountChecks = make(map[string]*ServiceAccountCheck)
+	}
+
 	// 1. Check config values first (set from frontend UI)
 	if cp.ServiceKeyName != "" && cp.ServiceKeySecret != "" {
+		aws.ServiceAccountChecks["hasKey"] = &ServiceAccountCheck{
+			Message: "ServiceKey exists",
+			Status:  true,
+		}
 		return cp.ServiceKeyName, cp.ServiceKeySecret
 	}
 
 	// 2. Check for secret
 	s, _ := aws.loadAWSAuthSecret(forceReload)
 	if s != nil && s.AccessKeyID != "" && s.SecretAccessKey != "" {
+		aws.ServiceAccountChecks["hasKey"] = &ServiceAccountCheck{
+			Message: "ServiceKey exists",
+			Status:  true,
+		}
 		return s.AccessKeyID, s.SecretAccessKey
 	}
 
 	// 3. Fall back to env vars
+	if env.GetAWSAccessKeyID() == "" || env.GetAWSAccessKeyID() == "" {
+		aws.ServiceAccountChecks["hasKey"] = &ServiceAccountCheck{
+			Message: "ServiceKey exists",
+			Status:  false,
+		}
+	} else {
+		aws.ServiceAccountChecks["hasKey"] = &ServiceAccountCheck{
+			Message: "ServiceKey exists",
+			Status:  true,
+		}
+	}
 	return env.GetAWSAccessKeyID(), env.GetAWSAccessKeySecret()
 }
 
@@ -1154,20 +1176,6 @@ func (aws *AWS) configureAWSAuth() error {
 			return err
 		}
 	}
-	if aws.ServiceAccountChecks == nil {
-		aws.ServiceAccountChecks = make(map[string]*ServiceAccountCheck)
-	}
-	if env.Get(env.AWSAccessKeyIDEnvVar, "") == "" || env.Get(env.AWSAccessKeySecretEnvVar, "") == "" {
-		aws.ServiceAccountChecks["hasKey"] = &ServiceAccountCheck{
-			Message: "ServiceKey exists",
-			Status:  false,
-		}
-	} else {
-		aws.ServiceAccountChecks["hasKey"] = &ServiceAccountCheck{
-			Message: "ServiceKey exists",
-			Status:  true,
-		}
-	}
 	return nil
 }