Skip to content

Commit b27257e

Browse files
authored
Feature/docker validate sha (#2971)
* Add --validate-sha flag for Docker push command * Fix SetValidateSha method ordering in push command * Reverted updated artifactory versions in tests * Update help.go
1 parent 422afa1 commit b27257e

File tree

4 files changed

+39
-34
lines changed

4 files changed

+39
-34
lines changed

buildtools/cli.go

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ package buildtools
33
import (
44
"errors"
55
"fmt"
6+
"os"
7+
"strconv"
8+
"strings"
9+
610
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/python"
711
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/setup"
812
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
913
"github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
1014
"github.com/jfrog/jfrog-cli-security/utils/techutils"
1115
setupdocs "github.com/jfrog/jfrog-cli/docs/buildtools/setup"
12-
"os"
13-
"strconv"
14-
"strings"
1516

1617
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/container"
1718
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/dotnet"
@@ -768,7 +769,7 @@ func pullCmd(c *cli.Context, image string) error {
768769
if show, err := cliutils.ShowGenericCmdHelpIfNeeded(c, c.Args(), "dockerpullhelp"); show || err != nil {
769770
return err
770771
}
771-
_, rtDetails, _, skipLogin, filteredDockerArgs, buildConfiguration, err := extractDockerOptionsFromArgs(c.Args())
772+
_, rtDetails, _, skipLogin, _, filteredDockerArgs, buildConfiguration, err := extractDockerOptionsFromArgs(c.Args())
772773
if err != nil {
773774
return err
774775
}
@@ -791,24 +792,24 @@ func pushCmd(c *cli.Context, image string) (err error) {
791792
if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil {
792793
return err
793794
}
794-
threads, rtDetails, detailedSummary, skipLogin, filteredDockerArgs, buildConfiguration, err := extractDockerOptionsFromArgs(c.Args())
795+
threads, rtDetails, detailedSummary, skipLogin, validateSha, filteredDockerArgs, buildConfiguration, err := extractDockerOptionsFromArgs(c.Args())
795796
if err != nil {
796797
return
797798
}
798799
printDeploymentView := log.IsStdErrTerminal()
799-
PushCommand := container.NewPushCommand(containerutils.DockerClient)
800-
PushCommand.SetThreads(threads).SetDetailedSummary(detailedSummary || printDeploymentView).SetCmdParams(filteredDockerArgs).SetSkipLogin(skipLogin).SetBuildConfiguration(buildConfiguration).SetServerDetails(rtDetails).SetImageTag(image)
801-
supported, err := PushCommand.IsGetRepoSupported()
800+
pushCommand := container.NewPushCommand(containerutils.DockerClient)
801+
pushCommand.SetThreads(threads).SetDetailedSummary(detailedSummary || printDeploymentView).SetCmdParams(filteredDockerArgs).SetSkipLogin(skipLogin).SetBuildConfiguration(buildConfiguration).SetServerDetails(rtDetails).SetValidateSha(validateSha).SetImageTag(image)
802+
supported, err := pushCommand.IsGetRepoSupported()
802803
if err != nil {
803804
return err
804805
}
805806
if !supported {
806807
return cliutils.NotSupportedNativeDockerCommand("docker-push")
807808
}
808-
err = commands.Exec(PushCommand)
809-
result := PushCommand.Result()
809+
err = commands.Exec(pushCommand)
810+
result := pushCommand.Result()
810811
defer cliutils.CleanupResult(result, &err)
811-
err = cliutils.PrintCommandSummary(PushCommand.Result(), detailedSummary, printDeploymentView, false, err)
812+
err = cliutils.PrintCommandSummary(pushCommand.Result(), detailedSummary, printDeploymentView, false, err)
812813
return
813814
}
814815

@@ -824,7 +825,7 @@ func dockerNativeCmd(c *cli.Context) error {
824825
if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil {
825826
return err
826827
}
827-
_, _, _, _, cleanArgs, _, err := extractDockerOptionsFromArgs(c.Args())
828+
_, _, _, _, _, cleanArgs, _, err := extractDockerOptionsFromArgs(c.Args())
828829
if err != nil {
829830
return err
830831
}
@@ -833,7 +834,7 @@ func dockerNativeCmd(c *cli.Context) error {
833834
}
834835

835836
// Remove all the none docker CLI flags from args.
836-
func extractDockerOptionsFromArgs(args []string) (threads int, serverDetails *coreConfig.ServerDetails, detailedSummary, skipLogin bool, cleanArgs []string, buildConfig *build.BuildConfiguration, err error) {
837+
func extractDockerOptionsFromArgs(args []string) (threads int, serverDetails *coreConfig.ServerDetails, detailedSummary, skipLogin bool, validateSha bool, cleanArgs []string, buildConfig *build.BuildConfiguration, err error) {
837838
cleanArgs = append([]string(nil), args...)
838839
var serverId string
839840
cleanArgs, serverId, err = coreutils.ExtractServerIdFromCommand(cleanArgs)
@@ -856,6 +857,11 @@ func extractDockerOptionsFromArgs(args []string) (threads int, serverDetails *co
856857
if err != nil {
857858
return
858859
}
860+
// Extract validateSha flag
861+
cleanArgs, validateSha, err = coreutils.ExtractBoolFlagFromArgs(cleanArgs, "validate-sha")
862+
if err != nil {
863+
return
864+
}
859865
cleanArgs, buildConfig, err = build.ExtractBuildDetailsFromArgs(cleanArgs)
860866
return
861867
}
@@ -934,17 +940,9 @@ func NpmPublishCmd(c *cli.Context) (err error) {
934940
if npmCmd.GetXrayScan() {
935941
commandsUtils.ConditionalUploadScanFunc = scan.ConditionalUploadDefaultScanFunc
936942
}
937-
938-
var printDeploymentView, detailedSummary bool
939-
940-
// Deployment view and Detailed summary is not supported when using npmrc for publishing since transfer details are not available.
941-
if npmCmd.UseNative() {
942-
printDeploymentView, detailedSummary = false, false
943-
} else {
944-
printDeploymentView, detailedSummary = log.IsStdErrTerminal(), npmCmd.IsDetailedSummary()
945-
if !detailedSummary {
946-
npmCmd.SetDetailedSummary(printDeploymentView)
947-
}
943+
printDeploymentView, detailedSummary := log.IsStdErrTerminal(), npmCmd.IsDetailedSummary()
944+
if !detailedSummary {
945+
npmCmd.SetDetailedSummary(printDeploymentView)
948946
}
949947
err = commands.Exec(npmCmd)
950948
result := npmCmd.Result()

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ require (
191191

192192
replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20250529104758-6d769a684388
193193

194-
//replace github.com/jfrog/jfrog-cli-artifactory => github.com/jfrog/jfrog-cli-artifactory v0.2.5-0.20250514065555-2ad0e403ae04
194+
replace github.com/jfrog/jfrog-cli-artifactory => github.com/jfrog/jfrog-cli-artifactory v0.3.2-0.20250527103322-0361d8f5612d
195195

196-
//replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20250514055103-d3d0d25f7c85
196+
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20250527091824-60a3b4b741aa
197197

198198
//replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20250508130334-f159cff9b11a
199199

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
186186
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
187187
github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYLipdsOFMY=
188188
github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w=
189-
github.com/jfrog/jfrog-cli-artifactory v0.3.1 h1:0F5CgS8iR7o0PoQWcjyLWWnZVrfruNstLezzRaAb9EY=
190-
github.com/jfrog/jfrog-cli-artifactory v0.3.1/go.mod h1:6QUvZ7US2VVUWzixh/ofn6LHhBelzLkAK+v5FqBvwZ4=
191-
github.com/jfrog/jfrog-cli-core/v2 v2.58.7 h1:njRlkJjNZ1cvG25S/6T4h+ouI+ZRABN6xZN87UIzB/M=
192-
github.com/jfrog/jfrog-cli-core/v2 v2.58.7/go.mod h1:ZXcipUeTTEQ/phqHdbCh4wJ5Oo4QVDxzQBREQ0J9mDc=
189+
github.com/jfrog/jfrog-cli-artifactory v0.3.2-0.20250527103322-0361d8f5612d h1:pc0wqdFr0T3VXSk7vHjlb1IQymHq/6UNphRjIeSV2bU=
190+
github.com/jfrog/jfrog-cli-artifactory v0.3.2-0.20250527103322-0361d8f5612d/go.mod h1:8N/wm24dayk3/+ScG3PZf8rO4yfiDpqIu5JwTwbFCnM=
191+
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20250527091824-60a3b4b741aa h1:ybm7alLNcgeVRaM4a4Ma1kjzFN5jxe5yIMvdmDATEWM=
192+
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20250527091824-60a3b4b741aa/go.mod h1:ZXcipUeTTEQ/phqHdbCh4wJ5Oo4QVDxzQBREQ0J9mDc=
193193
github.com/jfrog/jfrog-cli-platform-services v1.9.0 h1:r/ETgJuMUOUu12w20ydsF6paqEaj0khH6bxMRsdNz1Y=
194194
github.com/jfrog/jfrog-cli-platform-services v1.9.0/go.mod h1:pMZMSwhj7yA4VKyj0Skr2lObIyGpZUxNJ40DSLKXU38=
195195
github.com/jfrog/jfrog-cli-security v1.18.0 h1:+Lf7lW7C6XfCsCd11swJicgFackEPIKOOpQTbX3cd/M=

utils/cliutils/commandsflags.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package cliutils
22

33
import (
44
"fmt"
5-
"github.com/jfrog/jfrog-cli-artifactory/cliutils/flagkit"
65
"sort"
76
"strconv"
87

8+
"github.com/jfrog/jfrog-cli-artifactory/cliutils/flagkit"
9+
910
commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
1011
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
1112

@@ -345,6 +346,7 @@ const (
345346
// Build tool flags
346347
deploymentThreads = "deployment-threads"
347348
skipLogin = "skip-login"
349+
validateSha = "validate-sha"
348350

349351
// Unique docker promote flags
350352
dockerPromotePrefix = "docker-promote-"
@@ -1708,6 +1710,11 @@ var flagsMap = map[string]cli.Flag{
17081710
runNative: cli.BoolFlag{
17091711
Name: runNative,
17101712
Usage: "[Default: false] Set to true if you'd like to use the native client configurations. Note: This flag would invoke native client behind the scenes, has performance implications and does not support deployment view and detailed summary` `",
1713+
1714+
},
1715+
validateSha: cli.BoolFlag{
1716+
Name: validateSha,
1717+
Usage: "[Default: false] Set to true to enable SHA validation during Docker push.` `",
17111718
},
17121719
}
17131720

@@ -1829,11 +1836,11 @@ var commandFlags = map[string][]string{
18291836
},
18301837
Docker: {
18311838
BuildName, BuildNumber, module, Project,
1832-
serverId, skipLogin, threads, detailedSummary, watches, repoPath, licenses, xrOutput, fail, ExtendedTable, BypassArchiveLimits, MinSeverity, FixableOnly, vuln,
1839+
serverId, skipLogin, threads, detailedSummary, watches, repoPath, licenses, xrOutput, fail, ExtendedTable, BypassArchiveLimits, MinSeverity, FixableOnly, vuln, validateSha,
18331840
},
18341841
DockerPush: {
18351842
BuildName, BuildNumber, module, Project,
1836-
serverId, skipLogin, threads, detailedSummary,
1843+
serverId, skipLogin, threads, detailedSummary, validateSha,
18371844
},
18381845
DockerPull: {
18391846
BuildName, BuildNumber, module, Project,
@@ -1845,7 +1852,7 @@ var commandFlags = map[string][]string{
18451852
},
18461853
ContainerPush: {
18471854
BuildName, BuildNumber, module, url, user, password, accessToken, sshPassphrase, sshKeyPath,
1848-
serverId, skipLogin, threads, Project, detailedSummary,
1855+
serverId, skipLogin, threads, Project, detailedSummary, validateSha,
18491856
},
18501857
ContainerPull: {
18511858
BuildName, BuildNumber, module, url, user, password, accessToken, sshPassphrase, sshKeyPath,

0 commit comments

Comments
 (0)