diff --git a/internal/upload/batch.go b/internal/upload/batch.go index a0398376..319d51f2 100644 --- a/internal/upload/batch.go +++ b/internal/upload/batch.go @@ -299,9 +299,9 @@ func (boolOrString *boolOrString) MarshalJSON() ([]byte, error) { } type purlConfig struct { - PackageURL string `json:"pURL" yaml:"pURL"` - Version boolOrString `json:"version" yaml:"version"` // Either false or version string - FileRegex string `json:"fileRegex" yaml:"fileRegex"` + PackageURL string `json:"pURL" yaml:"pURL"` + Version boolOrString `json:"version" yaml:"version"` // Either false or version string + FileRegexes []string `json:"fileRegexes" yaml:"fileRegexes"` } type DebrickedConfig struct { @@ -332,8 +332,14 @@ func printSuccessfulUpload(f string) { fmt.Printf("Successfully uploaded: %s\n", color.YellowString(f)) } +type pURLConfigYAML struct { + PackageURL string `yaml:"pURL"` + Version *string `yaml:"version"` + FileRegexes []string `yaml:"fileRegexes"` +} + type DebrickedConfigYAML struct { - Overrides []map[string]string `yaml:"overrides"` + Overrides []pURLConfigYAML `yaml:"overrides"` } func GetDebrickedConfig(path string) DebrickedConfig { @@ -354,16 +360,16 @@ func GetDebrickedConfig(path string) DebrickedConfig { for _, entry := range yamlConfig.Overrides { var version string var exist bool - pURL := entry["pURL"] - fileRegex := entry["fileRegex"] - if _, exist = entry["version"]; exist { - version = entry["version"] - exist = true - } else { + pURL := entry.PackageURL + fileRegexes := entry.FileRegexes + if entry.Version == nil { version = "" exist = false + } else { + version = *entry.Version + exist = true } - overrides = append(overrides, purlConfig{PackageURL: pURL, Version: boolOrString{Version: version, HasVersion: exist}, FileRegex: fileRegex}) + overrides = append(overrides, purlConfig{PackageURL: pURL, Version: boolOrString{Version: version, HasVersion: exist}, FileRegexes: fileRegexes}) } return DebrickedConfig{ diff --git a/internal/upload/batch_test.go b/internal/upload/batch_test.go index 5d037ed7..35ae3287 100644 --- a/internal/upload/batch_test.go +++ b/internal/upload/batch_test.go @@ -141,14 +141,14 @@ func TestGetDebrickedConfig(t *testing.T) { expectedJSON, err := json.Marshal(DebrickedConfig{ Overrides: []purlConfig{ { - PackageURL: "pkg:npm/lodash", - Version: boolOrString{Version: "1.0.0", HasVersion: true}, - FileRegex: ".*/lodash/.*", + PackageURL: "pkg:npm/lodash", + Version: boolOrString{Version: "1.0.0", HasVersion: true}, + FileRegexes: []string{".*/lodash/.*"}, }, { - PackageURL: "pkg:maven/org.openjfx/javafx-base", - Version: boolOrString{Version: "", HasVersion: false}, - FileRegex: "subpath/org.openjfx/.*", + PackageURL: "pkg:maven/org.openjfx/javafx-base", + Version: boolOrString{Version: "", HasVersion: false}, + FileRegexes: []string{"subpath/org.openjfx/.*"}, }, }, }) @@ -180,18 +180,18 @@ func TestMarshalJSONDebrickedConfig(t *testing.T) { config, err := json.Marshal(DebrickedConfig{ Overrides: []purlConfig{ { - PackageURL: "pkg:npm/lodash", - Version: boolOrString{Version: "1.0.0", HasVersion: true}, - FileRegex: ".*/lodash/.*", + PackageURL: "pkg:npm/lodash", + Version: boolOrString{Version: "1.0.0", HasVersion: true}, + FileRegexes: []string{".*/lodash/.*"}, }, { - PackageURL: "pkg:maven/org.openjfx/javafx-base", - Version: boolOrString{Version: "", HasVersion: false}, - FileRegex: "subpath/org.openjfx/.*", + PackageURL: "pkg:maven/org.openjfx/javafx-base", + Version: boolOrString{Version: "", HasVersion: false}, + FileRegexes: []string{"subpath/org.openjfx/.*"}, }, }, }) - expectedJSON := "{\"overrides\":[{\"pURL\":\"pkg:npm/lodash\",\"version\":\"1.0.0\",\"fileRegex\":\".*/lodash/.*\"},{\"pURL\":\"pkg:maven/org.openjfx/javafx-base\",\"version\":false,\"fileRegex\":\"subpath/org.openjfx/.*\"}]}" + expectedJSON := "{\"overrides\":[{\"pURL\":\"pkg:npm/lodash\",\"version\":\"1.0.0\",\"fileRegexes\":[\".*/lodash/.*\"]},{\"pURL\":\"pkg:maven/org.openjfx/javafx-base\",\"version\":false,\"fileRegexes\":[\"subpath/org.openjfx/.*\"]}]}" assert.Nil(t, err) assert.Equal(t, []byte(expectedJSON), config) } diff --git a/internal/upload/testdata/debricked-config.yaml b/internal/upload/testdata/debricked-config.yaml index c886ff30..1481b3e3 100644 --- a/internal/upload/testdata/debricked-config.yaml +++ b/internal/upload/testdata/debricked-config.yaml @@ -1,6 +1,8 @@ overrides: - pURL: "pkg:npm/lodash" version: "1.0.0" # optional: if left out, we will decide version - fileRegex: ".*/lodash/.*" # PCRE2 + fileRegexes: + - ".*/lodash/.*" # PCRE2 - pURL: "pkg:maven/org.openjfx/javafx-base" - fileRegex: "subpath/org.openjfx/.*" + fileRegexes: + - "subpath/org.openjfx/.*"