Browse Source

Support common idiom for GCP SM

Common idiom for GCP SM is like:
{
    "name": {
        "client_id": "<client_id>",
        "client_secret": "<client_secret>",
    }
}

Using DataFrom, the current GCP SM will fail to unmarshal cause it's expecting
{
    "name": "{\"client_id\": \"<client_id>\", \"client_secret\": \"<client_secret>\"}",
}
which is much more annoying to work with.  By tweaking the implementation to
try to decode to a string, but if that fails, use the raw []byte of the value
we get the best of both worlds.
Andrew Leap 4 years ago
parent
commit
f1fad4576c
1 changed files with 8 additions and 2 deletions
  1. 8 2
      pkg/provider/gcp/secretmanager/secretsmanager.go

+ 8 - 2
pkg/provider/gcp/secretmanager/secretsmanager.go

@@ -197,7 +197,7 @@ func (sm *ProviderGCP) GetSecretMap(ctx context.Context, ref esv1alpha1.External
 		return nil, err
 	}
 
-	kv := make(map[string]string)
+	kv := make(map[string]json.RawMessage)
 	err = json.Unmarshal(data, &kv)
 	if err != nil {
 		return nil, fmt.Errorf(errJSONSecretUnmarshal, err)
@@ -205,7 +205,13 @@ func (sm *ProviderGCP) GetSecretMap(ctx context.Context, ref esv1alpha1.External
 
 	secretData := make(map[string][]byte)
 	for k, v := range kv {
-		secretData[k] = []byte(v)
+		var strVal string
+		err = json.Unmarshal(v, &strVal)
+		if err == nil {
+			secretData[k] = []byte(strVal)
+		} else {
+			secretData[k] = v
+		}
 	}
 
 	return secretData, nil