Overview
The Filtered Resources Add-on (introduced in Artifactory version 2.3.3) allows treating any textual file as a filtered resource by processing it as a FreeMarker template.
Each file artifact can be marked as 'filtered' and upon a download request, the content of the artifact is passed through a FreeMarker processer before being returned to the user.
This feature is extremely powerful and flexible since Artifactory provides some of its own API to the filtering context (see below), allowing you to create and provision dynamic content, based on information stored in Artifactory.
For example, you can provision different content base on the user originating IP address or based on changing property values attached to the artifact.
Marking an Artifact as a Filtered Resource
Each artifact can become filtered by selecting it in the artifacts Tree Browser and marking the checkbox labeled 'Filtered' located in the 'General' tab.
NOTE! that you must have 'annotate' permissions on the artifact.
Filtering Context
Artifactory provides the following environment variables for the FreeMarker template:
- "properties" (org.artifactory.md.Properties) - Contains the properties of the requested artifact and any matrix params included in the request; when a clash of properties with identical keys occurs, the former takes precedence
- "request" (org.artifactory.request.Request) - The current request that was sent for the artifact
- "security" (org.artifactory.security.Security) - Artifactory's current security object
Provisioning Build Tool Settings
When logged-in as an admin user, you can provision your user-generated settings for the various build tools (Maven, Gradle and Ivy) using the Filtered Resources features.
To provision user-generated settings:
- Browse to the settings generator of the desired build tool.
- Select the appropriate repositories.
- Edit the settings as required.
- Under the "Settings Provisioning" section: select a target repository and path
- Click Generate.
Example
The following example demonstrates provisioning a different resource based on the current user group and a property on the requested artifact.
In this example, the artifact 'vcsProj.conf.xml'
has a property 'vcs.rootUrl'
which holds the root URL for the version control system. Depending on the user group a different project version control URL is returned.
For the template of 'vcsProj.conf.xml'
:
<servers> <#list properties.get("vcs.rootUrl") as vcsUrl> <#list security.getCurrentUserGroupNames() as groupName> <vcs>${vcsUrl}/<#if groupName == "dev-product1">product1<#elseif groupName == "dev-product2">product2<#else>global</#if></vcs> </#list> </#list> </servers>
If, for example, the value of the the 'vcs.rootUrl'
property on the 'vcsProj.conf.xml'
artifact is 'http://vcs.company.com'
and the file is downloaded by a developer belonging to the 'dev-product2'
group, then the returned content is:
<servers> <vcs> http://vcs.company.com/product2 </vcs> </servers>