Skip to content

Commit 79e32da

Browse files
attiasasbhanurp
authored andcommitted
Get deployment view (jfrog#1533)
* expose GetDeploymentViewString * format
1 parent 8294d4c commit 79e32da

File tree

12 files changed

+106
-98
lines changed

12 files changed

+106
-98
lines changed

artifactory/commands/transferconfig/transferconfig_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func TestValidateTargetServer(t *testing.T) {
118118
_, err = w.Write(content)
119119
assert.NoError(t, err)
120120
default:
121-
content, err := json.Marshal(users)
121+
content, err := json.Marshal(users) // #nosec G117 -- test mock response
122122
assert.NoError(t, err)
123123
_, err = w.Write(content)
124124
assert.NoError(t, err)

artifactory/commands/transferfiles/utils_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,12 @@ var convertPatternToPathPrefixTestCases = []struct {
479479
input string
480480
expected string
481481
}{
482-
{"folder/subfolder/*", "folder/subfolder"}, // strips trailing /*
483-
{"folder/**", "folder"}, // strips trailing /**
484-
{"folder/", "folder"}, // strips trailing /
485-
{"folder", "folder"}, // no change when no trailing pattern
486-
{"a/b/c/d/e/*", "a/b/c/d/e"}, // deep path with wildcard
487-
{"single", "single"}, // single segment without slash
482+
{"folder/subfolder/*", "folder/subfolder"}, // strips trailing /*
483+
{"folder/**", "folder"}, // strips trailing /**
484+
{"folder/", "folder"}, // strips trailing /
485+
{"folder", "folder"}, // no change when no trailing pattern
486+
{"a/b/c/d/e/*", "a/b/c/d/e"}, // deep path with wildcard
487+
{"single", "single"}, // single segment without slash
488488
}
489489

490490
func TestConvertPatternToPathPrefix(t *testing.T) {
@@ -592,11 +592,11 @@ var convertPatternToAqlMatchTestCases = []struct {
592592
input string
593593
expected string
594594
}{
595-
{"folder/subfolder/*", "*folder/subfolder*"}, // path with wildcard
596-
{"folder", "*folder*"}, // simple folder name
595+
{"folder/subfolder/*", "*folder/subfolder*"}, // path with wildcard
596+
{"folder", "*folder*"}, // simple folder name
597597
{"org/company/project/*", "*org/company/project*"}, // deep nested path
598-
{"*already/prefixed", "*already/prefixed*"}, // already has leading wildcard
599-
{"already/suffixed*", "*already/suffixed*"}, // already has trailing wildcard
598+
{"*already/prefixed", "*already/prefixed*"}, // already has leading wildcard
599+
{"already/suffixed*", "*already/suffixed*"}, // already has trailing wildcard
600600
}
601601

602602
func TestConvertPatternToAqlMatch(t *testing.T) {

artifactory/commands/utils/precheckrunner/remoteurlchecker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (rrc *RemoteRepositoryCheck) createRemoteUrlRequest() ([]remoteRepoSettings
109109
func (rrc *RemoteRepositoryCheck) doCheckRemoteRepositories(args RunArguments, remoteUrlRequest []remoteRepoSettings) (inaccessibleRepositories *[]inaccessibleRepository, err error) {
110110
artifactoryUrl := clientutils.AddTrailingSlashIfNeeded(args.ServerDetails.ArtifactoryUrl)
111111

112-
body, err := json.Marshal(remoteUrlRequest)
112+
body, err := json.Marshal(remoteUrlRequest) // #nosec G117 -- credentials sent to Artifactory API
113113
if err != nil {
114114
return nil, errorutils.CheckError(err)
115115
}

common/commands/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func doConfig(t *testing.T, serverId string, inputDetails *config.ServerDetails,
443443

444444
func configStructToString(t *testing.T, artConfig *config.ServerDetails) string {
445445
artConfig.IsDefault = false
446-
marshaledStruct, err := json.Marshal(*artConfig)
446+
marshaledStruct, err := json.Marshal(*artConfig) // #nosec G117 -- test helper
447447
assert.NoError(t, err)
448448
return string(marshaledStruct)
449449
}

common/spec/specfiles.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ type File struct {
9494
TargetPathInArchive string
9595
Include []string `json:"include,omitempty"`
9696
Package string `json:"package,omitempty"`
97-
Version string `json:"version,omitempty"`
98-
Type string `json:"type,omitempty"`
99-
RepoKey string `json:"repoKey,omitempty"`
97+
Version string `json:"version,omitempty"`
98+
Type string `json:"type,omitempty"`
99+
RepoKey string `json:"repoKey,omitempty"`
100100
}
101101

102102
func (f File) GetInclude() []string {

general/token/oidctokenexchange.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (otc *OidcTokenExchangeCommand) PrintResponseToConsole() {
173173
AccessToken: otc.response.AccessToken,
174174
Username: otc.response.Username,
175175
}
176-
jsonOutput, err := json.Marshal(response)
176+
jsonOutput, err := json.Marshal(response) // #nosec G117 -- intentional output of OIDC exchange result
177177
if err != nil {
178178
log.Error("Failed to marshal response to JSON:", err)
179179
return

plugins/common/utils.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,19 +317,29 @@ func PrintDetailedSummaryReport(basicSummary string, reader *content.ContentRead
317317

318318
// Print a file tree based on the items' path in the reader's list.
319319
func PrintDeploymentView(reader *content.ContentReader) error {
320+
output, err := GetDeploymentViewString(reader)
321+
if err != nil {
322+
return err
323+
}
324+
if len(output) > 0 {
325+
log.Info("These files were uploaded:\n\n" + output)
326+
} else {
327+
log.Info("No files were uploaded.")
328+
}
329+
return nil
330+
}
331+
332+
func GetDeploymentViewString(reader *content.ContentReader) (string, error) {
320333
tree := artifactoryUtils.NewFileTree()
321334
for transferDetails := new(clientutils.FileTransferDetails); reader.NextRecord(transferDetails) == nil; transferDetails = new(clientutils.FileTransferDetails) {
322335
tree.AddFile(transferDetails.TargetPath, "")
323336
}
324337
if err := reader.GetError(); err != nil {
325-
return err
338+
return "", err
326339
}
327340
reader.Reset()
328341
output := tree.String()
329-
if len(output) > 0 {
330-
log.Info("These files were uploaded:\n\n" + output)
331-
}
332-
return nil
342+
return output, nil
333343
}
334344

335345
// Get the detailed summary record.

utils/config/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,11 +590,11 @@ type ServerDetails struct {
590590
OnemodelUrl string `json:"-"`
591591
ApptrustUrl string `json:"-"`
592592
User string `json:"user,omitempty"`
593-
Password string `json:"password,omitempty"` // #nosec G117 -- config struct for auth
593+
Password string `json:"password,omitempty"` // #nosec G117 -- config struct for auth
594594
SshKeyPath string `json:"sshKeyPath,omitempty"`
595595
SshPassphrase string `json:"sshPassphrase,omitempty"`
596-
AccessToken string `json:"accessToken,omitempty"` // #nosec G117 -- config struct for auth
597-
RefreshToken string `json:"refreshToken,omitempty"` // #nosec G117 -- config struct for auth
596+
AccessToken string `json:"accessToken,omitempty"` // #nosec G117 -- config struct for auth
597+
RefreshToken string `json:"refreshToken,omitempty"` // #nosec G117 -- config struct for auth
598598
ArtifactoryRefreshToken string `json:"artifactoryRefreshToken,omitempty"`
599599
ArtifactoryTokenRefreshInterval int `json:"tokenRefreshInterval,omitempty"`
600600
ClientCertPath string `json:"clientCertPath,omitempty"`

utils/config/config_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ func createEncryptionTestConfig() *Config {
246246
ServerId: "test-server",
247247
Url: "http://acme.jfrog.io",
248248
User: "elmar",
249-
Password: "Wabbit", // #nosec G101 -- test data only
249+
Password: "Wabbit", // #nosec G101 -- test data only
250250
AccessToken: "DewiciousWegOfWamb", // #nosec G101 -- test data only
251-
SshPassphrase: "KiwwTheWabbit", // #nosec G101 -- test data only
251+
SshPassphrase: "KiwwTheWabbit", // #nosec G101 -- test data only
252252
}}},
253253
}}
254254
}
@@ -479,7 +479,7 @@ func TestCreateAuthConfigAppendPreRequestFunctionBehavior(t *testing.T) {
479479
name: "DisableTokenRefreshTrue_WithArtifactoryRefreshToken",
480480
serverDetails: &ServerDetails{
481481
ServerId: "test-server",
482-
AccessToken: "access-token-123", // #nosec G101 -- test data only
482+
AccessToken: "access-token-123", // #nosec G101 -- test data only
483483
ArtifactoryRefreshToken: "artifactory-refresh-token-789", // #nosec G101 -- test data only
484484
User: "testuser",
485485
Password: "testpass", // #nosec G101 -- test data only
@@ -491,7 +491,7 @@ func TestCreateAuthConfigAppendPreRequestFunctionBehavior(t *testing.T) {
491491
name: "DisableTokenRefreshFalse_WithArtifactoryRefreshToken",
492492
serverDetails: &ServerDetails{
493493
ServerId: "test-server",
494-
AccessToken: "access-token-123", // #nosec G101 -- test data only
494+
AccessToken: "access-token-123", // #nosec G101 -- test data only
495495
ArtifactoryRefreshToken: "artifactory-refresh-token-789", // #nosec G101 -- test data only
496496
User: "testuser",
497497
Password: "testpass", // #nosec G101 -- test data only

utils/config/configtoken.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ type configToken struct {
1818
MissionControlUrl string `json:"missionControlUrl,omitempty"`
1919
PipelinesUrl string `json:"pipelinesUrl,omitempty"`
2020
User string `json:"user,omitempty"`
21-
Password string `json:"password,omitempty"` // #nosec G117 -- config struct for auth
21+
Password string `json:"password,omitempty"` // #nosec G117 -- config struct for auth
2222
SshKeyPath string `json:"sshKeyPath,omitempty"`
2323
SshPassphrase string `json:"sshPassphrase,omitempty"`
24-
AccessToken string `json:"accessToken,omitempty"` // #nosec G117 -- config struct for auth
25-
RefreshToken string `json:"refreshToken,omitempty"` // #nosec G117 -- config struct for auth
24+
AccessToken string `json:"accessToken,omitempty"` // #nosec G117 -- config struct for auth
25+
RefreshToken string `json:"refreshToken,omitempty"` // #nosec G117 -- config struct for auth
2626
TokenRefreshInterval int `json:"tokenRefreshInterval,omitempty"`
2727
ClientCertPath string `json:"clientCertPath,omitempty"`
2828
ClientCertKeyPath string `json:"clientCertKeyPath,omitempty"`
@@ -98,7 +98,7 @@ func Export(details *ServerDetails) (string, error) {
9898
return "", errorutils.CheckErrorf("could not generate config token: config is encrypted, and wrong master key was provided")
9999
}
100100
}
101-
buffer, err := json.Marshal(fromServerDetails(details))
101+
buffer, err := json.Marshal(fromServerDetails(details)) // #nosec G117 -- intentional serialization of auth config for export token
102102
if err != nil {
103103
return "", err
104104
}

0 commit comments

Comments
 (0)