Skip to content

Commit 0be5cbc

Browse files
committed
fix(store-types): Add some debug logging to create tyoes
Signed-off-by: spbsoluble <[email protected]>
1 parent a4021a2 commit 0be5cbc

File tree

1 file changed

+63
-12
lines changed

1 file changed

+63
-12
lines changed

cmd/storeTypes.go

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ package cmd
1717
import (
1818
"encoding/json"
1919
"fmt"
20-
"github.com/AlecAivazis/survey/v2"
21-
"github.com/Keyfactor/keyfactor-go-client/v2/api"
22-
"github.com/rs/zerolog/log"
23-
"github.com/spf13/cobra"
2420
"io"
2521
"net/http"
2622
"os"
2723
"sort"
2824
"strings"
25+
26+
"github.com/AlecAivazis/survey/v2"
27+
"github.com/Keyfactor/keyfactor-go-client/v2/api"
28+
"github.com/rs/zerolog/log"
29+
"github.com/spf13/cobra"
2930
)
3031

3132
var storeTypesCmd = &cobra.Command{
@@ -102,6 +103,14 @@ var storesTypeCreateCmd = &cobra.Command{
102103
}
103104
storeTypeIsValid := false
104105

106+
log.Debug().Str("storeType", storeType).
107+
Bool("listTypes", listTypes).
108+
Str("storeTypeConfigFile", storeTypeConfigFile).
109+
Bool("creatAll", creatAll).
110+
Str("gitRef", gitRef).
111+
Strs("validStoreTypes", validStoreTypes).
112+
Msg("create command flags")
113+
105114
if listTypes {
106115
fmt.Println("Available store types:")
107116
sort.Strings(validStoreTypes)
@@ -138,12 +147,16 @@ var storesTypeCreateCmd = &cobra.Command{
138147
}
139148
for _, v := range validStoreTypes {
140149
if strings.EqualFold(v, strings.ToUpper(storeType)) || creatAll {
141-
log.Printf("[DEBUG] Valid store type: %s", storeType)
150+
log.Debug().Str("storeType", storeType).Msg("Store type is valid")
142151
storeTypeIsValid = true
143152
break
144153
}
145154
}
146155
if !storeTypeIsValid {
156+
log.Error().
157+
Str("storeType", storeType).
158+
Bool("isValid", storeTypeIsValid).
159+
Msg("Invalid store type")
147160
fmt.Printf("ERROR: Invalid store type: %s\nValid types are:\n", storeType)
148161
for _, st := range validStoreTypes {
149162
fmt.Println(fmt.Sprintf("\t%s", st))
@@ -292,7 +305,10 @@ var storesTypeDeleteCmd = &cobra.Command{
292305
}
293306

294307
if dryRun {
295-
outputResult(fmt.Sprintf("dry run delete called on certificate store type (%v) with ID: %d", st, id), outputFormat)
308+
outputResult(
309+
fmt.Sprintf("dry run delete called on certificate store type (%v) with ID: %d", st, id),
310+
outputFormat,
311+
)
296312
} else {
297313
log.Debug().Interface("storeType", st).
298314
Int("id", id).
@@ -410,7 +426,12 @@ func getStoreTypesInternet(gitRef string) (map[string]interface{}, error) {
410426
//resp, err := http.Get("https://raw.githubusercontent.com/keyfactor/kfutil/main/store_types.json")
411427
//resp, err := http.Get("https://raw.githubusercontent.com/keyfactor/kfctl/master/storetypes/storetypes.json")
412428

413-
resp, rErr := http.Get(fmt.Sprintf("https://raw.githubusercontent.com/Keyfactor/kfutil/%s/store_types.json", gitRef))
429+
resp, rErr := http.Get(
430+
fmt.Sprintf(
431+
"https://raw.githubusercontent.com/Keyfactor/kfutil/%s/store_types.json",
432+
gitRef,
433+
),
434+
)
414435
if rErr != nil {
415436
return nil, rErr
416437
}
@@ -489,7 +510,13 @@ func init() {
489510

490511
// GET store type templates
491512
storeTypesCmd.AddCommand(fetchStoreTypesCmd)
492-
fetchStoreTypesCmd.Flags().StringVarP(&gitRef, FlagGitRef, "b", "main", "The git branch or tag to reference when pulling store-types from the internet.")
513+
fetchStoreTypesCmd.Flags().StringVarP(
514+
&gitRef,
515+
FlagGitRef,
516+
"b",
517+
"main",
518+
"The git branch or tag to reference when pulling store-types from the internet.",
519+
)
493520

494521
// LIST command
495522
storeTypesCmd.AddCommand(storesTypesListCmd)
@@ -504,10 +531,28 @@ func init() {
504531
var storeTypeName string
505532
var storeTypeID int
506533
storeTypesCmd.AddCommand(storesTypeCreateCmd)
507-
storesTypeCreateCmd.Flags().StringVarP(&storeTypeName, "name", "n", "", "Short name of the certificate store type to get. Valid choices are: "+validTypesString)
534+
storesTypeCreateCmd.Flags().StringVarP(
535+
&storeTypeName,
536+
"name",
537+
"n",
538+
"",
539+
"Short name of the certificate store type to get. Valid choices are: "+validTypesString,
540+
)
508541
storesTypeCreateCmd.Flags().BoolVarP(&listValidStoreTypes, "list", "l", false, "List valid store types.")
509-
storesTypeCreateCmd.Flags().StringVarP(&filePath, "from-file", "f", "", "Path to a JSON file containing certificate store type data for a single store.")
510-
storesTypeCreateCmd.Flags().StringVarP(&gitRef, FlagGitRef, "b", "main", "The git branch or tag to reference when pulling store-types from the internet.")
542+
storesTypeCreateCmd.Flags().StringVarP(
543+
&filePath,
544+
"from-file",
545+
"f",
546+
"",
547+
"Path to a JSON file containing certificate store type data for a single store.",
548+
)
549+
storesTypeCreateCmd.Flags().StringVarP(
550+
&gitRef,
551+
FlagGitRef,
552+
"b",
553+
"main",
554+
"The git branch or tag to reference when pulling store-types from the internet.",
555+
)
511556
storesTypeCreateCmd.Flags().BoolVarP(&createAll, "all", "a", false, "Create all store types.")
512557

513558
// UPDATE command
@@ -519,7 +564,13 @@ func init() {
519564
var dryRun bool
520565
storeTypesCmd.AddCommand(storesTypeDeleteCmd)
521566
storesTypeDeleteCmd.Flags().IntVarP(&storeTypeID, "id", "i", -1, "ID of the certificate store type to delete.")
522-
storesTypeDeleteCmd.Flags().StringVarP(&storeTypeName, "name", "n", "", "Name of the certificate store type to delete.")
567+
storesTypeDeleteCmd.Flags().StringVarP(
568+
&storeTypeName,
569+
"name",
570+
"n",
571+
"",
572+
"Name of the certificate store type to delete.",
573+
)
523574
storesTypeDeleteCmd.Flags().BoolVarP(&dryRun, "dry-run", "t", false, "Specifies whether to perform a dry run.")
524575
storesTypeDeleteCmd.MarkFlagsMutuallyExclusive("id", "name")
525576
storesTypeDeleteCmd.Flags().BoolVarP(&deleteAll, "all", "a", false, "Delete all store types.")

0 commit comments

Comments
 (0)