@@ -91,8 +91,9 @@ var storesTypeCreateCmd = &cobra.Command{
9191 cmd .SilenceUsage = true
9292 // Specific flags
9393 gitRef , _ := cmd .Flags ().GetString (FlagGitRef )
94+ gitRepo , _ := cmd .Flags ().GetString (FlagGitRepo )
9495 creatAll , _ := cmd .Flags ().GetBool ("all" )
95- validStoreTypes := getValidStoreTypes ("" , gitRef )
96+ validStoreTypes := getValidStoreTypes ("" , gitRef , gitRepo )
9697 storeType , _ := cmd .Flags ().GetString ("name" )
9798 listTypes , _ := cmd .Flags ().GetBool ("list" )
9899 storeTypeConfigFile , _ := cmd .Flags ().GetString ("from-file" )
@@ -110,7 +111,10 @@ var storesTypeCreateCmd = &cobra.Command{
110111
111112 // CLI Logic
112113 if gitRef == "" {
113- gitRef = "main"
114+ gitRef = DefaultGitRef
115+ }
116+ if gitRepo == "" {
117+ gitRepo = DefaultGitRepo
114118 }
115119 storeTypeIsValid := false
116120
@@ -119,6 +123,7 @@ var storesTypeCreateCmd = &cobra.Command{
119123 Str ("storeTypeConfigFile" , storeTypeConfigFile ).
120124 Bool ("creatAll" , creatAll ).
121125 Str ("gitRef" , gitRef ).
126+ Str ("gitRepo" , gitRepo ).
122127 Strs ("validStoreTypes" , validStoreTypes ).
123128 Msg ("create command flags" )
124129
@@ -183,7 +188,7 @@ var storesTypeCreateCmd = &cobra.Command{
183188 } else {
184189 typesToCreate = validStoreTypes
185190 }
186- storeTypeConfig , stErr := readStoreTypesConfig ("" , gitRef , offline )
191+ storeTypeConfig , stErr := readStoreTypesConfig ("" , gitRef , gitRepo , offline )
187192 if stErr != nil {
188193 log .Error ().Err (stErr ).Send ()
189194 return stErr
@@ -263,7 +268,7 @@ var storesTypeDeleteCmd = &cobra.Command{
263268 validStoreTypesResp , vstErr := kfClient .ListCertificateStoreTypes ()
264269 if vstErr != nil {
265270 log .Error ().Err (vstErr ).Msg ("unable to list certificate store types" )
266- validStoreTypes = getValidStoreTypes ("" , gitRef )
271+ validStoreTypes = getValidStoreTypes ("" , gitRef , DefaultGitRepo )
267272 } else {
268273 for _ , v := range * validStoreTypesResp {
269274 validStoreTypes = append (validStoreTypes , v .ShortName )
@@ -360,6 +365,7 @@ var fetchStoreTypesCmd = &cobra.Command{
360365 cmd .SilenceUsage = true
361366 // Specific flags
362367 gitRef , _ := cmd .Flags ().GetString (FlagGitRef )
368+ gitRepo , _ := cmd .Flags ().GetString (FlagGitRepo )
363369
364370 // Debug + expEnabled checks
365371 isExperimental := false
@@ -372,7 +378,7 @@ var fetchStoreTypesCmd = &cobra.Command{
372378 if gitRef == "" {
373379 gitRef = "main"
374380 }
375- templates , err := readStoreTypesConfig ("" , gitRef , offline )
381+ templates , err := readStoreTypesConfig ("" , gitRef , gitRepo , offline )
376382 if err != nil {
377383 log .Error ().Err (err ).Send ()
378384 return err
@@ -480,15 +486,26 @@ func formatStoreTypes(sTypesList *[]interface{}) (map[string]interface{}, error)
480486 return output , nil
481487}
482488
483- func getStoreTypesInternet (gitRef string ) (map [string ]interface {}, error ) {
489+ func getStoreTypesInternet (gitRef string , repo string ) (map [string ]interface {}, error ) {
484490 //resp, err := http.Get("https://raw.githubusercontent.com/keyfactor/kfutil/main/store_types.json")
485491 //resp, err := http.Get("https://raw.githubusercontent.com/keyfactor/kfctl/master/storetypes/storetypes.json")
486492
487- baseUrl := "https://raw.githubusercontent.com/Keyfactor/kfutil /%s/store_types.json "
493+ baseUrl := "https://raw.githubusercontent.com/Keyfactor/%s /%s/%s "
488494 if gitRef == "" {
489- gitRef = "main"
495+ gitRef = DefaultGitRef
496+ }
497+ if repo == "" {
498+ repo = DefaultGitRepo
499+ }
500+
501+ var fileName string
502+ if repo == "kfutil" {
503+ fileName = "store_types.json"
504+ } else {
505+ fileName = "integration-manifest.json"
490506 }
491- url := fmt .Sprintf (baseUrl , gitRef )
507+
508+ url := fmt .Sprintf (baseUrl , repo , gitRef , fileName )
492509 log .Debug ().
493510 Str ("url" , url ).
494511 Msg ("Getting store types from internet" )
@@ -513,7 +530,23 @@ func getStoreTypesInternet(gitRef string) (map[string]interface{}, error) {
513530 var result []interface {}
514531 jErr := json .Unmarshal (body , & result )
515532 if jErr != nil {
516- return nil , jErr
533+ log .Warn ().Err (jErr ).Msg ("Unable to decode JSON file, attempting to parse an integration manifest" )
534+ // Attempt to parse as an integration manifest
535+ var manifest IntegrationManifest
536+ log .Debug ().Msg ("Decoding JSON file as integration manifest" )
537+ // Reset the file pointer
538+
539+ mErr := json .Unmarshal (body , & manifest )
540+ if mErr != nil {
541+ return nil , jErr
542+ }
543+ log .Debug ().Msg ("Decoded JSON file as integration manifest" )
544+ sTypes := manifest .About .Orchestrator .StoreTypes
545+ output := make (map [string ]interface {})
546+ for _ , st := range sTypes {
547+ output [st .ShortName ] = st
548+ }
549+ return output , nil
517550 }
518551 output , sErr := formatStoreTypes (& result )
519552 if sErr != nil {
@@ -525,18 +558,20 @@ func getStoreTypesInternet(gitRef string) (map[string]interface{}, error) {
525558
526559}
527560
528- func getValidStoreTypes (fp string , gitRef string ) []string {
561+ func getValidStoreTypes (fp string , gitRef string , gitRepo string ) []string {
529562 log .Debug ().
530563 Str ("file" , fp ).
531564 Str ("gitRef" , gitRef ).
565+ Str ("gitRepo" , gitRepo ).
532566 Bool ("offline" , offline ).
533567 Msg (DebugFuncEnter )
534568
535569 log .Debug ().
536570 Str ("file" , fp ).
537571 Str ("gitRef" , gitRef ).
572+ Str ("gitRepo" , gitRepo ).
538573 Msg ("Reading store types config." )
539- validStoreTypes , rErr := readStoreTypesConfig (fp , gitRef , offline )
574+ validStoreTypes , rErr := readStoreTypesConfig (fp , gitRef , gitRepo , offline )
540575 if rErr != nil {
541576 log .Error ().Err (rErr ).Msg ("unable to read store types" )
542577 return nil
@@ -549,7 +584,7 @@ func getValidStoreTypes(fp string, gitRef string) []string {
549584 return validStoreTypesList
550585}
551586
552- func readStoreTypesConfig (fp , gitRef string , offline bool ) (map [string ]interface {}, error ) {
587+ func readStoreTypesConfig (fp , gitRef string , gitRepo string , offline bool ) (map [string ]interface {}, error ) {
553588 log .Debug ().Str ("file" , fp ).Str ("gitRef" , gitRef ).Msg ("Entering readStoreTypesConfig" )
554589
555590 var (
@@ -560,7 +595,7 @@ func readStoreTypesConfig(fp, gitRef string, offline bool) (map[string]interface
560595 log .Debug ().Msg ("Reading store types config from file" )
561596 } else {
562597 log .Debug ().Msg ("Reading store types config from internet" )
563- sTypes , stErr = getStoreTypesInternet (gitRef )
598+ sTypes , stErr = getStoreTypesInternet (gitRef , gitRepo )
564599 }
565600
566601 if stErr != nil || sTypes == nil || len (sTypes ) == 0 {
@@ -600,11 +635,11 @@ func readStoreTypesConfig(fp, gitRef string, offline bool) (map[string]interface
600635}
601636
602637func init () {
603- defaultGitRef := "main"
604638 offline = true // temporarily set to true as it runs before the flag is set
605639 debugFlag = false // temporarily set to false as it runs before the flag is set
606640 var gitRef string
607- validTypesString := strings .Join (getValidStoreTypes ("" , defaultGitRef ), ", " )
641+ var gitRepo string
642+ validTypesString := strings .Join (getValidStoreTypes ("" , DefaultGitRef , DefaultGitRepo ), ", " )
608643 offline = false //revert this so that flag is not set to true by default
609644 RootCmd .AddCommand (storeTypesCmd )
610645
@@ -618,6 +653,14 @@ func init() {
618653 "The git branch or tag to reference when pulling store-types from the internet." ,
619654 )
620655
656+ fetchStoreTypesCmd .Flags ().StringVarP (
657+ & gitRepo ,
658+ FlagGitRepo ,
659+ "r" ,
660+ DefaultGitRepo ,
661+ "The repository to pull store-type definitions from." ,
662+ )
663+
621664 // LIST command
622665 storeTypesCmd .AddCommand (storesTypesListCmd )
623666
@@ -653,6 +696,14 @@ func init() {
653696 "main" ,
654697 "The git branch or tag to reference when pulling store-types from the internet." ,
655698 )
699+ storesTypeCreateCmd .Flags ().StringVarP (
700+ & gitRepo ,
701+ FlagGitRepo ,
702+ "r" ,
703+ DefaultGitRepo ,
704+ "The repository to pull store-types definitions from." ,
705+ )
706+
656707 storesTypeCreateCmd .Flags ().BoolVarP (& createAll , "all" , "a" , false , "Create all store types." )
657708
658709 // UPDATE command
0 commit comments