Skip to content

Commit 740d0d3

Browse files
authored
Add sha256 detailed-summary to release bundle create, update and sign (#1077)
1 parent 0917a85 commit 740d0d3

File tree

7 files changed

+139
-41
lines changed

7 files changed

+139
-41
lines changed

Diff for: artifactory/cli.go

+31-8
Original file line numberDiff line numberDiff line change
@@ -2307,8 +2307,7 @@ func buildPublishCmd(c *cli.Context) error {
23072307

23082308
err = commands.Exec(buildPublishCmd)
23092309
if buildPublishCmd.IsDetailedSummary() {
2310-
summary := buildPublishCmd.GetSummary()
2311-
if summary != nil {
2310+
if summary := buildPublishCmd.GetSummary(); summary != nil {
23122311
return cliutils.PrintBuildInfoSummaryReport(summary.IsSucceeded(), summary.GetSha256(), err)
23132312
}
23142313
}
@@ -2509,6 +2508,9 @@ func releaseBundleCreateCmd(c *cli.Context) error {
25092508
if !(c.NArg() == 2 && c.IsSet("spec") || (c.NArg() == 3 && !c.IsSet("spec"))) {
25102509
return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c)
25112510
}
2511+
if c.IsSet("detailed-summary") && !c.IsSet("sign") {
2512+
return cliutils.PrintHelpAndReturnError("The --detailed-summary option can't be used without --sign", c)
2513+
}
25122514
var releaseBundleCreateSpec *spec.SpecFiles
25132515
var err error
25142516
if c.IsSet("spec") {
@@ -2533,15 +2535,24 @@ func releaseBundleCreateCmd(c *cli.Context) error {
25332535
if err != nil {
25342536
return err
25352537
}
2536-
releaseBundleCreateCmd.SetServerDetails(rtDetails).SetReleaseBundleCreateParams(params).SetSpec(releaseBundleCreateSpec).SetDryRun(c.Bool("dry-run"))
2538+
releaseBundleCreateCmd.SetServerDetails(rtDetails).SetReleaseBundleCreateParams(params).SetSpec(releaseBundleCreateSpec).SetDryRun(c.Bool("dry-run")).SetDetailedSummary(c.Bool("detailed-summary"))
25372539

2538-
return commands.Exec(releaseBundleCreateCmd)
2540+
commands.Exec(releaseBundleCreateCmd)
2541+
if releaseBundleCreateCmd.IsDetailedSummary() {
2542+
if summary := releaseBundleCreateCmd.GetSummary(); summary != nil {
2543+
return cliutils.PrintBuildInfoSummaryReport(summary.IsSucceeded(), summary.GetSha256(), err)
2544+
}
2545+
}
2546+
return err
25392547
}
25402548

25412549
func releaseBundleUpdateCmd(c *cli.Context) error {
25422550
if !(c.NArg() == 2 && c.IsSet("spec") || (c.NArg() == 3 && !c.IsSet("spec"))) {
25432551
return cliutils.PrintHelpAndReturnError("Wrong number of arguments.", c)
25442552
}
2553+
if c.IsSet("detailed-summary") && !c.IsSet("sign") {
2554+
return cliutils.PrintHelpAndReturnError("The --detailed-summary option can't be used without --sign", c)
2555+
}
25452556
var releaseBundleUpdateSpec *spec.SpecFiles
25462557
var err error
25472558
if c.IsSet("spec") {
@@ -2566,9 +2577,15 @@ func releaseBundleUpdateCmd(c *cli.Context) error {
25662577
if err != nil {
25672578
return err
25682579
}
2569-
releaseBundleUpdateCmd.SetServerDetails(rtDetails).SetReleaseBundleUpdateParams(params).SetSpec(releaseBundleUpdateSpec).SetDryRun(c.Bool("dry-run"))
2580+
releaseBundleUpdateCmd.SetServerDetails(rtDetails).SetReleaseBundleUpdateParams(params).SetSpec(releaseBundleUpdateSpec).SetDryRun(c.Bool("dry-run")).SetDetailedSummary(c.Bool("detailed-summary"))
25702581

2571-
return commands.Exec(releaseBundleUpdateCmd)
2582+
err = commands.Exec(releaseBundleUpdateCmd)
2583+
if releaseBundleUpdateCmd.IsDetailedSummary() {
2584+
if summary := releaseBundleUpdateCmd.GetSummary(); summary != nil {
2585+
return cliutils.PrintBuildInfoSummaryReport(summary.IsSucceeded(), summary.GetSha256(), err)
2586+
}
2587+
}
2588+
return err
25722589
}
25732590

25742591
func releaseBundleSignCmd(c *cli.Context) error {
@@ -2584,8 +2601,14 @@ func releaseBundleSignCmd(c *cli.Context) error {
25842601
if err != nil {
25852602
return err
25862603
}
2587-
releaseBundleSignCmd.SetServerDetails(rtDetails).SetReleaseBundleSignParams(params)
2588-
return commands.Exec(releaseBundleSignCmd)
2604+
releaseBundleSignCmd.SetServerDetails(rtDetails).SetReleaseBundleSignParams(params).SetDetailedSummary(c.Bool("detailed-summary"))
2605+
err = commands.Exec(releaseBundleSignCmd)
2606+
if releaseBundleSignCmd.IsDetailedSummary() {
2607+
if summary := releaseBundleSignCmd.GetSummary(); summary != nil {
2608+
return cliutils.PrintBuildInfoSummaryReport(summary.IsSucceeded(), summary.GetSha256(), err)
2609+
}
2610+
}
2611+
return err
25892612
}
25902613

25912614
func releaseBundleDistributeCmd(c *cli.Context) error {

Diff for: buildinfo_test.go

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package main
22

33
import (
4-
"bytes"
54
"encoding/json"
65
"fmt"
7-
"github.com/jfrog/jfrog-cli/utils/summary"
86
"github.com/jfrog/jfrog-client-go/utils/log"
97
"io/ioutil"
108
"os"
@@ -204,30 +202,12 @@ func TestBuildPublishDetailedSummary(t *testing.T) {
204202
defer log.SetLogger(previousLog)
205203
// Execute the bp command with --detailed-summary.
206204
assert.NoError(t, artifactoryCli.Exec("bp", tests.RtBuildName1, buildNumber, "--detailed-summary=true"))
207-
verifyBuildInfoDetailedSummary(t, buffer, previousLog)
205+
tests.VerifySha256DetailedSummary(t, buffer, previousLog)
208206

209207
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails)
210208
cleanArtifactoryTest()
211209
}
212210

213-
func verifyBuildInfoDetailedSummary(t *testing.T, buffer *bytes.Buffer, logger log.Log) {
214-
content := buffer.Bytes()
215-
buffer.Reset()
216-
logger.Output(string(content))
217-
218-
var result summary.BuildInfoSummary
219-
err := json.Unmarshal(content, &result)
220-
assert.NoError(t, err)
221-
222-
assert.Equal(t, summary.Success, result.Status)
223-
assert.Equal(t, 1, result.Totals.Success)
224-
assert.Equal(t, 0, result.Totals.Failure)
225-
// Verify a sha256 was returned
226-
assert.NotEqual(t, 0, len(result.Sha256Array), "Summary validation failed - no sha256 has returned from artifactory.")
227-
// Verify sha256 is valid (a string size 256 characters) and not an empty string.
228-
assert.Equal(t, 64, len(result.Sha256Array[0].Sha256Str), "Summary validation failed - invalid sha256 has returned from artifactory")
229-
}
230-
231211
func TestBuildPublishDryRun(t *testing.T) {
232212
initArtifactoryTest(t)
233213
buildNumber := "11"

Diff for: distribution_test.go

+73
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"errors"
5+
"github.com/jfrog/jfrog-client-go/utils/log"
56
"io/ioutil"
67
"path/filepath"
78
"testing"
@@ -463,6 +464,78 @@ func TestBundlePathMappingUsingSpec(t *testing.T) {
463464
cleanDistributionTest(t)
464465
}
465466

467+
func TestReleaseBundleCreateDetailedSummary(t *testing.T) {
468+
initDistributionTest(t)
469+
470+
// Upload files
471+
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
472+
assert.NoError(t, err)
473+
runRt(t, "u", "--spec="+specFile)
474+
475+
buffer, previousLog := tests.RedirectLogOutputToBuffer()
476+
// Restore previous logger when the function returns
477+
defer log.SetLogger(previousLog)
478+
479+
// Create a release bundle with b2.in
480+
runRb(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b2.in", "--sign", "--detailed-summary")
481+
inttestutils.VerifyLocalBundleExistence(t, tests.BundleName, bundleVersion, true, distHttpDetails)
482+
483+
tests.VerifySha256DetailedSummary(t, buffer, previousLog)
484+
485+
// Cleanup
486+
cleanDistributionTest(t)
487+
}
488+
489+
func TestReleaseBundleUpdateDetailedSummary(t *testing.T) {
490+
initDistributionTest(t)
491+
492+
// Upload files
493+
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
494+
assert.NoError(t, err)
495+
runRt(t, "u", "--spec="+specFile)
496+
497+
buffer, previousLog := tests.RedirectLogOutputToBuffer()
498+
// Restore previous logger when the function returns
499+
defer log.SetLogger(previousLog)
500+
501+
// Create a release bundle with b2.in
502+
runRb(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b2.in")
503+
inttestutils.VerifyLocalBundleExistence(t, tests.BundleName, bundleVersion, true, distHttpDetails)
504+
505+
// Update release bundle to have b1.in
506+
runRb(t, "rbu", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b1.in", "--sign", "--detailed-summary")
507+
508+
tests.VerifySha256DetailedSummary(t, buffer, previousLog)
509+
510+
// Cleanup
511+
cleanDistributionTest(t)
512+
}
513+
514+
func TestReleaseBundleSignDetailedSummary(t *testing.T) {
515+
initDistributionTest(t)
516+
517+
// Upload files
518+
specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB)
519+
assert.NoError(t, err)
520+
runRt(t, "u", "--spec="+specFile)
521+
522+
buffer, previousLog := tests.RedirectLogOutputToBuffer()
523+
// Restore previous logger when the function returns
524+
defer log.SetLogger(previousLog)
525+
526+
// Create a release bundle with b2.in
527+
runRb(t, "rbc", tests.BundleName, bundleVersion, tests.DistRepo1+"/data/b2.in")
528+
inttestutils.VerifyLocalBundleExistence(t, tests.BundleName, bundleVersion, true, distHttpDetails)
529+
530+
// Update release bundle to have b1.in
531+
runRb(t, "rbs", tests.BundleName, bundleVersion, "--detailed-summary")
532+
533+
tests.VerifySha256DetailedSummary(t, buffer, previousLog)
534+
535+
// Cleanup
536+
cleanDistributionTest(t)
537+
}
538+
466539
// Run `jfrog rt rb*` command`. The first arg is the distribution command, such as 'rbc', 'rbu', etc.
467540
func runRb(t *testing.T, args ...string) {
468541
err := distributionCli.Exec(args...)

Diff for: go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ require (
2323
gopkg.in/yaml.v2 v2.4.0
2424
)
2525

26-
// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v0.22.3-0.20210513141528-6e33bd08a53c
26+
replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v0.22.4-0.20210519160047-2add626ec176
2727

28-
// replace github.com/jfrog/jfrog-cli-core => github.com/jfrog/jfrog-cli-core v1.6.3-0.20210511071620-ba401bec9a7a
28+
replace github.com/jfrog/jfrog-cli-core => github.com/jfrog/jfrog-cli-core v1.6.4-0.20210520113720-db757dcfd8e3
2929

3030
// replace github.com/jfrog/gocmd => github.com/jfrog/gocmd master
3131

Diff for: go.sum

+4-7
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OI
113113
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
114114
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
115115
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
116-
github.com/gookit/color v1.3.2/go.mod h1:R3ogXq2B9rTbXoSHJ1HyUVAZ3poOJHpd9nQmyGZsfvQ=
117116
github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk=
118117
github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=
119118
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
@@ -152,11 +151,10 @@ github.com/jfrog/gocmd v0.2.0 h1:nw4Jy8lg8q54thJ88cU8QQDZk83NFgxMXwMadl78II4=
152151
github.com/jfrog/gocmd v0.2.0/go.mod h1:TeZBKJw38D3aKpkIH6tCCztECdhNLIkwHbnCZG8umKE=
153152
github.com/jfrog/gofrog v1.0.6 h1:yUDxSCw8gTK6vC4PvtG0HTnEOQJSZ+O4lWGCgkev1nU=
154153
github.com/jfrog/gofrog v1.0.6/go.mod h1:HkDzg+tMNw23UryoOv0+LB94BzYcl6MCIoz8Tmlb+s8=
155-
github.com/jfrog/jfrog-cli-core v1.6.3 h1:FCWUoC3keGLX3ZJ1UyoaKJtqA7mSThbIedUE13nKLHs=
156-
github.com/jfrog/jfrog-cli-core v1.6.3/go.mod h1:1JkLfrs0UkRrD8M3K1fakDOSyk2DA54mlj7ME0AAlSg=
157-
github.com/jfrog/jfrog-client-go v0.21.0/go.mod h1:0RYDrQKCIdJbx6pjopwtwXh4/PaEW9FqFc4b4ox8fl0=
158-
github.com/jfrog/jfrog-client-go v0.22.3 h1:CqircVnWso+EbpYymsLq1CplHlQ8zxHdy/VOhaAX6Bs=
159-
github.com/jfrog/jfrog-client-go v0.22.3/go.mod h1:1XMLr/yzslzV9uABPrX4gpA0Bvc51ZX6LRvu/L0WQPc=
154+
github.com/jfrog/jfrog-cli-core v1.6.4-0.20210520113720-db757dcfd8e3 h1:/szEkvVSuHWc5P/2j4vONMWIpbodkgZKp9TXEN6fLiI=
155+
github.com/jfrog/jfrog-cli-core v1.6.4-0.20210520113720-db757dcfd8e3/go.mod h1:/IHTLnwoFVhe1pFcGuiNSKPDLcg1OZhjQivtZ9zEzsU=
156+
github.com/jfrog/jfrog-client-go v0.22.4-0.20210519160047-2add626ec176 h1:vI/CQ+yorG94bv/onmhkW3OtLedCyfrWn3sE5Vs0uF4=
157+
github.com/jfrog/jfrog-client-go v0.22.4-0.20210519160047-2add626ec176/go.mod h1:1XMLr/yzslzV9uABPrX4gpA0Bvc51ZX6LRvu/L0WQPc=
160158
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
161159
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
162160
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
@@ -478,7 +476,6 @@ gopkg.in/src-d/go-billy.v4 v4.3.0 h1:KtlZ4c1OWbIs4jCv5ZXrTqG8EQocr0g/d4DjNg70aek
478476
gopkg.in/src-d/go-billy.v4 v4.3.0/go.mod h1:tm33zBoOwxjYHZIE+OV8bxTWFMJLrconzFMd38aARFk=
479477
gopkg.in/src-d/go-git-fixtures.v3 v3.1.1 h1:XWW/s5W18RaJpmo1l0IYGqXKuJITWRFuA45iOf1dKJs=
480478
gopkg.in/src-d/go-git-fixtures.v3 v3.1.1/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g=
481-
gopkg.in/src-d/go-git.v4 v4.7.0/go.mod h1:CzbUWqMn4pvmvndg3gnh5iZFmSsbhyhUWdI0IQ60AQo=
482479
gopkg.in/src-d/go-git.v4 v4.7.1 h1:phAV/kNULxfYEvyInGdPuq3U2MtPpJdgmtOUF3cghkQ=
483480
gopkg.in/src-d/go-git.v4 v4.7.1/go.mod h1:xrJH/YX8uSWewT6evfocf8qsivF18JgCN7/IMitOptY=
484481
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=

Diff for: utils/cliutils/commandsflags.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ const (
349349
rbRepo = releaseBundlePrefix + repo
350350
rbPassphrase = releaseBundlePrefix + passphrase
351351
distTarget = releaseBundlePrefix + target
352+
rbDetailedSummary = releaseBundlePrefix + detailedSummary
352353
sign = "sign"
353354
desc = "desc"
354355
releaseNotesPath = "release-notes-path"
@@ -1056,6 +1057,10 @@ var flagsMap = map[string]cli.Flag{
10561057
Name: dryRun,
10571058
Usage: "[Default: false] Set to true to disable communication with JFrog Distribution.` `",
10581059
},
1060+
rbDetailedSummary: cli.BoolFlag{
1061+
Name: detailedSummary,
1062+
Usage: "[Default: false] Set to true to get a command summary with details about the release bundle artifact.` `",
1063+
},
10591064
sign: cli.BoolFlag{
10601065
Name: sign,
10611066
Usage: "[Default: false] If set to true, automatically signs the release bundle version.` `",
@@ -1426,15 +1431,15 @@ var commandFlags = map[string][]string{
14261431
},
14271432
ReleaseBundleCreate: {
14281433
url, distUrl, user, password, apikey, accessToken, sshKeyPath, sshPassPhrase, serverId, spec, specVars, targetProps,
1429-
rbDryRun, sign, desc, exclusions, releaseNotesPath, releaseNotesSyntax, rbPassphrase, rbRepo, insecureTls, distTarget,
1434+
rbDryRun, sign, desc, exclusions, releaseNotesPath, releaseNotesSyntax, rbPassphrase, rbRepo, insecureTls, distTarget, rbDetailedSummary,
14301435
},
14311436
ReleaseBundleUpdate: {
14321437
url, distUrl, user, password, apikey, accessToken, sshKeyPath, sshPassPhrase, serverId, spec, specVars, targetProps,
1433-
rbDryRun, sign, desc, exclusions, releaseNotesPath, releaseNotesSyntax, rbPassphrase, rbRepo, insecureTls, distTarget,
1438+
rbDryRun, sign, desc, exclusions, releaseNotesPath, releaseNotesSyntax, rbPassphrase, rbRepo, insecureTls, distTarget, rbDetailedSummary,
14341439
},
14351440
ReleaseBundleSign: {
14361441
url, distUrl, user, password, apikey, accessToken, sshKeyPath, sshPassPhrase, serverId, rbPassphrase, rbRepo,
1437-
insecureTls,
1442+
insecureTls, rbDetailedSummary,
14381443
},
14391444
ReleaseBundleDistribute: {
14401445
url, distUrl, user, password, apikey, accessToken, sshKeyPath, sshPassPhrase, serverId, rbDryRun, distRules,

Diff for: utils/tests/utils.go

+20
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package tests
33
import (
44
"bytes"
55
"encoding/base64"
6+
"encoding/json"
67
"errors"
78
"flag"
89
"fmt"
10+
"github.com/jfrog/jfrog-cli/utils/summary"
911
"io/ioutil"
1012
"math/rand"
1113
"os"
@@ -631,3 +633,21 @@ func RedirectLogOutputToBuffer() (buffer *bytes.Buffer, previousLog log.Log) {
631633
log.SetLogger(newLog)
632634
return buffer, previousLog
633635
}
636+
637+
func VerifySha256DetailedSummary(t *testing.T, buffer *bytes.Buffer, logger log.Log) {
638+
content := buffer.Bytes()
639+
buffer.Reset()
640+
logger.Output(string(content))
641+
642+
var result summary.BuildInfoSummary
643+
err := json.Unmarshal(content, &result)
644+
assert.NoError(t, err)
645+
646+
assert.Equal(t, summary.Success, result.Status)
647+
assert.Equal(t, 1, result.Totals.Success)
648+
assert.Equal(t, 0, result.Totals.Failure)
649+
// Verify a sha256 was returned
650+
assert.NotEmpty(t, result.Sha256Array, "Summary validation failed - no sha256 has returned from Artifactory.")
651+
// Verify sha256 is valid (a string size 256 characters) and not an empty string.
652+
assert.Equal(t, 64, len(result.Sha256Array[0].Sha256Str), "Summary validation failed - invalid sha256 has returned from artifactory")
653+
}

0 commit comments

Comments
 (0)