@@ -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
92101var importStoresCmd = & cobra.Command {
0 commit comments