devopshq / artifactory-cleanup

Extended cleanup tool for JFrog Artifactory
MIT License
126 stars 66 forks source link

Substitute repo name in yaml #105

Closed Kaskarden closed 3 months ago

Kaskarden commented 1 year ago

added functionality to use an environment variable so you don't have to hardcode the repo name into the config yaml bumped version to 1.0.7

allburov commented 1 year ago

Hi! The idea of the tool - to keep all cleanup policies in text format so you can push it to version control system, review and use other best tool and practice for the code. Everything as Code! It's fine to keep secret or connection URL in environment variables tho.

I don't see why one would need to change repo name via command line or environment variable. Could you explain it? There ought to be serious reason for that change

allburov commented 1 year ago

Btw, don't bump version in PR if you contribute to a project if reviewer didn't ask it explicitly. It can lead to unnecessary conflicts while merging

Kaskarden commented 1 year ago

The problem that I was trying to solve was this: I have different artifactory "environments" (development, test, etc.). The way these are seperated is by repo name. I want to automatically clean all environments with the same configuration. The command line script I wrote determines which environment it needs to clean by determining which environment it is run in. Currently I have to write different policies to seperate the different environments, which makes it hard to read the configuration. It would be a lot easier if I could just substitute the repo name according to which environment I'm in. And sorry for bumping the version

allburov commented 1 year ago

The Artifactory URL and username/password for environments are the same or different?

Kaskarden commented 1 year ago

The URL is the same, the username and password combination is also determined by the script and then substituted accordingly

allburov commented 1 year ago

I see.

Here's what I'd suggest you to do instead of changing a repo name at the runtime.

  1. Use yaml-anchors to avoid duplicating policies
  2. Create the separate policies for different environment
  3. Run the cleanup with different username\password and specify rules
    - name: dev-repo
      rules:
        - rule: Repo
          name: repo.dev
    - name: stg-repo
      rules:
        - rule: Repo
          name: repo.stg
artifactory-cleanup --policy dev-repo --username DEV_USER
artifactory-cleanup --policy stg-repo --username STG_USER

Would it solve your case? If it doesn't - please describe the case more, may be add few examples and we'll see how it can fit in the project!

If we can't solve it with the current tool - I'll look at PR closely and may be we can add the functionality to the project.

allburov commented 3 months ago

Everything is a Code is the best one