jfrog-cli icon indicating copy to clipboard operation
jfrog-cli copied to clipboard

JFrog-CLI generates incorrect rpt template

Open p4r53c opened this issue 1 year ago • 0 comments

Describe the bug

jf rt rpt generates an incorrect template from the Artifactory API point of view.

Current behavior

$ jf rt rpt test.json
Select the template type (press Tab for options): update
Insert the repository key > npm-env-test-federated
Select the repository class (press Tab for options): local
Select the repository's package type (press Tab for options): npm
You can type ":x" at any time to save and exit.
Select the next configuration key (press Tab for options): environment
Insert the name of the environment to assign to > PROD
Select the next configuration key (press Tab for options): :x
09:29:24 [:large_blue_circle:Info] Repository configuration template successfully created at test.json.

...

$ cat test.json
{"environments":"PROD","key":"npm-env-test-federated","packageType":"npm","rclass":"federated"}

As you may see, the template contains an environments object with a string value, although it should contain a list, as shown in the documentation.

Such a template will be executed via jf rt ru and will successfully update the environments for the repository, but if you call jf rt cl, then the response Repository ${repoName} update successfully. will be returned from the API, but the environments for the repository will be empty.

Reproduction steps

1. Check current state of the repo

$ jf rt cl api/repositories/npm-env-test-federated -XGET -s | grep "environments"
  "environments" : [ "DEV" ],

2. Generate template to chenge env to PROD

$ jf rt rpt test.json
Select the template type (press Tab for options): update
Insert the repository key > npm-env-test-federated
Select the repository class (press Tab for options): local
Select the repository's package type (press Tab for options): npm
You can type ":x" at any time to save and exit.
Select the next configuration key (press Tab for options): environment
Insert the name of the environment to assign to > PROD
Select the next configuration key (press Tab for options): :x
09:29:24 [:large_blue_circle:Info] Repository configuration template successfully created at test.json.

3. Check template (env is str, not list)

$ cat test.json
{"environments":"PROD","key":"npm-env-test-federated","packageType":"npm","rclass":"federated"}

4. RU with CLI

$ jf rt ru test.json
09:54:49 [:large_blue_circle:Info] Updating repository 'npm-env-test-federated'...
09:54:49 [:large_blue_circle:Info] Done updating repository 'npm-env-test-federated'.

5. Check (success, expected, current env state is PROD)

$ jf rt cl api/repositories/npm-env-test-federated -XGET -s | grep "environments"
  "environments" : [ "PROD" ],

6. Change env in test.json from PROD to DEV

$ sed -i '' 's/PROD/DEV/g' test.json
$ cat test.json
{"environments":"DEV","key":"npm-env-test-federated","packageType":"npm","rclass":"federated"}

7. RU with CURL call

$ jf rt cl api/repositories/npm-env-test-federated -XPOST -H "Content-Type: application/json" -d @test.json
Repository npm-env-test-federated update successfully.

8. Check (unexpected, current env state was reset)

$ jf rt cl api/repositories/npm-env-test-federated -XGET -s | grep "environments"
  "environments" : [ ],

9. Set state to DEV with CLI RU (same payload)

$ jf rt ru test.json
10:13:30 [:large_blue_circle:Info] Updating repository 'npm-env-test-federated'...
10:13:31 [:large_blue_circle:Info] Done updating repository 'npm-env-test-federated'.
$ jf rt cl api/repositories/npm-env-test-federated -XGET -s | grep "environments"
  "environments" : [ "DEV" ],

10. Fix env in template to list type from str for PROD and change it with RU CURL

$ sed -i '' 's/"PROD"/[ "PROD" ]/g' test.json

$ cat test.json
{"environments":[ "PROD" ],"key":"npm-env-test-federated","packageType":"npm","rclass":"federated"}

$ jf rt cl api/repositories/npm-env-test-federated -XPOST -H "Content-Type: application/json" -d @test.json
Repository npm-env-test-federated update successfully.

11. Check again (success, env was not reseted with list typed env)

$ jf rt cl api/repositories/npm-env-test-federated -XGET -s | grep "environments"
  "environments" : [ "PROD" ],

Expected behavior

The rpt command should generate a template in which environments are passed as a list and not a string, even if the element is 1.

JFrog CLI version

2.74.0

Operating system type and version

macOS Sequoia 15.3.1

JFrog Artifactory version

No response

JFrog Xray version

No response

p4r53c avatar Mar 10 '25 15:03 p4r53c