Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all config commands - atomic #1470

Merged
merged 40 commits into from
Jun 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
117c358
Add TestConfigConcurrency
sverdlov93 Mar 9, 2022
d6bcbc4
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli into config-…
sverdlov93 Mar 9, 2022
7d29ac3
Add TestConfigConcurrency
sverdlov93 Mar 9, 2022
a181fd2
Add TestConfigConcurrency
sverdlov93 Mar 9, 2022
df6ab71
Add TestConfigConcurrency
sverdlov93 Mar 9, 2022
8397271
Add TestConfigConcurrency
sverdlov93 Mar 9, 2022
2aadc32
Add TestConfigConcurrency
sverdlov93 Mar 10, 2022
274ff44
Update tests.yml
sverdlov93 Mar 10, 2022
c877acd
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli into config-…
sverdlov93 Mar 10, 2022
c11e8b2
Add TestConfigConcurrency
sverdlov93 Mar 10, 2022
95b196e
Merge branch 'config-concurrency-test' of https://github.com/sverdlov…
sverdlov93 Mar 10, 2022
bdde66f
Add TestConfigConcurrency
sverdlov93 Mar 10, 2022
b248b29
Add TestConfigConcurrency
sverdlov93 Mar 10, 2022
7d52666
Add TestConfigConcurrency
sverdlov93 Mar 10, 2022
a2588fa
Fix config command
sverdlov93 Mar 15, 2022
7d4945c
Update tests.yml
sverdlov93 Mar 16, 2022
e5551da
Update tests.yml
sverdlov93 Mar 16, 2022
f63dc17
update after CR
sverdlov93 Mar 29, 2022
cb8eb54
Merge branch 'config-concurrency-test' of https://github.com/sverdlov…
sverdlov93 Mar 29, 2022
bc65c1b
update after CR
sverdlov93 Mar 29, 2022
6bedc1a
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli into config-…
sverdlov93 May 3, 2022
284861a
update go.mod
sverdlov93 May 3, 2022
1284b3f
add logs
sverdlov93 May 3, 2022
5fcede4
add logs
sverdlov93 May 4, 2022
0f532f7
add logs
sverdlov93 May 8, 2022
0e66a19
Update analysis.yml
sverdlov93 May 24, 2022
803c79d
Update analysis.yml
sverdlov93 May 24, 2022
0e25cbf
Update analysis.yml
sverdlov93 May 24, 2022
e88f19f
Update utils.go
sverdlov93 May 24, 2022
61333c8
Update utils.go
sverdlov93 May 24, 2022
5630a2a
add frogbot.yml
sverdlov93 May 31, 2022
9ad0a50
Merge branch 'dev' into config-concurrency-test
sverdlov93 May 31, 2022
ad9a7f2
merge dev
sverdlov93 May 31, 2022
a470699
merge dev
sverdlov93 May 31, 2022
ba0192d
merge dev
sverdlov93 Jun 8, 2022
e6a4594
merge dev
sverdlov93 Jun 8, 2022
a57e87c
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli into config-…
sverdlov93 Jun 12, 2022
c1a1729
remove logs
sverdlov93 Jun 12, 2022
eeab612
update go.mod
sverdlov93 Jun 12, 2022
d60da1f
update go.mod
sverdlov93 Jun 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
go-version: 1.17.x
- name: Static Code Analysis
uses: dominikh/staticcheck-action@v1

Go-Sec:
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 2 additions & 3 deletions access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ func TestRefreshableAccessTokens(t *testing.T) {
err := coreenvsetup.GenerateNewLongTermRefreshableAccessToken(server)
assert.NoError(t, err)
assert.NotEmpty(t, server.RefreshToken)
configCmd := commands.NewConfigCommand().SetDetails(server).SetInteractive(false).SetServerId(tests.ServerId)
err = configCmd.Run()
assert.NoError(t, err)
configCmd := commands.NewConfigCommand(commands.AddOrEdit, tests.ServerId).SetDetails(server).SetInteractive(false)
assert.NoError(t, configCmd.Run())
defer deleteServerConfig(t)

// Upload a file and assert the refreshable tokens were generated.
Expand Down
19 changes: 12 additions & 7 deletions artifactory/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -1493,31 +1493,36 @@ func prepareSearchCommand(c *cli.Context) (*spec.SpecFiles, error) {
return searchSpec, err
}

func searchCmd(c *cli.Context) error {
func searchCmd(c *cli.Context) (err error) {
searchSpec, err := prepareSearchCommand(c)
if err != nil {
return err
return
}
artDetails, err := cliutils.CreateArtifactoryDetailsByFlags(c)
if err != nil {
return err
return
}
retries, err := getRetries(c)
if err != nil {
return err
return
}
retryWaitTime, err := getRetryWaitTime(c)
if err != nil {
return err
return
}
searchCmd := generic.NewSearchCommand()
searchCmd.SetServerDetails(artDetails).SetSpec(searchSpec).SetRetries(retries).SetRetryWaitMilliSecs(retryWaitTime)
err = commands.Exec(searchCmd)
if err != nil {
return err
return
}
reader := searchCmd.Result().Reader()
defer reader.Close()
defer func() {
e := reader.Close()
if err == nil {
err = e
}
}()
length, err := reader.Length()
if err != nil {
return err
Expand Down
22 changes: 11 additions & 11 deletions artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,9 @@ func TestArtifactoryCreateUsers(t *testing.T) {

func verifyUsersExistInArtifactory(csvFilePath string, t *testing.T) {
// Parse input CSV
content, err := os.Open(csvFilePath)
output, err := os.Open(csvFilePath)
assert.NoError(t, err)
csvReader := csv.NewReader(content)
csvReader := csv.NewReader(output)
// Ignore the header
_, err = csvReader.Read()
assert.NoError(t, err)
Expand Down Expand Up @@ -4318,18 +4318,18 @@ func verifySummary(t *testing.T, buffer *bytes.Buffer, logger log.Log, cmdError
assert.NoError(t, cmdError)
}

content := buffer.Bytes()
output := buffer.Bytes()
buffer.Reset()
logger.Output(string(content))
logger.Output(string(output))

status, err := jsonparser.GetString(content, "status")
status, err := jsonparser.GetString(output, "status")
assert.NoError(t, err)
assert.Equal(t, expected.status, status, "Summary validation failed")

resultSuccess, err := jsonparser.GetInt(content, "totals", "success")
resultSuccess, err := jsonparser.GetInt(output, "totals", "success")
assert.NoError(t, err)

resultFailure, err := jsonparser.GetInt(content, "totals", "failure")
resultFailure, err := jsonparser.GetInt(output, "totals", "failure")
assert.NoError(t, err)

assert.Equal(t, expected.success, resultSuccess, "Summary validation failed")
Expand Down Expand Up @@ -4466,7 +4466,7 @@ func execListBuildNamesRest() ([]string, error) {
}

func execCreateRepoRest(repoConfig, repoName string) {
content, err := ioutil.ReadFile(repoConfig)
output, err := ioutil.ReadFile(repoConfig)
if err != nil {
log.Error(err)
os.Exit(1)
Expand All @@ -4477,7 +4477,7 @@ func execCreateRepoRest(repoConfig, repoName string) {
log.Error(err)
os.Exit(1)
}
resp, body, err := client.SendPut(serverDetails.ArtifactoryUrl+"api/repositories/"+repoName, content, artHttpDetails, "")
resp, body, err := client.SendPut(serverDetails.ArtifactoryUrl+"api/repositories/"+repoName, output, artHttpDetails, "")
if err != nil {
log.Error(err)
os.Exit(1)
Expand Down Expand Up @@ -4930,11 +4930,11 @@ func TestAccessTokenCreate(t *testing.T) {

func checkAccessToken(t *testing.T, buffer *bytes.Buffer) {
// Write the command output to the origin
content := buffer.Bytes()
output := buffer.Bytes()
buffer.Reset()

// Extract the token from the output
token, err := jsonparser.GetString(content, "access_token")
token, err := jsonparser.GetString(output, "access_token")
assert.NoError(t, err)

// Try ping with the new token
Expand Down
15 changes: 8 additions & 7 deletions config/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ func addOrEdit(c *cli.Context, operation configOperation) error {
if err != nil {
return err
}
configCmd := commands.NewConfigCommand().SetDetails(configCommandConfiguration.ServerDetails).SetInteractive(configCommandConfiguration.Interactive).
SetServerId(serverId).SetEncPassword(configCommandConfiguration.EncPassword).SetUseBasicAuthOnly(configCommandConfiguration.BasicAuthOnly)
return configCmd.Config()
configCmd := commands.NewConfigCommand(commands.AddOrEdit, serverId).SetDetails(configCommandConfiguration.ServerDetails).SetInteractive(configCommandConfiguration.Interactive).
SetEncPassword(configCommandConfiguration.EncPassword).SetUseBasicAuthOnly(configCommandConfiguration.BasicAuthOnly)
return configCmd.Run()
}

func showCmd(c *cli.Context) error {
Expand All @@ -172,15 +172,15 @@ func deleteCmd(c *cli.Context) error {

// Clear all configurations
if c.NArg() == 0 {
return commands.ClearConfig(!quiet)
return commands.NewConfigCommand(commands.Clear, "").SetInteractive(!quiet).Run()
}

// Delete single configuration
serverId := c.Args()[0]
if !quiet && !coreutils.AskYesNo("Are you sure you want to delete \""+serverId+"\" configuration?", false) {
return nil
}
return commands.DeleteConfig(serverId)
return commands.NewConfigCommand(commands.Delete, serverId).Run()
}

func importCmd(c *cli.Context) error {
Expand All @@ -206,7 +206,8 @@ func useCmd(c *cli.Context) error {
if c.NArg() != 1 {
return cliutils.WrongNumberOfArgumentsHandler(c)
}
return commands.Use(c.Args()[0])
serverId := c.Args()[0]
return commands.NewConfigCommand(commands.Use, serverId).Run()
}

func CreateConfigCommandConfiguration(c *cli.Context) (configCommandConfiguration *commands.ConfigCommandConfiguration, err error) {
Expand Down Expand Up @@ -240,7 +241,7 @@ func validateServerExistence(serverId string, operation configOperation) error {
}

func validateConfigFlags(configCommandConfiguration *commands.ConfigCommandConfiguration) error {
// Validate the option is not used along with an access token
// Validate the option is not used along with access token
if configCommandConfiguration.BasicAuthOnly && configCommandConfiguration.ServerDetails.AccessToken != "" {
return errorutils.CheckErrorf("the --%s option is only supported when username and password/API key are provided", cliutils.BasicAuthOnly)
}
Expand Down
4 changes: 2 additions & 2 deletions general/cisetup/cisetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ func getPipelinesToken() (string, error) {

func runConfigCmd() (err error) {
for {
configCmd := coreCommonCommands.NewConfigCommand().SetInteractive(true).SetServerId(cisetup.ConfigServerId).SetEncPassword(true)
err = configCmd.Config()
configCmd := coreCommonCommands.NewConfigCommand(coreCommonCommands.AddOrEdit, cisetup.ConfigServerId).SetInteractive(true).SetEncPassword(true)
err = configCmd.Run()
if err != nil {
log.Error(err)
continue
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.

replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.3.0

replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.15.3-0.20220607100216-b587c75985e2
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.15.3-0.20220612140652-15952821e71d
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ github.com/jfrog/build-info-go v1.3.0 h1:0NutMPwG4qTCXyPhTCo7eGeot9cTT5A7d9LLCdD
github.com/jfrog/build-info-go v1.3.0/go.mod h1:S2x0YOFBqBYp22goGRXGfy3ut7XaespgroVJpD6fPwk=
github.com/jfrog/gofrog v1.1.2 h1:txts7zSFEGan3a8G+AJCrcq4a/z8PrCmZ7m6c7qaALg=
github.com/jfrog/gofrog v1.1.2/go.mod h1:9YN5v4LlsCfLIXpwQnzSf1wVtgjdHM20FzuIu58RMI4=
github.com/jfrog/jfrog-cli-core/v2 v2.15.3-0.20220607100216-b587c75985e2 h1:uHwYRKO2rbgZXOmeSVdQiXbgHI2b+pKyIHLW8jl9TM8=
github.com/jfrog/jfrog-cli-core/v2 v2.15.3-0.20220607100216-b587c75985e2/go.mod h1:V0I57x3VCbzbDZMYAeecH8S+mwNSMQOmnXmxKMqUjbg=
github.com/jfrog/jfrog-cli-core/v2 v2.15.3-0.20220612140652-15952821e71d h1:276bGXr5QxPxuGbMnA/rrzmz191+rjgK8+UIoZG81No=
github.com/jfrog/jfrog-cli-core/v2 v2.15.3-0.20220612140652-15952821e71d/go.mod h1:V0I57x3VCbzbDZMYAeecH8S+mwNSMQOmnXmxKMqUjbg=
github.com/jfrog/jfrog-client-go v1.13.2-0.20220607094927-52dc3f597671 h1:qtBo1ISPQKqLzyVBDJxLN4XxGy7ZvBCjxk5ICBbrq44=
github.com/jfrog/jfrog-client-go v1.13.2-0.20220607094927-52dc3f597671/go.mod h1:IRxbnT/kVsTEpqAYNC9sZgKUrL4ekUYiqXFXhoLe0J4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down
4 changes: 2 additions & 2 deletions missioncontrol/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ func offerConfig(c *cli.Context) (*config.ServerDetails, error) {
return nil, err
}
details := createMCDetailsFromFlags(c)
configCmd := coreCommonCommands.NewConfigCommand().SetDefaultDetails(details).SetInteractive(true)
err = configCmd.Config()
configCmd := coreCommonCommands.NewConfigCommand(coreCommonCommands.AddOrEdit, details.ServerId).SetDefaultDetails(details).SetInteractive(true)
err = configCmd.Run()
if err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions utils/cliutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ func ShouldOfferConfig() (bool, error) {
if err != nil || exists {
return false, err
}

clearConfigCmd := coreCommonCommands.NewConfigCommand(coreCommonCommands.Clear, "")
var ci bool
if ci, err = clientutils.GetBoolEnvValue(coreutils.CI, false); err != nil {
return false, err
}
if ci {
_ = coreConfig.SaveServersConf(make([]*coreConfig.ServerDetails, 0))
_ = clearConfigCmd.Run()
return false, nil
}

Expand All @@ -295,7 +295,7 @@ func ShouldOfferConfig() (bool, error) {
"Configure now?", coreutils.CI)
confirmed := coreutils.AskYesNo(msg, false)
if !confirmed {
_ = coreConfig.SaveServersConf(make([]*coreConfig.ServerDetails, 0))
_ = clearConfigCmd.Run()
return false, nil
}
return true, nil
Expand Down Expand Up @@ -363,8 +363,8 @@ func offerConfig(c *cli.Context, domain CommandDomain) (*coreConfig.ServerDetail
return nil, err
}
details := createServerDetailsFromFlags(c, domain)
configCmd := coreCommonCommands.NewConfigCommand().SetDefaultDetails(details).SetInteractive(true).SetEncPassword(true)
err = configCmd.Config()
configCmd := coreCommonCommands.NewConfigCommand(coreCommonCommands.AddOrEdit, details.ServerId).SetDefaultDetails(details).SetInteractive(true).SetEncPassword(true)
err = configCmd.Run()
if err != nil {
return nil, err
}
Expand Down