Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions download/ExpireFileInRepos/ExpireFileInReposTest.groovy
Original file line number Diff line number Diff line change
@@ -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
}
}
23 changes: 23 additions & 0 deletions download/ExpireFileInRepos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Artifactory expireFileInRepos 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/virtual
repository.

## Features

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

* 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

38 changes: 38 additions & 0 deletions download/ExpireFileInRepos/expireFileInRepos.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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<String> reposToExpire = List.of(/*TODO: add repo names*/)

download {
beforeDownloadRequest { Request request, RepoPath repoPath ->
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
}
}
}

def isRemote(String repoKey) {
return repositories.getRemoteRepositories().contains(repoKey)
}

def isVirtual(String repoKey) {
return repositories.getVirtualRepositories().contains(repoKey)
}