@@ -3,6 +3,7 @@ package version
33import (
44 "encoding/json"
55 "strconv"
6+ "strings"
67
78 "github.com/jfrog/jfrog-cli-application/apptrust/service/versions"
89
@@ -164,6 +165,10 @@ func (cv *createAppVersionCommand) parseBuilds(buildsStr string) ([]model.Create
164165 if err != nil {
165166 return nil , errorutils .CheckErrorf ("invalid build format: %v" , err )
166167 }
168+ err = validateRequiredFieldsInMap (buildEntryMap , nameField , idField )
169+ if err != nil {
170+ return nil , errorutils .CheckErrorf ("invalid build format: %v" , err )
171+ }
167172 build := model.CreateVersionBuild {
168173 Name : buildEntryMap [nameField ],
169174 Number : buildEntryMap [idField ],
@@ -193,6 +198,10 @@ func (cv *createAppVersionCommand) parseReleaseBundles(rbStr string) ([]model.Cr
193198 if err != nil {
194199 return nil , errorutils .CheckErrorf ("invalid release bundle format: %v" , err )
195200 }
201+ err = validateRequiredFieldsInMap (releaseBundleEntryMap , nameField , versionField )
202+ if err != nil {
203+ return nil , errorutils .CheckErrorf ("invalid release bundle format: %v" , err )
204+ }
196205 bundles = append (bundles , model.CreateVersionReleaseBundle {
197206 Name : releaseBundleEntryMap [nameField ],
198207 Version : releaseBundleEntryMap [versionField ],
@@ -214,6 +223,10 @@ func (cv *createAppVersionCommand) parseSourceVersions(applicationVersionsStr st
214223 if err != nil {
215224 return nil , errorutils .CheckErrorf ("invalid application version format: %v" , err )
216225 }
226+ err = validateRequiredFieldsInMap (applicationVersionEntryMap , applicationKeyField , versionField )
227+ if err != nil {
228+ return nil , errorutils .CheckErrorf ("invalid application version format: %v" , err )
229+ }
217230 refs = append (refs , model.CreateVersionReference {
218231 ApplicationKey : applicationVersionEntryMap [applicationKeyField ],
219232 Version : applicationVersionEntryMap [versionField ],
@@ -284,3 +297,15 @@ func validateNoSpecAndFlagsTogether(ctx *components.Context) error {
284297 }
285298 return nil
286299}
300+
301+ func validateRequiredFieldsInMap (m map [string ]string , requiredFields ... string ) error {
302+ if m == nil {
303+ return errorutils .CheckErrorf ("missing required fields: %v" , strings .Join (requiredFields , ", " ))
304+ }
305+ for _ , field := range requiredFields {
306+ if _ , exists := m [field ]; ! exists {
307+ return errorutils .CheckErrorf ("missing required field: %s" , field )
308+ }
309+ }
310+ return nil
311+ }
0 commit comments