Skip to content

Commit 20fcdf5

Browse files
committed
fix(stores): import csv return useful error message when invalid store-type name or ID are passed rather than panic.
Signed-off-by: spbsoluble <1661003+spbsoluble@users.noreply.github.com>
1 parent 9eeb238 commit 20fcdf5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

cmd/storesBulkOperations.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ var storesCreateFromCSVCmd = &cobra.Command{
213213

214214
// check for minimum necessary required fields for creating certificate stores
215215
log.Info().Msgf("Checking for minimum required fields for creating certificate stores")
216-
intID, reqPropertiesForStoreType := getRequiredProperties(st, *kfClient)
216+
intID, reqPropertiesForStoreType, pErr := getRequiredProperties(st, *kfClient)
217+
if pErr != nil {
218+
return pErr
219+
}
217220

218221
// if not present in header, throw error.
219222
headerRow := inFile[0]
@@ -863,13 +866,17 @@ func getHeadersForStoreType(id interface{}, kfClient api.Client) (int64, string,
863866
return intId, shortName, csvHeaders
864867
}
865868

866-
func getRequiredProperties(id interface{}, kfClient api.Client) (int64, []string) {
869+
func getRequiredProperties(id interface{}, kfClient api.Client) (int64, []string, error) {
867870

868871
storeType, err := kfClient.GetCertificateStoreType(id)
869872
if err != nil {
870-
log.Printf("Error: %s", err)
871-
fmt.Printf("Error: %s\n", err)
872-
panic("error retrieving store type")
873+
log.Error().
874+
Interface("id", id).
875+
Err(err).Msg("Error retrieving store type from Keyfactor Command")
876+
return 0, nil, fmt.Errorf(
877+
"error retrieving store type '%s' from Keyfactor Command, please ensure you're using `ShortName` or `Id`",
878+
id,
879+
)
873880
}
874881

875882
output, jErr := json.Marshal(storeType)
@@ -895,7 +902,7 @@ func getRequiredProperties(id interface{}, kfClient api.Client) (int64, []string
895902
}
896903
intId, _ := jsonParsedObj.S("StoreType").Data().(json.Number).Int64()
897904

898-
return intId, reqProps
905+
return intId, reqProps, nil
899906
}
900907

901908
func unmarshalPropertiesString(properties string) map[string]interface{} {

0 commit comments

Comments
 (0)