Skip to content

Commit 3d9bf7a

Browse files
committed
fix(migrate): use debug flag to show verbose object logging
1 parent 3a53e44 commit 3d9bf7a

File tree

1 file changed

+61
-47
lines changed

1 file changed

+61
-47
lines changed

cmd/migrate.go

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -203,41 +203,46 @@ var migratePamCmd = &cobra.Command{
203203
for _, pamType := range pamTypes {
204204
if *pamType.Id == *fromPamProvider.ProviderType.Id {
205205
fromPamType = pamType
206-
// TODO: remove debugging
207-
fmt.Println("vvv FROM TYPE vvv")
208-
jobject, _ := json.MarshalIndent(pamType, "", " ")
209-
fmt.Println(string(jobject))
210-
jobject, _ = json.MarshalIndent(pamType.AdditionalProperties["Parameters"], "", " ")
211-
fmt.Println(string(jobject))
212-
fmt.Println("^^^ FROM TYPE ^^^")
206+
207+
if debugFlag {
208+
fmt.Println("vvv FROM TYPE vvv")
209+
jobject, _ := json.MarshalIndent(pamType, "", " ")
210+
fmt.Println(string(jobject))
211+
jobject, _ = json.MarshalIndent(pamType.AdditionalProperties["Parameters"], "", " ")
212+
fmt.Println(string(jobject))
213+
fmt.Println("^^^ FROM TYPE ^^^")
214+
}
213215
}
214216

215217
if *pamType.Name == migrateTo {
216218
toPamType = pamType
217-
// TODO: remove debugging
218-
fmt.Println("vvv TO TYPE vvv")
219-
jobject, _ := json.MarshalIndent(pamType, "", " ")
220-
fmt.Println(string(jobject))
221-
jobject, _ = json.MarshalIndent(pamType.AdditionalProperties["Parameters"], "", " ")
222-
fmt.Println(string(jobject))
223-
fmt.Println("^^^ TO TYPE ^^^")
219+
220+
if debugFlag {
221+
fmt.Println("vvv TO TYPE vvv")
222+
jobject, _ := json.MarshalIndent(pamType, "", " ")
223+
fmt.Println(string(jobject))
224+
jobject, _ = json.MarshalIndent(pamType.AdditionalProperties["Parameters"], "", " ")
225+
fmt.Println(string(jobject))
226+
fmt.Println("^^^ TO TYPE ^^^")
227+
}
224228
}
225229
}
226230

227231
// TODO: check typing, have to access "Parameters" instead of ProviderTypeParams
228232
for _, pamParamType := range fromPamType.AdditionalProperties["Parameters"].([]interface{}) {
229-
jobject, _ := json.MarshalIndent(pamParamType, "", " ")
230-
fmt.Println(string(jobject))
231233
if pamParamType.(map[string]interface{})["InstanceLevel"].(bool) {
232234
// found definition of an instance level param for the type in question
233235
// create key in map for the field name
234236
inUsePamParamValues[pamParamType.(map[string]interface{})["Name"].(string)] = map[string]string{}
235-
fmt.Println("made it!")
236237
}
237238
}
238239

239-
jobject, _ := json.MarshalIndent(inUsePamParamValues, "", " ")
240-
fmt.Println(string(jobject))
240+
if debugFlag {
241+
fmt.Println("vvv IN USE PAM PROVIDER PARAMETER INSTANCES vvv")
242+
jobject, _ := json.MarshalIndent(inUsePamParamValues, "", " ")
243+
fmt.Println(string(jobject))
244+
fmt.Println("^^^ IN USE PAM PROVIDER PARAMETER INSTANCES ^^^")
245+
}
241246

242247
// step through list of every defined param value
243248
// record unique GUIDs of every param value on InstanceLevel : true
@@ -254,13 +259,13 @@ var migratePamCmd = &cobra.Command{
254259
fromProviderLevelParamValues[fieldName] = *pamParam.Value
255260
}
256261
}
257-
jobject, _ = json.MarshalIndent(inUsePamParamValues, "", " ")
258-
fmt.Println(string(jobject))
259-
260-
// TODO: make sure every field has the same number of GUIDs tracked
261-
// tally GUID count for logging
262262

263-
// log.Info().Msgf("Found %d PAM Provider usages of Provider %s",)
263+
if debugFlag {
264+
fmt.Println("vvv IN USE PAM PROVIDER PARAMETER VALUES vvv")
265+
jobject, _ := json.MarshalIndent(inUsePamParamValues, "", " ")
266+
fmt.Println(string(jobject))
267+
fmt.Println("^^^ IN USE PAM PROVIDER PARAMETER VALUES ^^^")
268+
}
264269

265270
// GET all PAM Types
266271
// select array entry with matching Name field of <<TO>>
@@ -296,13 +301,17 @@ var migratePamCmd = &cobra.Command{
296301
return rErr
297302
}
298303

299-
jobject, _ = json.MarshalIndent(certStore, "", " ")
300-
fmt.Println(string(jobject))
301-
fmt.Println("^^^ found cert store ^^^")
304+
if debugFlag {
305+
fmt.Println("vvv FOUND CERT STORE vvv")
306+
jobject, _ := json.MarshalIndent(certStore, "", " ")
307+
fmt.Println(string(jobject))
308+
fmt.Println("^^^ FOUND CERT STORE ^^^")
302309

303-
jobject, _ = json.MarshalIndent(certStore.Properties, "", " ")
304-
fmt.Println(string(jobject))
305-
fmt.Println("^^^ cert store properties ^^^")
310+
fmt.Println("vvv CERT STORE PROPERTIES vvv")
311+
jobject, _ = json.MarshalIndent(certStore.Properties, "", " ")
312+
fmt.Println(string(jobject))
313+
fmt.Println("^^^ CERT STORE PROPERTIES ^^^")
314+
}
306315

307316
// foreach property key (properties is an object not an array)
308317
// if value is an object, and object has an InstanceGuid
@@ -340,14 +349,12 @@ var migratePamCmd = &cobra.Command{
340349
}
341350
}
342351

343-
jobject, _ = json.MarshalIndent(certStore.Properties, "", " ")
344-
fmt.Println(string(jobject))
345-
fmt.Println("^^^ SECRETS REFORMATTED ^^^")
346-
347-
// propertiesAsString, _ := json.Marshal(certStore.Properties)
348-
// jsonProps := string(propertiesAsString)
349-
// escapedProps := strings.ReplaceAll(jsonProps, "\"", "\\\"")
350-
// fmt.Println(escapedProps)
352+
if debugFlag {
353+
fmt.Println("vvv SECRETS REFORMATTED vvv")
354+
jobject, _ := json.MarshalIndent(certStore.Properties, "", " ")
355+
fmt.Println(string(jobject))
356+
fmt.Println("^^^ SECRETS REFORMATTED ^^^")
357+
}
351358

352359
// update property object
353360
// set required fields, and new Properties
@@ -368,7 +375,8 @@ var migratePamCmd = &cobra.Command{
368375
return rErr
369376
}
370377

371-
jobject, _ = json.MarshalIndent(updatedStore, "", " ")
378+
fmt.Println("vvv UPDATED STORE vvv")
379+
jobject, _ := json.MarshalIndent(updatedStore, "", " ")
372380
fmt.Println(string(jobject))
373381
fmt.Println("^^^ UPDATED STORE ^^^")
374382

@@ -462,9 +470,13 @@ func createMigrationTargetPamProvider(sdkClient *keyfactor.APIClient, fromPamPro
462470
msg := "Created new PAM Provider definition to be created."
463471
fmt.Println(msg)
464472
log.Info().Msg(msg)
465-
jobject, _ := json.MarshalIndent(migrationPamProvider, "", " ")
466-
fmt.Println(string(jobject))
467-
fmt.Println("^^^ PAM Provider to be created ^^^")
473+
474+
if debugFlag {
475+
fmt.Println("vvv PAM PROVIDER TO BE CREATED vvv")
476+
jobject, _ := json.MarshalIndent(migrationPamProvider, "", " ")
477+
fmt.Println(string(jobject))
478+
fmt.Println("^^^ PAM PROVIDER TO BE CREATED ^^^")
479+
}
468480

469481
// POST new PAM Provider
470482
// create new PAM Instance of designated <<TO>> type
@@ -487,10 +499,12 @@ func createMigrationTargetPamProvider(sdkClient *keyfactor.APIClient, fromPamPro
487499
return *createdPamProvider, returnHttpErr(httpResponse, rErr)
488500
}
489501

490-
fmt.Println("vvv CREATED MIGRATION PAM PROVIDER vvv")
491-
jobject, _ = json.MarshalIndent(createdPamProvider, "", " ")
492-
fmt.Println(string(jobject))
493-
fmt.Println("^^^ CREATED MIGRATION PAM PROVIDER ^^^")
502+
if debugFlag {
503+
fmt.Println("vvv CREATED MIGRATION PAM PROVIDER vvv")
504+
jobject, _ := json.MarshalIndent(createdPamProvider, "", " ")
505+
fmt.Println(string(jobject))
506+
fmt.Println("^^^ CREATED MIGRATION PAM PROVIDER ^^^")
507+
}
494508

495509
return *createdPamProvider, nil
496510
}

0 commit comments

Comments
 (0)