bug fix for casting string to boolean and added possibility to keep artefacts based on regex - #204
bug fix for casting string to boolean and added possibility to keep artefacts based on regex#204wotd wants to merge 4 commits into
Conversation
Fixed bug with casting string to boolean
There was a problem hiding this comment.
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\.*/ |
There was a problem hiding this comment.
Could you provide more details about the releaseRegex parameter being referenced here. It looks like the parameter value is not being used at all.
There was a problem hiding this comment.
What do you mean? It is used in artifactCleanup function :)
There was a problem hiding this comment.
@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\.*/ |
There was a problem hiding this comment.
What is purpose of this regex defined out of a policy?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Params are separated by semicolons, it won't work with a comma.
There was a problem hiding this comment.
ouch! my mistake! i will fix it tomorrow
| else { | ||
| validator = true | ||
| } | ||
| return validator |
There was a problem hiding this comment.
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\.*/ |
There was a problem hiding this comment.
Is this a good default pattern? I feel like -\d+\.\d+\.\d+ or something would do better.
|
Guys, I have fixed most of your comments. Please take a look and let me know what do you think. |
|
Looks better. There's still a typo in your regex Other than that I think it's good! |
elioengcomp
left a comment
There was a problem hiding this comment.
@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}" | ||
| } |
There was a problem hiding this comment.
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+\.*/ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
|
|
Closing this PR due to inactivity. |
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.