Skip to content

Commit

Permalink
Added distribution PathMappings validations
Browse files Browse the repository at this point in the history
  • Loading branch information
Yarden-Edery committed Nov 14, 2023
1 parent bd68272 commit eb9a27f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions common/spec/specfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func CreateSpecFromFile(specFilePath string, specVars map[string]string) (spec *

type File struct {
Aql utils.Aql
PathMapping utils.PathMapping `json:"mappings"`
Pattern string
Exclusions []string
Target string
Expand Down Expand Up @@ -148,6 +149,7 @@ func (f *File) ToCommonParams() (*utils.CommonParams, error) {
}

params.Aql = f.Aql
params.PathMapping = f.PathMapping
params.Pattern = f.Pattern
params.Exclusions = f.Exclusions
params.Target = f.Target
Expand All @@ -171,6 +173,7 @@ func ValidateSpec(files []File, isTargetMandatory, isSearchBasedSpec bool) error

for _, file := range files {
isAql := len(file.Aql.ItemsFind) > 0
isPathMapping := len(file.PathMapping.Input) > 0 && len(file.PathMapping.Output) > 0
isPattern := len(file.Pattern) > 0
isExclusions := len(file.Exclusions) > 0 && len(file.Exclusions[0]) > 0
isTarget := len(file.Target) > 0
Expand All @@ -194,6 +197,9 @@ func ValidateSpec(files []File, isTargetMandatory, isSearchBasedSpec bool) error
isBypassArchiveInspection, _ := file.IsBypassArchiveInspection(false)
isTransitive, _ := file.IsTransitive(false)

if isPathMapping && !isAql {
return errorutils.CheckErrorf("mappings supported only with Aql")
}
if isTargetMandatory && !isTarget {
return errorutils.CheckErrorf("spec must include target")
}
Expand All @@ -206,6 +212,12 @@ func ValidateSpec(files []File, isTargetMandatory, isSearchBasedSpec bool) error
if isSearchBasedSpec && !isAql && !isPattern && !isBuild && !isBundle {
return errorutils.CheckErrorf("spec must include either aql, pattern, build or bundle")
}
if isPathMapping && isTarget {
return fileSpecValidationError("mappings", "target")
}
if isPathMapping && isPattern {
return fileSpecValidationError("mappings", "pattern")
}
if isOffset {
if isBuild {
return fileSpecValidationError("build", "offset")
Expand Down

0 comments on commit eb9a27f

Please sign in to comment.