Skip to content

Commit

Permalink
Merge branch 'dev' into rbc-with-project
Browse files Browse the repository at this point in the history
  • Loading branch information
bhanurp authored Feb 26, 2025
2 parents 9cbdc9a + 7bd7346 commit 1a4be25
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
13 changes: 13 additions & 0 deletions artifactory/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -1962,6 +1962,19 @@ func curlCmd(c *cli.Context) error {
if err != nil {
return err
}

// Check if --server-id is explicitly passed in arguments
flagIndex, _, _, err := coreutils.FindFlag("--server-id", cliutils.ExtractCommand(c))
if err != nil {
return err
}
// If --server-id is NOT present, then we check for JFROG_CLI_SERVER_ID env variable
if flagIndex == -1 {
if artDetails, err := cliutils.CreateArtifactoryDetailsByFlags(c); err == nil && artDetails.ArtifactoryUrl != "" {
rtCurlCommand.SetServerDetails(artDetails)
rtCurlCommand.SetUrl(artDetails.ArtifactoryUrl)
}
}
return commands.Exec(rtCurlCommand)
}

Expand Down
44 changes: 35 additions & 9 deletions artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5543,15 +5543,41 @@ func TestArtifactoryCurl(t *testing.T) {
_, err := createServerConfigAndReturnPassphrase(t)
defer deleteServerConfig(t)
assert.NoError(t, err)
// Check curl command with config default server
err = artifactoryCli.WithoutCredentials().Exec("curl", "-XGET", "/api/system/version")
assert.NoError(t, err)
// Check curl command with '--server-id' flag
err = artifactoryCli.WithoutCredentials().Exec("curl", "-XGET", "/api/system/version", "--server-id="+tests.ServerId)
assert.NoError(t, err)
// Check curl command with invalid server id - should get an error.
err = artifactoryCli.WithoutCredentials().Exec("curl", "-XGET", "/api/system/version", "--server-id=not_configured_name_"+tests.ServerId)
assert.Error(t, err)

baseArgs := []string{"curl", "-XGET", "/api/system/version"}

testRuns := []struct {
testName string
serverIDEnvValue string
expectedErr bool
serverID string
}{
{"defaultConfig", "", false, ""},
{"serverIdFlag", "", false, tests.ServerId},
{"invalidServerId", "", true, "not_configured_name_" + tests.ServerId},
{"envVarSet", tests.ServerId, false, ""},
{"envVarWithFlag", tests.ServerId, false, tests.ServerId},
{"priorityFlagOverEnv", "wrong_server_id", false, tests.ServerId},
{"priorityEnvOverDefault", tests.ServerId, false, ""},
}

for _, test := range testRuns {
t.Run(test.testName, func(t *testing.T) {
setEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, coreutils.ServerID, test.serverIDEnvValue)

args := append([]string{}, baseArgs...)
if test.serverID != "" {
args = append(args, "--server-id="+test.serverID)
}
err = artifactoryCli.WithoutCredentials().Exec(args...)
if test.expectedErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
setEnvCallBack()
})
}

cleanArtifactoryTest()
}
Expand Down

0 comments on commit 1a4be25

Please sign in to comment.