Skip to content

Commit 054b0f1

Browse files
committed
fix(cli): Fix POST payload for ServerUsername and ServerPassword
Signed-off-by: spbsoluble <1661003+spbsoluble@users.noreply.github.com>
1 parent 48e7cbb commit 054b0f1

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

cmd/migrate.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,9 @@ func reformatPamSecretForPost(secretProp map[string]interface{}) map[string]inte
659659
// check if secretProp has a "ProviderId" key
660660
if prId, ok := secretProp["ProviderId"]; ok && prId != nil {
661661
reformatted["Provider"] = prId
662+
} else if prId, ok := secretProp["Provider"]; ok && prId != nil {
663+
reformatted["Provider"] = prId
664+
reformatted["ProviderId"] = prId
662665
}
663666
// check if secretProp has a "ProviderTypeParameterValues" key
664667
if vals, valsOk := secretProp["ProviderTypeParameterValues"]; valsOk && vals != nil {
@@ -672,6 +675,15 @@ func reformatPamSecretForPost(secretProp map[string]interface{}) map[string]inte
672675
reformattedParams[name] = value
673676
}
674677

678+
reformatted["Parameters"] = reformattedParams
679+
} else if vals, valsOk := secretProp["Parameters"]; valsOk && vals != nil {
680+
// already in Parameters format, just cast and set
681+
//reformatted["Parameters"] = vals
682+
providerParams := vals.(map[string]interface{})
683+
reformattedParams := map[string]string{}
684+
for name, param := range providerParams {
685+
reformattedParams[name] = fmt.Sprintf("%v", param)
686+
}
675687
reformatted["Parameters"] = reformattedParams
676688
}
677689

cmd/storesBulkOperations.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ func stripAllBOMs(s string) string {
5555

5656
// formatProperties will iterate through the properties of a json object and convert any "int" values to strings
5757
// this is required because the Keyfactor API expects all properties to be strings
58-
func formatProperties(json *gabs.Container, reqPropertiesForStoreType []string) *gabs.Container {
58+
func formatProperties(propsJson *gabs.Container, reqPropertiesForStoreType []string) *gabs.Container {
5959
// Iterate through required properties and add to JSON
6060
for _, reqProp := range reqPropertiesForStoreType {
61-
if json.ExistsP("Properties." + reqProp) {
62-
log.Debug().Str("reqProp", reqProp).Msg("Property exists in json")
61+
if propsJson.ExistsP("Properties." + reqProp) {
62+
log.Debug().Str("reqProp", reqProp).Msg("Property exists in propsJson")
6363
continue
6464
}
65-
json.Set("", "Properties", reqProp) // Correctly add the required property
65+
propsJson.Set("", "Properties", reqProp) // Correctly add the required property
6666
}
6767

6868
// Iterate through properties and convert any "int" values to strings
69-
properties, _ := json.S("Properties").ChildrenMap()
69+
properties, _ := propsJson.S("Properties").ChildrenMap()
7070
for name, prop := range properties {
7171
if prop.Data() == nil {
7272
log.Debug().Str("name", name).Msg("Property is nil")
@@ -77,16 +77,25 @@ func formatProperties(json *gabs.Container, reqPropertiesForStoreType []string)
7777
log.Debug().Str("name", name).Msg("Property is an int")
7878
asStr := strconv.Itoa(prop.Data().(int))
7979
// Use gabs' Set method to update the property value
80-
json.Set(asStr, "Properties", name)
80+
propsJson.Set(asStr, "Properties", name)
8181
case map[string]interface{}:
8282
if name == "ServerUsername" || name == "ServerPassword" {
8383
reformatted := reformatPamSecretForPost(prop.Data().(map[string]interface{}))
84-
json.Set(reformatted["value"], "Properties", name)
84+
if reformatted != nil {
85+
if _, ok := reformatted["value"].(string); ok {
86+
propsJson.Set(reformatted["value"], "Properties", name)
87+
} else {
88+
jsonVal, _ := json.Marshal(reformatted)
89+
reformatted["value"] = string(jsonVal)
90+
propsJson.Set(reformatted, "Properties", name)
91+
}
92+
}
93+
8594
break
8695
}
8796
}
8897
}
89-
return json
98+
return propsJson
9099
}
91100

92101
var importStoresCmd = &cobra.Command{

0 commit comments

Comments
 (0)