Skip to content

bug fix for casting string to boolean and added possibility to keep artefacts based on regex - #204

Closed
wotd wants to merge 4 commits into
jfrog:masterfrom
wotd:master
Closed

bug fix for casting string to boolean and added possibility to keep artefacts based on regex#204
wotd wants to merge 4 commits into
jfrog:masterfrom
wotd:master

Conversation

@wotd

@wotd wotd commented Apr 4, 2018

Copy link
Copy Markdown

It is possible to keep artefacts with names containing specified string and small bug with casting string to boolean is now fixed. If you define string in url and using as boolean will always be true.

@elioengcomp elioengcomp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @wotd,

Thank you for the contribution.

I added some comments to your PR. Can you review them and provide more details?

Best.
Elio

Global.paceTimeMS = params['paceTimeMS'] ? params['paceTimeMS'][0] as int : 0
artifactCleanup(months, repos, log, Global.paceTimeMS, dryRun, disablePropertiesSupport)
def keepRelease = params['keepRelease'] ? params['keepRelease'][0].toBoolean() : false
def releaseRegex = params['releaseRegex'] ? config.regex as Pattern : ~/.*-\d\.\d\.\d\.*/

@elioengcomp elioengcomp Apr 4, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide more details about the releaseRegex parameter being referenced here. It looks like the parameter value is not being used at all.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? It is used in artifactCleanup function :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wotd The value of params['releaseRegex'] is being used only on the left side of the ? operator. Is it supposed to be a boolean?

[ "0 0 5 ? * 1", [ "libs-releases-local" ], 3 ],
]

// regex = ~/.*-\d\.\d\.\d\.*/

@elioengcomp elioengcomp Apr 4, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is purpose of this regex defined out of a policy?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in line 57:
def releaseRegex = params['releaseRegex'] ? config.regex as Pattern : ~/.*-\d\.\d\.\d\.*/
I was wondering if it would be convenient to have possibility to set it also outside of policy (like global setting for all repositories). Is it bad idea?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep all the configurations inside a policy to follow the current behavior. Otherwise we can question if we should have a global setting to all the other configurations, and I don't believe that is the main goal of your proposal.

@DarthFennec DarthFennec left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing! I've also left some comments.


// curl command example for running this plugin (Prior Artifactory 5.x, use pipe '|' and not semi-colons ';' for parameters separation).
// curl -i -uadmin:password -X POST "http://localhost:8081/artifactory/api/plugins/execute/cleanup?params=months=1;repos=libs-release-local;dryRun=true;paceTimeMS=2000;disablePropertiesSupport=true"
// curl -i -uadmin:password -X POST "http://localhost:8081/artifactory/api/plugins/execute/cleanup?params=months=1;repos=libs-release-local;dryRun=true;paceTimeMS=2000;disablePropertiesSupport=true,keepRelease=true"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Params are separated by semicolons, it won't work with a comma.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch! my mistake! i will fix it tomorrow

else {
validator = true
}
return validator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can be shortened to something like:

private def checkName(keepRelease, releaseRegex, artifactName) {
    return !keepRelease || !(artifactName ==~ releaseRegex)
}

Global.paceTimeMS = params['paceTimeMS'] ? params['paceTimeMS'][0] as int : 0
artifactCleanup(months, repos, log, Global.paceTimeMS, dryRun, disablePropertiesSupport)
def keepRelease = params['keepRelease'] ? params['keepRelease'][0].toBoolean() : false
def releaseRegex = params['releaseRegex'] ? config.regex as Pattern : ~/.*-\d\.\d\.\d\.*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a good default pattern? I feel like -\d+\.\d+\.\d+ or something would do better.

@wotd

wotd commented Apr 6, 2018

Copy link
Copy Markdown
Author

Guys, I have fixed most of your comments. Please take a look and let me know what do you think.

@DarthFennec

Copy link
Copy Markdown
Contributor

Looks better. There's still a typo in your regex ~/.*-\d+\.\d+\.\d+\.*/; I don't think you mean to escape that last dot. So it should be ~/.*-\d+\.\d+\.\d+.*/ (or even just ~/-\d+\.\d+\.\d+/ will work fine, you don't need those .*s at the beginning and end).

Other than that I think it's good!

@elioengcomp elioengcomp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wotd thanks for the fixes. I've added two more comments.

log.info "\t==> currentUser: ${security.currentUser().getUsername()}"
log.info "\t==> canDelete: ${security.canDelete(it)}"
log.info "\t==> protected by regex: ${releaseRegex}"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace the duplicated log lines here by something like this:

log.info "Found $it, $cntFoundArtifacts/$artifactsCleanedUp.size total $bytesFound bytes"
log.info "\t==> currentUser: ${security.currentUser().getUsername()}"	
log.info "\t==> canDelete: ${security.canDelete(it)}"
if (checkName(keepRelease, releaseRegex, it)) {
    log.info "\t==> protected by regex: ${releaseRegex}"
} 

Global.paceTimeMS = params['paceTimeMS'] ? params['paceTimeMS'][0] as int : 0
artifactCleanup(months, repos, log, Global.paceTimeMS, dryRun, disablePropertiesSupport)
def keepRelease = params['keepRelease'] ? params['keepRelease'][0].toBoolean() : false
def releaseRegex = config.policies[0][7] ? config.policies[0][7] as Pattern : ~/.*-\d+\.\d+\.\d+\.*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using the first policy regex as a default value for cleanup requests. Why aren't you getting the value from the parameters like the others?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not possible to properly pass all regex chars in POST request (I think some of them are forbidden) so it would be easier to avoid this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can percent-encode them by hand of course, but that's probably not the best approach. Still, just going with the first configured regex seems weird as well. Who's to say the first regex is the correct one? If you need one of the others (or an entirely different non-configured one) you're just out of luck ...

It might be possible to choose the "most correct" regex based on the provided repo names, or even their package types, but there are problems with that too.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@martinm82

Copy link
Copy Markdown

@wotd can we close this PR in favour of #399?

@yashprit-jfrog

Copy link
Copy Markdown
Contributor

Closing this PR due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants