Skip to content

Commit ed3634b

Browse files
author
Sahar Bracha
committed
Add artifacts source to create application version spec
1 parent added11 commit ed3634b

File tree

7 files changed

+247
-2
lines changed

7 files changed

+247
-2
lines changed

apptrust/commands/version/create_app_version_cmd.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type createAppVersionCommand struct {
2929
}
3030

3131
type createVersionSpec struct {
32+
Artifacts []model.CreateVersionArtifact `json:"artifacts,omitempty"`
3233
Packages []model.CreateVersionPackage `json:"packages,omitempty"`
3334
Builds []model.CreateVersionBuild `json:"builds,omitempty"`
3435
ReleaseBundles []model.CreateVersionReleaseBundle `json:"release_bundles,omitempty"`
@@ -137,11 +138,12 @@ func (cv *createAppVersionCommand) loadFromSpec(ctx *components.Context) (*model
137138
}
138139

139140
// Validation: if all sources are empty, return error
140-
if (len(spec.Packages) == 0) && (len(spec.Builds) == 0) && (len(spec.ReleaseBundles) == 0) && (len(spec.Versions) == 0) {
141-
return nil, errorutils.CheckErrorf("Spec file is empty: must provide at least one source (packages, builds, release_bundles, or versions)")
141+
if (len(spec.Packages) == 0) && (len(spec.Builds) == 0) && (len(spec.ReleaseBundles) == 0) && (len(spec.Versions) == 0) && (len(spec.Artifacts) == 0) {
142+
return nil, errorutils.CheckErrorf("Spec file is empty: must provide at least one source (artifacts, packages, builds, release_bundles, or versions)")
142143
}
143144

144145
sources := &model.CreateVersionSources{
146+
Artifacts: spec.Artifacts,
145147
Packages: spec.Packages,
146148
Builds: spec.Builds,
147149
ReleaseBundles: spec.ReleaseBundles,

apptrust/commands/version/create_app_version_cmd_test.go

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,143 @@ func TestCreateAppVersionCommand_SpecFileSuite(t *testing.T) {
462462
expectsError: true,
463463
errorContains: "Spec file is empty",
464464
},
465+
{
466+
name: "artifacts spec file",
467+
specPath: "./testfiles/artifacts-spec.json",
468+
args: []string{"app-artifacts", "1.0.0"},
469+
expectsPayload: &model.CreateAppVersionRequest{
470+
ApplicationKey: "app-artifacts",
471+
Version: "1.0.0",
472+
Sources: &model.CreateVersionSources{
473+
Artifacts: []model.CreateVersionArtifact{
474+
{
475+
Path: "repo/path/to/artifact1.jar",
476+
SHA256: "abc123def456",
477+
},
478+
{
479+
Path: "repo/path/to/artifact2.war",
480+
},
481+
},
482+
},
483+
},
484+
},
485+
{
486+
name: "artifacts only spec file",
487+
specPath: "./testfiles/artifacts-only-spec.json",
488+
args: []string{"app-single-artifact", "2.0.0"},
489+
expectsPayload: &model.CreateAppVersionRequest{
490+
ApplicationKey: "app-single-artifact",
491+
Version: "2.0.0",
492+
Sources: &model.CreateVersionSources{
493+
Artifacts: []model.CreateVersionArtifact{
494+
{
495+
Path: "repo/path/to/single-artifact.jar",
496+
SHA256: "1234567890abcdef",
497+
},
498+
},
499+
},
500+
},
501+
},
502+
{
503+
name: "mixed sources with artifacts spec file",
504+
specPath: "./testfiles/mixed-sources-spec.json",
505+
args: []string{"app-mixed", "3.0.0"},
506+
expectsPayload: &model.CreateAppVersionRequest{
507+
ApplicationKey: "app-mixed",
508+
Version: "3.0.0",
509+
Sources: &model.CreateVersionSources{
510+
Artifacts: []model.CreateVersionArtifact{
511+
{
512+
Path: "repo/path/to/artifact.jar",
513+
SHA256: "abc123",
514+
},
515+
},
516+
Packages: []model.CreateVersionPackage{
517+
{
518+
Type: "npm",
519+
Name: "my-package",
520+
Version: "1.0.0",
521+
Repository: "npm-repo",
522+
},
523+
},
524+
Builds: []model.CreateVersionBuild{
525+
{
526+
Name: "build1",
527+
Number: "42",
528+
},
529+
},
530+
},
531+
},
532+
},
533+
{
534+
name: "all sources spec file",
535+
specPath: "./testfiles/all-sources-spec.json",
536+
args: []string{"app-all-sources", "5.0.0"},
537+
expectsPayload: &model.CreateAppVersionRequest{
538+
ApplicationKey: "app-all-sources",
539+
Version: "5.0.0",
540+
Sources: &model.CreateVersionSources{
541+
Artifacts: []model.CreateVersionArtifact{
542+
{
543+
Path: "repo/path/to/app.jar",
544+
SHA256: "abc123def456789",
545+
},
546+
{
547+
Path: "repo/path/to/lib.war",
548+
},
549+
},
550+
Packages: []model.CreateVersionPackage{
551+
{
552+
Type: "npm",
553+
Name: "my-package",
554+
Version: "1.2.3",
555+
Repository: "npm-local",
556+
},
557+
{
558+
Type: "docker",
559+
Name: "my-docker-image",
560+
Version: "2.0.0",
561+
Repository: "docker-local",
562+
},
563+
},
564+
Builds: []model.CreateVersionBuild{
565+
{
566+
Name: "my-build",
567+
Number: "123",
568+
IncludeDependencies: true,
569+
},
570+
{
571+
Name: "another-build",
572+
Number: "456",
573+
RepositoryKey: "build-info",
574+
IncludeDependencies: false,
575+
},
576+
},
577+
ReleaseBundles: []model.CreateVersionReleaseBundle{
578+
{
579+
Name: "my-release-bundle",
580+
Version: "1.0.0",
581+
ProjectKey: "my-project",
582+
RepositoryKey: "rb-repo",
583+
},
584+
{
585+
Name: "another-bundle",
586+
Version: "2.0.0",
587+
},
588+
},
589+
Versions: []model.CreateVersionReference{
590+
{
591+
ApplicationKey: "dependency-app-1",
592+
Version: "3.0.0",
593+
},
594+
{
595+
ApplicationKey: "dependency-app-2",
596+
Version: "4.5.6",
597+
},
598+
},
599+
},
600+
},
601+
},
465602
}
466603

467604
for _, tt := range tests {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"artifacts": [
3+
{
4+
"path": "repo/path/to/app.jar",
5+
"sha256": "abc123def456789"
6+
},
7+
{
8+
"path": "repo/path/to/lib.war"
9+
}
10+
],
11+
"packages": [
12+
{
13+
"type": "npm",
14+
"name": "my-package",
15+
"version": "1.2.3",
16+
"repository_key": "npm-local"
17+
},
18+
{
19+
"type": "docker",
20+
"name": "my-docker-image",
21+
"version": "2.0.0",
22+
"repository_key": "docker-local"
23+
}
24+
],
25+
"builds": [
26+
{
27+
"name": "my-build",
28+
"number": "123",
29+
"include_dependencies": true
30+
},
31+
{
32+
"name": "another-build",
33+
"number": "456",
34+
"repository_key": "build-info",
35+
"include_dependencies": false
36+
}
37+
],
38+
"release_bundles": [
39+
{
40+
"name": "my-release-bundle",
41+
"version": "1.0.0",
42+
"project_key": "my-project",
43+
"repository_key": "rb-repo"
44+
},
45+
{
46+
"name": "another-bundle",
47+
"version": "2.0.0"
48+
}
49+
],
50+
"versions": [
51+
{
52+
"application_key": "dependency-app-1",
53+
"version": "3.0.0"
54+
},
55+
{
56+
"application_key": "dependency-app-2",
57+
"version": "4.5.6"
58+
}
59+
]
60+
}
61+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"artifacts": [
3+
{
4+
"path": "repo/path/to/single-artifact.jar",
5+
"sha256": "1234567890abcdef"
6+
}
7+
]
8+
}
9+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"artifacts": [
3+
{
4+
"path": "repo/path/to/artifact1.jar",
5+
"sha256": "abc123def456"
6+
},
7+
{
8+
"path": "repo/path/to/artifact2.war"
9+
}
10+
]
11+
}
12+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"artifacts": [
3+
{
4+
"path": "repo/path/to/artifact.jar",
5+
"sha256": "abc123"
6+
}
7+
],
8+
"packages": [
9+
{
10+
"type": "npm",
11+
"name": "my-package",
12+
"version": "1.0.0",
13+
"repository_key": "npm-repo"
14+
}
15+
],
16+
"builds": [
17+
{
18+
"name": "build1",
19+
"number": "42"
20+
}
21+
]
22+
}
23+

apptrust/model/create_app_version_request.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type CreateVersionPackage struct {
1515
}
1616

1717
type CreateVersionSources struct {
18+
Artifacts []CreateVersionArtifact `json:"artifacts,omitempty"`
1819
Packages []CreateVersionPackage `json:"packages,omitempty"`
1920
Builds []CreateVersionBuild `json:"builds,omitempty"`
2021
ReleaseBundles []CreateVersionReleaseBundle `json:"release_bundles,omitempty"`

0 commit comments

Comments
 (0)