diff --git a/artifactory/commands/utils/templateutils.go b/artifactory/commands/utils/templateutils.go index 08d1be79a..f88f5854c 100644 --- a/artifactory/commands/utils/templateutils.go +++ b/artifactory/commands/utils/templateutils.go @@ -21,15 +21,15 @@ type TemplateUserCommand interface { Vars() string } -func ConvertTemplateToMap(tuc TemplateUserCommand) (map[string]interface{}, error) { +func ConvertTemplateToMap(templateUserCommand TemplateUserCommand) (map[string]interface{}, error) { // Read the template file - content, err := fileutils.ReadFile(tuc.TemplatePath()) + content, err := fileutils.ReadFile(templateUserCommand.TemplatePath()) if errorutils.CheckError(err) != nil { return nil, err } // Replace vars string-by-string if needed - if len(tuc.Vars()) > 0 { - templateVars := coreutils.SpecVarsStringToMap(tuc.Vars()) + if len(templateUserCommand.Vars()) > 0 { + templateVars := coreutils.SpecVarsStringToMap(templateUserCommand.Vars()) content = coreutils.ReplaceVars(content, templateVars) } // Unmarshal template to a map @@ -38,6 +38,36 @@ func ConvertTemplateToMap(tuc TemplateUserCommand) (map[string]interface{}, erro return configMap, errorutils.CheckError(err) } +func ConvertTemplateToMaps(templateUserCommand TemplateUserCommand) (interface{}, error) { + content, err := fileutils.ReadFile(templateUserCommand.TemplatePath()) + if err != nil { + return nil, errorutils.CheckError(err) + } + // Replace vars string-by-string if needed + if len(templateUserCommand.Vars()) > 0 { + templateVars := coreutils.SpecVarsStringToMap(templateUserCommand.Vars()) + content = coreutils.ReplaceVars(content, templateVars) + } + + var multiRepoCreateEntities []map[string]interface{} + err = json.Unmarshal(content, &multiRepoCreateEntities) + if err == nil { + return multiRepoCreateEntities, nil + } + + if _, ok := err.(*json.SyntaxError); ok { + return nil, errorutils.CheckError(err) + } + + var repoCreateEntity map[string]interface{} + err = json.Unmarshal(content, &repoCreateEntity) + if err == nil { + return repoCreateEntity, nil + } + + return nil, errorutils.CheckError(err) +} + func ValidateMapEntry(key string, value interface{}, writersMap map[string]ioutils.AnswerWriter) error { if _, ok := writersMap[key]; !ok { return errorutils.CheckErrorf("template syntax error: unknown key: \"" + key + "\".") diff --git a/go.mod b/go.mod index 0f1ca2dad..41c311cb2 100644 --- a/go.mod +++ b/go.mod @@ -114,7 +114,7 @@ require ( sigs.k8s.io/yaml v1.4.0 // indirect ) -// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20250707095624-7062538a0961 +replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20250717041744-d3ea4d99f4e7 // replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20250611113558-c1a092f216fd diff --git a/go.sum b/go.sum index 6a280e965..502fb5b70 100644 --- a/go.sum +++ b/go.sum @@ -113,8 +113,8 @@ github.com/jfrog/build-info-go v1.10.14 h1:PWnw+rBwiQTHZ5q+84+E8MHFjtAQkB3+Oc2sK github.com/jfrog/build-info-go v1.10.14/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE= github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s= github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4= -github.com/jfrog/jfrog-client-go v1.54.2 h1:z7GjCyIbV5Wx35USVDCF/0vf/fCWki++pZ7lcKt0gj0= -github.com/jfrog/jfrog-client-go v1.54.2/go.mod h1:1v0eih4thdPA4clBo9TuvAMT25sGDr1IQJ81DXQ/lBY= +github.com/jfrog/jfrog-client-go v1.28.1-0.20250717041744-d3ea4d99f4e7 h1:IHClKKEHPZMR1UWTTVYjqf3asYrCuEq1wd4lI/ASHRQ= +github.com/jfrog/jfrog-client-go v1.28.1-0.20250717041744-d3ea4d99f4e7/go.mod h1:1v0eih4thdPA4clBo9TuvAMT25sGDr1IQJ81DXQ/lBY= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=