Skip to content

Commit 6fa5830

Browse files
authored
Make the signing key optinal jf release-bundle-create (#2762)
1 parent d776596 commit 6fa5830

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

lifecycle/cli.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ func validateCreateReleaseBundleContext(c *cli.Context) error {
127127
return cliutils.WrongNumberOfArgumentsHandler(c)
128128
}
129129

130-
if err := assertSigningKeyProvided(c); err != nil {
131-
return err
132-
}
133-
134130
return assertValidCreationMethod(c)
135131
}
136132

@@ -188,10 +184,6 @@ func promote(c *cli.Context) error {
188184
return cliutils.WrongNumberOfArgumentsHandler(c)
189185
}
190186

191-
if err := assertSigningKeyProvided(c); err != nil {
192-
return err
193-
}
194-
195187
lcDetails, err := createLifecycleDetailsByFlags(c)
196188
if err != nil {
197189
return err
@@ -358,13 +350,6 @@ func validateDistributeCommand(c *cli.Context) error {
358350
return nil
359351
}
360352

361-
func assertSigningKeyProvided(c *cli.Context) error {
362-
if c.String(cliutils.SigningKey) == "" {
363-
return errorutils.CheckErrorf("the --%s option is mandatory", cliutils.SigningKey)
364-
}
365-
return nil
366-
}
367-
368353
func createLifecycleDetailsByFlags(c *cli.Context) (*coreConfig.ServerDetails, error) {
369354
lcDetails, err := cliutils.CreateServerDetailsWithConfigOffer(c, true, commonCliUtils.Platform)
370355
if err != nil {

lifecycle/cli_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ func TestValidateCreateReleaseBundleContext(t *testing.T) {
2121
{"extraArgs", []string{"one", "two", "three", "four"}, []string{}, true},
2222
{"bothSources", []string{"one", "two", "three"}, []string{cliutils.Builds + "=/path/to/file", cliutils.ReleaseBundles + "=/path/to/file"}, true},
2323
{"noSources", []string{"one", "two", "three"}, []string{}, true},
24-
{"builds without signing key", []string{"name", "version"}, []string{cliutils.Builds + "=/path/to/file"}, true},
24+
{"builds without signing key", []string{"name", "version"}, []string{cliutils.Builds + "=/path/to/file"}, false},
2525
{"builds correct", []string{"name", "version"}, []string{
2626
cliutils.Builds + "=/path/to/file", cliutils.SigningKey + "=key"}, false},
27-
{"releaseBundles without signing key", []string{"name", "version", "env"}, []string{cliutils.ReleaseBundles + "=/path/to/file"}, true},
27+
{"releaseBundles without signing key", []string{"name", "version"}, []string{cliutils.ReleaseBundles + "=/path/to/file"}, false},
2828
{"releaseBundles correct", []string{"name", "version"}, []string{
2929
cliutils.ReleaseBundles + "=/path/to/file", cliutils.SigningKey + "=key"}, false},
3030
{"spec without signing key", []string{"name", "version", "env"}, []string{"spec=/path/to/file"}, true},

lifecycle_test.go

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ import (
2929
)
3030

3131
const (
32-
artifactoryLifecycleMinVersion = "7.68.3"
33-
gpgKeyPairName = "lc-tests-key-pair"
34-
lcTestdataPath = "lifecycle"
35-
releaseBundlesSpec = "release-bundles-spec.json"
36-
buildsSpec12 = "builds-spec-1-2.json"
37-
buildsSpec3 = "builds-spec-3.json"
38-
prodEnvironment = "PROD"
39-
number1, number2, number3 = "111", "222", "333"
32+
artifactoryLifecycleMinVersion = "7.68.3"
33+
signingKeyOptionalArtifactoryMinVersion = "7.101.1"
34+
gpgKeyPairName = "lc-tests-key-pair"
35+
lcTestdataPath = "lifecycle"
36+
releaseBundlesSpec = "release-bundles-spec.json"
37+
buildsSpec12 = "builds-spec-1-2.json"
38+
buildsSpec3 = "builds-spec-3.json"
39+
prodEnvironment = "PROD"
40+
number1, number2, number3 = "111", "222", "333"
41+
withoutSigningKey = true
4042
)
4143

4244
var (
@@ -45,7 +47,7 @@ var (
4547
)
4648

4749
func TestBackwardCompatibleReleaseBundleCreation(t *testing.T) {
48-
cleanCallback := initLifecycleTest(t)
50+
cleanCallback := initLifecycleTest(t, artifactoryLifecycleMinVersion)
4951
defer cleanCallback()
5052
lcManager := getLcServiceManager(t)
5153

@@ -87,30 +89,39 @@ func compareRbArtifacts(t *testing.T, actual services.ReleaseBundleSpecResponse,
8789
}
8890

8991
func TestReleaseBundleCreationFromAql(t *testing.T) {
90-
testReleaseBundleCreation(t, tests.UploadDevSpecA, tests.LifecycleAql, tests.GetExpectedLifecycleCreationByAql())
92+
testReleaseBundleCreation(t, tests.UploadDevSpecA, tests.LifecycleAql, tests.GetExpectedLifecycleCreationByAql(), false)
9193
}
9294

9395
func TestReleaseBundleCreationFromArtifacts(t *testing.T) {
94-
testReleaseBundleCreation(t, tests.UploadDevSpec, tests.LifecycleArtifacts, tests.GetExpectedLifecycleCreationByArtifacts())
96+
testReleaseBundleCreation(t, tests.UploadDevSpec, tests.LifecycleArtifacts, tests.GetExpectedLifecycleCreationByArtifacts(), false)
9597
}
9698

97-
func testReleaseBundleCreation(t *testing.T, uploadSpec, creationSpec string, expected []string) {
98-
cleanCallback := initLifecycleTest(t)
99-
defer cleanCallback()
100-
lcManager := getLcServiceManager(t)
99+
func TestReleaseBundleCreationFromArtifactsWithoutSigningKey(t *testing.T) {
100+
testReleaseBundleCreation(t, tests.UploadDevSpec, tests.LifecycleArtifacts, tests.GetExpectedLifecycleCreationByArtifacts(), withoutSigningKey)
101+
}
102+
103+
func testReleaseBundleCreation(t *testing.T, uploadSpec, creationSpec string, expected []string, withoutSigningKey bool) {
104+
if withoutSigningKey {
105+
cleanCallback := initLifecycleTest(t, signingKeyOptionalArtifactoryMinVersion)
106+
defer cleanCallback()
107+
} else {
108+
cleanCallback := initLifecycleTest(t, artifactoryLifecycleMinVersion)
109+
defer cleanCallback()
110+
}
101111

112+
lcManager := getLcServiceManager(t)
102113
specFile, err := tests.CreateSpec(uploadSpec)
103114
assert.NoError(t, err)
104115
runRt(t, "upload", "--spec="+specFile)
105116

106-
createRbFromSpec(t, creationSpec, tests.LcRbName1, number1, true)
117+
createRbFromSpec(t, creationSpec, tests.LcRbName1, number1, true, withoutSigningKey)
107118
defer deleteReleaseBundle(t, lcManager, tests.LcRbName1, number1)
108119

109120
assertRbArtifacts(t, lcManager, tests.LcRbName1, number1, expected)
110121
}
111122

112123
func TestLifecycleFullFlow(t *testing.T) {
113-
cleanCallback := initLifecycleTest(t)
124+
cleanCallback := initLifecycleTest(t, signingKeyOptionalArtifactoryMinVersion)
114125
defer cleanCallback()
115126
lcManager := getLcServiceManager(t)
116127

@@ -119,17 +130,17 @@ func TestLifecycleFullFlow(t *testing.T) {
119130
defer deleteBuilds()
120131

121132
// Create release bundle from builds synchronously.
122-
createRbFromSpec(t, tests.LifecycleBuilds12, tests.LcRbName1, number1, true)
133+
createRbFromSpec(t, tests.LifecycleBuilds12, tests.LcRbName1, number1, true, false)
123134
defer deleteReleaseBundle(t, lcManager, tests.LcRbName1, number1)
124135

125136
// Create release bundle from a build asynchronously and assert status.
126137
// This build has dependencies which are included in the release bundle.
127-
createRbFromSpec(t, tests.LifecycleBuilds3, tests.LcRbName2, number2, false)
138+
createRbFromSpec(t, tests.LifecycleBuilds3, tests.LcRbName2, number2, false, false)
128139
defer deleteReleaseBundle(t, lcManager, tests.LcRbName2, number2)
129140
assertStatusCompleted(t, lcManager, tests.LcRbName2, number2, "")
130141

131142
// Create a combined release bundle from the two previous release bundle.
132-
createRbFromSpec(t, tests.LifecycleReleaseBundles, tests.LcRbName3, number3, true)
143+
createRbFromSpec(t, tests.LifecycleReleaseBundles, tests.LcRbName3, number3, true, false)
133144
defer deleteReleaseBundle(t, lcManager, tests.LcRbName3, number3)
134145

135146
// Promote the last release bundle to prod repo 1.
@@ -161,7 +172,7 @@ func TestLifecycleFullFlow(t *testing.T) {
161172

162173
// Import bundles only work on onPerm platforms
163174
func TestImportReleaseBundle(t *testing.T) {
164-
cleanCallback := initLifecycleTest(t)
175+
cleanCallback := initLifecycleTest(t, artifactoryLifecycleMinVersion)
165176
defer cleanCallback()
166177
wd, err := os.Getwd()
167178
assert.NoError(t, err)
@@ -195,22 +206,25 @@ func uploadBuilds(t *testing.T) func() {
195206
func createRbBackwardCompatible(t *testing.T, specName, sourceOption, rbName, rbVersion string, sync bool) {
196207
specFile, err := getSpecFile(specName)
197208
assert.NoError(t, err)
198-
createRb(t, specFile, sourceOption, rbName, rbVersion, sync)
209+
createRb(t, specFile, sourceOption, rbName, rbVersion, sync, false)
199210
}
200211

201-
func createRbFromSpec(t *testing.T, specName, rbName, rbVersion string, sync bool) {
212+
func createRbFromSpec(t *testing.T, specName, rbName, rbVersion string, sync bool, withoutSigningKey bool) {
202213
specFile, err := tests.CreateSpec(specName)
203214
assert.NoError(t, err)
204-
createRb(t, specFile, "spec", rbName, rbVersion, sync)
215+
createRb(t, specFile, "spec", rbName, rbVersion, sync, withoutSigningKey)
205216
}
206217

207-
func createRb(t *testing.T, specFilePath, sourceOption, rbName, rbVersion string, sync bool) {
218+
func createRb(t *testing.T, specFilePath, sourceOption, rbName, rbVersion string, sync bool, withoutSigningKey bool) {
208219
argsAndOptions := []string{
209220
"rbc",
210221
rbName,
211222
rbVersion,
212223
getOption(sourceOption, specFilePath),
213-
getOption(cliutils.SigningKey, gpgKeyPairName),
224+
}
225+
226+
if !withoutSigningKey {
227+
argsAndOptions = append(argsAndOptions, getOption(cliutils.SigningKey, gpgKeyPairName))
214228
}
215229
// Add the --sync option only if requested, to test the default value.
216230
if sync {
@@ -363,11 +377,12 @@ func uploadBuildWithDeps(t *testing.T, buildName, buildNumber string) {
363377
runRt(t, "build-publish", buildName, buildNumber)
364378
}
365379

366-
func initLifecycleTest(t *testing.T) (cleanCallback func()) {
380+
func initLifecycleTest(t *testing.T, minVersion string) (cleanCallback func()) {
367381
if !*tests.TestLifecycle {
368382
t.Skip("Skipping lifecycle test. To run release bundle test add the '-test.lc=true' option.")
369383
}
370-
validateArtifactoryVersion(t, artifactoryLifecycleMinVersion)
384+
385+
validateArtifactoryVersion(t, minVersion)
371386

372387
if !isLifecycleSupported(t) {
373388
t.Skip("Skipping lifecycle test because the functionality is not enabled on the provided JPD.")

utils/cliutils/commandsflags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ var flagsMap = map[string]cli.Flag{
16501650
},
16511651
lcSigningKey: cli.StringFlag{
16521652
Name: SigningKey,
1653-
Usage: "[Mandatory] The GPG/RSA key-pair name given in Artifactory.` `",
1653+
Usage: "[Optional] The GPG/RSA key-pair name given in Artifactory. If the key isn't provided, the command creates or uses the default key.` `",
16541654
},
16551655
lcPathMappingPattern: cli.StringFlag{
16561656
Name: PathMappingPattern,

0 commit comments

Comments
 (0)