Skip to content

Commit 77d047a

Browse files
committed
feat(cli): pam migrate to handle Keyfactor secrets.
Signed-off-by: spbsoluble <1661003+spbsoluble@users.noreply.github.com>
1 parent 98ef719 commit 77d047a

2 files changed

Lines changed: 30 additions & 13 deletions

File tree

cmd/helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,8 @@ func storePasswordPropToCSV(
552552
row[fmt.Sprintf("Password.Parameters.%s", paramName)] = *v.Value
553553
}
554554
}
555-
} else if store.Password.Value != nil {
556-
row["Password"] = store.Password.Value
555+
} else if store.Password.HasValue && store.Password.Value != nil {
556+
row["Password"] = fmt.Sprintf("%s", *store.Password.Value)
557557
}
558558

559559
return nil

cmd/migrate.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ var migratePamCmd = &cobra.Command{
392392
}
393393

394394
// check Store Password for PAM field, and process migration if applicable
395-
var storePassword *api.StorePasswordConfig
395+
var storePassword *api.UpdateStorePasswordConfig
396396
if certStore.Password.IsManaged { // managed secret, i.e. PAM Provider in use
397397

398398
// check if Pam Secret is using our migrating provider
@@ -643,21 +643,38 @@ func selectProviderTypeParamId(name string, pamTypeParameterDefinitions []interf
643643
}
644644

645645
func reformatPamSecretForPost(secretProp map[string]interface{}) map[string]interface{} {
646-
reformatted := map[string]interface{}{
647-
"Provider": secretProp["ProviderId"],
646+
647+
reformatted := map[string]interface{}{}
648+
// check if secretProp has a "SecretValue" key
649+
if secVal, ok := secretProp["SecretValue"]; ok && secVal != nil {
650+
// add top level "value" key with SecretValue
651+
formattedVal := make(map[string]interface{})
652+
formattedVal["SecretValue"] = secVal
653+
// convert formattedVal into escaped JSON string
654+
jsonVal, _ := json.Marshal(formattedVal)
655+
reformatted["value"] = string(jsonVal)
656+
//reformatted["value"] = formattedVal
648657
}
649658

650-
providerParams := secretProp["ProviderTypeParameterValues"].([]interface{})
651-
reformattedParams := map[string]string{}
659+
// check if secretProp has a "ProviderId" key
660+
if prId, ok := secretProp["ProviderId"]; ok && prId != nil {
661+
reformatted["Provider"] = prId
662+
}
663+
// check if secretProp has a "ProviderTypeParameterValues" key
664+
if vals, valsOk := secretProp["ProviderTypeParameterValues"]; valsOk && vals != nil {
665+
providerParams := secretProp["ProviderTypeParameterValues"].([]interface{})
666+
reformattedParams := map[string]string{}
652667

653-
for _, param := range providerParams {
654-
providerTypeParam := param.(map[string]interface{})["ProviderTypeParam"].(map[string]interface{})
655-
name := providerTypeParam["Name"].(string)
656-
value := param.(map[string]interface{})["Value"].(string)
657-
reformattedParams[name] = value
668+
for _, param := range providerParams {
669+
providerTypeParam := param.(map[string]interface{})["ProviderTypeParam"].(map[string]interface{})
670+
name := providerTypeParam["Name"].(string)
671+
value := param.(map[string]interface{})["Value"].(string)
672+
reformattedParams[name] = value
673+
}
674+
675+
reformatted["Parameters"] = reformattedParams
658676
}
659677

660-
reformatted["Parameters"] = reformattedParams
661678
return reformatted
662679
}
663680

0 commit comments

Comments
 (0)