From a2859219c1852695b01f547bf956d3c897da2520 Mon Sep 17 00:00:00 2001 From: dvirt Date: Tue, 29 Nov 2022 13:21:46 +0200 Subject: [PATCH 1/3] create new plugin expireFileInRemoteRepos --- .../ExpireFileInRemoteReposTest.groovy | 10 ++++++ download/ExpireFileInRemoteRepos/README.md | 21 ++++++++++++ .../expireFileInRemoteRepos.groovy | 33 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 download/ExpireFileInRemoteRepos/ExpireFileInRemoteReposTest.groovy create mode 100644 download/ExpireFileInRemoteRepos/README.md create mode 100644 download/ExpireFileInRemoteRepos/expireFileInRemoteRepos.groovy diff --git a/download/ExpireFileInRemoteRepos/ExpireFileInRemoteReposTest.groovy b/download/ExpireFileInRemoteRepos/ExpireFileInRemoteReposTest.groovy new file mode 100644 index 00000000..fa9ceb6e --- /dev/null +++ b/download/ExpireFileInRemoteRepos/ExpireFileInRemoteReposTest.groovy @@ -0,0 +1,10 @@ +import spock.lang.Specification + +class PluginTest extends Specification { + def 'not implemented plugin test'() { + when: + throw new Exception("Not implemented.") + then: + false + } +} \ No newline at end of file diff --git a/download/ExpireFileInRemoteRepos/README.md b/download/ExpireFileInRemoteRepos/README.md new file mode 100644 index 00000000..8fa14c04 --- /dev/null +++ b/download/ExpireFileInRemoteRepos/README.md @@ -0,0 +1,21 @@ +Artifactory expireFileInRemoteRepos User Plugin +==================================================== + +An implementation of the beforeDownloadRequest execution point. This +plugin causes artifacts (including binaries) to expire and be re-cached when downloaded from a remote +repository. + +## Features + +To use the plugin, modify the script by adding the names of the remote repositories you wish to expire files in. +The names are to be added to the list 'reposToExpire' + +## Installation + +* Place script under your plugins folder at `${ARTIFACTORY_HOME}/etc/plugins/` +* Restart your artifactory instance or [use the API to reload plugins][1] + + + +[1]:https://www.jfrog.com/confluence/display/RTF/User+Plugins#UserPlugins-ReloadingPlugins + diff --git a/download/ExpireFileInRemoteRepos/expireFileInRemoteRepos.groovy b/download/ExpireFileInRemoteRepos/expireFileInRemoteRepos.groovy new file mode 100644 index 00000000..ff5e5331 --- /dev/null +++ b/download/ExpireFileInRemoteRepos/expireFileInRemoteRepos.groovy @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2022 JFrog Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.artifactory.repo.RepoPath +import org.artifactory.request.Request + +final List reposToExpire = List.of(/*TODO: add repo names*/) + +download { + beforeDownloadRequest { Request request, RepoPath repoPath -> + if (reposToExpire.contains(repoPath.repoKey) && isRemote(repoPath.repoKey)) { + log.debug 'Repository ${repoPath.repoKey} is marked for file expiration. Expiring file: ${repoPath.name}' + expired = true + } + } +} + +def isRemote(String repoKey) { + return repositories.getRemoteRepositories().contains(repoKey) +} \ No newline at end of file From c952fbd3db9afefaadb74fa8b62c027a6753ea1e Mon Sep 17 00:00:00 2001 From: dvirt Date: Tue, 29 Nov 2022 16:12:59 +0200 Subject: [PATCH 2/3] create new plugin expireFileInRepos --- .../ExpireFileInReposTest.groovy} | 0 .../README.md | 8 +++++--- .../expireFileInRepos.groovy} | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) rename download/{ExpireFileInRemoteRepos/ExpireFileInRemoteReposTest.groovy => ExpireFileInRepos/ExpireFileInReposTest.groovy} (100%) rename download/{ExpireFileInRemoteRepos => ExpireFileInRepos}/README.md (65%) rename download/{ExpireFileInRemoteRepos/expireFileInRemoteRepos.groovy => ExpireFileInRepos/expireFileInRepos.groovy} (82%) diff --git a/download/ExpireFileInRemoteRepos/ExpireFileInRemoteReposTest.groovy b/download/ExpireFileInRepos/ExpireFileInReposTest.groovy similarity index 100% rename from download/ExpireFileInRemoteRepos/ExpireFileInRemoteReposTest.groovy rename to download/ExpireFileInRepos/ExpireFileInReposTest.groovy diff --git a/download/ExpireFileInRemoteRepos/README.md b/download/ExpireFileInRepos/README.md similarity index 65% rename from download/ExpireFileInRemoteRepos/README.md rename to download/ExpireFileInRepos/README.md index 8fa14c04..b56faab2 100644 --- a/download/ExpireFileInRemoteRepos/README.md +++ b/download/ExpireFileInRepos/README.md @@ -2,13 +2,15 @@ Artifactory expireFileInRemoteRepos User Plugin ==================================================== An implementation of the beforeDownloadRequest execution point. This -plugin causes artifacts (including binaries) to expire and be re-cached when downloaded from a remote +plugin causes artifacts (including binaries) to expire and be re-cached when downloaded from a remote/virtual repository. ## Features -To use the plugin, modify the script by adding the names of the remote repositories you wish to expire files in. -The names are to be added to the list 'reposToExpire' +To use the plugin, modify the script by adding the names of the repositories you wish to expire artifacts in. +The names are to be added to the list 'reposToExpire'. +Note: using this plugin, when downloading artifacts from virtual repositories - artifacts are expired and served from +the source repo for all underlying repos ## Installation diff --git a/download/ExpireFileInRemoteRepos/expireFileInRemoteRepos.groovy b/download/ExpireFileInRepos/expireFileInRepos.groovy similarity index 82% rename from download/ExpireFileInRemoteRepos/expireFileInRemoteRepos.groovy rename to download/ExpireFileInRepos/expireFileInRepos.groovy index ff5e5331..9ec64a7d 100644 --- a/download/ExpireFileInRemoteRepos/expireFileInRemoteRepos.groovy +++ b/download/ExpireFileInRepos/expireFileInRepos.groovy @@ -21,7 +21,8 @@ final List reposToExpire = List.of(/*TODO: add repo names*/) download { beforeDownloadRequest { Request request, RepoPath repoPath -> - if (reposToExpire.contains(repoPath.repoKey) && isRemote(repoPath.repoKey)) { + if ((isRemote(repoPath.repoKey) || isVirtual(repoPath.repoKey)) + && reposToExpire.contains(repoPath.repoKey)) { log.debug 'Repository ${repoPath.repoKey} is marked for file expiration. Expiring file: ${repoPath.name}' expired = true } @@ -30,4 +31,8 @@ download { def isRemote(String repoKey) { return repositories.getRemoteRepositories().contains(repoKey) +} + +def isVirtual(String repoKey) { + return repositories.getVirtualRepositories().contains(repoKey) } \ No newline at end of file From 7395d9e33cfc9870d442ecc85ed50fe4dccf855a Mon Sep 17 00:00:00 2001 From: dvirt Date: Tue, 29 Nov 2022 16:24:07 +0200 Subject: [PATCH 3/3] create new plugin expireFileInRepos --- download/ExpireFileInRepos/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/download/ExpireFileInRepos/README.md b/download/ExpireFileInRepos/README.md index b56faab2..5bd548c2 100644 --- a/download/ExpireFileInRepos/README.md +++ b/download/ExpireFileInRepos/README.md @@ -1,4 +1,4 @@ -Artifactory expireFileInRemoteRepos User Plugin +Artifactory expireFileInRepos User Plugin ==================================================== An implementation of the beforeDownloadRequest execution point. This