Skip to content

Commit 5fe3967

Browse files
committed
fix(cli/pam-types): Add support for V2 integration-manifest files.
Signed-off-by: spbsoluble <1661003+spbsoluble@users.noreply.github.com>
1 parent d698f04 commit 5fe3967

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

cmd/pamTypes.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ func getPAMTypesInternet(gitRef string, repo string) (map[string]interface{}, er
594594
if jErr != nil {
595595
log.Warn().Err(jErr).Msg("Unable to decode JSON file, attempting to parse an integration manifest")
596596
// Attempt to parse as an integration manifest
597-
var manifest IntegrationManifest
597+
var manifest IntegrationManifestV2
598598
log.Debug().Msg("Decoding JSON file as integration manifest")
599599
// Reset the file pointer
600600

@@ -842,22 +842,38 @@ func createPAMTypeFromFile(filename string, kfClient *keyfactor.Client) ([]keyfa
842842
if err != nil || (pamType.Name == "" || pamType.Parameters == nil) {
843843
log.Warn().Err(err).Msg("Unable to decode JSON file, attempting to parse an integration manifest")
844844
// Attempt to parse as an integration manifest
845-
var manifest IntegrationManifest
845+
var manifest IntegrationManifestV3
846846
log.Debug().Msg("Decoding JSON file as integration manifest")
847847
// Reset the file pointer
848848
_, err = file.Seek(0, 0)
849849
decoder = json.NewDecoder(file)
850850
mErr := decoder.Decode(&manifest)
851851
if mErr != nil {
852-
return nil, err
852+
log.Error().Err(err).Msg("Unable to decode JSON file as integration manifest V3")
853+
log.Debug().Msg("Attempting to decode as a V2 integration manifest")
854+
var v2Manifest IntegrationManifestV2
855+
_, err = file.Seek(0, 0)
856+
decoder = json.NewDecoder(file)
857+
v2MErr := decoder.Decode(&v2Manifest)
858+
if v2MErr != nil {
859+
log.Error().Err(err).Msg("Unable to decode JSON file as integration manifest V2")
860+
return nil, fmt.Errorf("invalid integration manifest format")
861+
}
862+
v2pamTypes := v2Manifest.About.PAM.PAMTypes
863+
log.Debug().Msg("Converting V2 manifest to V3")
864+
for _, v2pamType := range v2pamTypes {
865+
pamTypes = append(pamTypes, v2pamType)
866+
}
867+
} else {
868+
log.Debug().Msg("Decoded JSON file as integration manifest V3")
869+
pamTypes = manifest.About.PAM.PAMTypes
853870
}
854-
log.Debug().Msg("Decoded JSON file as integration manifest")
855-
pamTypes = manifest.About.PAM.PAMTypes
856871
} else {
857872
log.Debug().Msg("Decoded JSON file as single pam type")
858873
pamTypes = []keyfactor.ProviderTypeCreateRequest{pamType}
859874
}
860875

876+
log.Debug().Msg("successfully decoded JSON file")
861877
output := make([]keyfactor.ProviderTypeResponse, 0)
862878
for _, pt := range pamTypes {
863879
log.Debug().Msgf("Creating certificate pam type %s", pt.Name)

0 commit comments

Comments
 (0)