The following section provides a sample code for a Before Remote Download worker.
export default async (context: PlatformContext, data: BeforeRemoteDownloadRequest): Promise<BeforeRemoteDownloadResponse> => { let status: ActionStatus = ActionStatus.UNSPECIFIED; let requestHeaders: { [key: string]: Header } = {}; try { // The in-browser HTTP client facilitates making calls to the JFrog REST APIs //To call an external endpoint, use 'await context.clients.axios.get("https://foo.com")' const res = await context.clients.platformHttp.get('/artifactory/api/v1/system/readiness'); // You should reach this part if the HTTP request status is successful (HTTP Status 399 or lower) if (res.status === 200) { status = ActionStatus.PROCEED; requestHeaders['Content-Type'] = { value: ['text/plain'] }; console.log("Artifactory ping success"); } else { status = ActionStatus.WARN; console.warn(`Request is successful but returned status other than 200. Status code : ${res.status}`); } } catch(error) { // The platformHttp client throws PlatformHttpClientError if the HTTP request status is 400 or higher status = ActionStatus.STOP; console.error(`Request failed with status code ${error.status || '<none>'} caused by : ${error.message}`) } return { message: "proceed", status: ActionStatus.PROCEED, requestHeaders, } }
Input Parameters
context
Provides baseUrl, token, and clients to communicate with the JFrog Platform (for more information, see PlatformContext).
data
The request with download details sent by Artifactory.
{ "metadata": { "repoPath": { "key": "local-repo", "path": "folder/subfolder/my-file", "id": "local-repo:folder/subfolder/my-file", "isRoot": false, "isFolder": false }, "originalRepoPath": { "key": "local-repo", "path": "old/folder/subfolder/my-file", "id": "local-repo:old/folder/subfolder/my-file", "isRoot": false, "isFolder": false }, "name": "my-file", "headOnly": false, "checksum": false, "recursive": false, "modificationTime": 0, "directoryRequest": false, "metadata": false, "lastModified": 1, "ifModifiedSince": 0, "servletContextUrl": "https://jpd.jfrog.io/artifactory", "uri": "/artifactory/local-repo/folder/subfolder/my-file", "clientAddress": "100.100.100.100", "zipResourcePath": "", "zipResourceRequest": false, "replaceHeadRequestWithGet": false, "repoType": 1 }, "userContext": { "id": "jffe@00xxxxxxxxxxxxxxxxxxxxxxxx/users/bob", "isToken": true, "realm": "realm" }, "headers": { "Content-Type": { "value": [ "text/plain" ] }, "Accept": { "value": [ "application/json" ] } } }
Response
{ "data": { "message": "proceed", "status": 1, "requestHeaders": { "Content-Type": { "value": [ "text/plain" ] } } }, "executionStatus": "STATUS_SUCCESS" }
Possible Statuses
ActionStatus.PROCEED
- The worker allows Artifactory to proceed with downloading an artifact from the remote.ActionStatus.STOP
- The worker does not allow Artifactory to download an artifact from the remote.ActionStatus.WARN
- The worker provides a warning before Artifactory can proceed with downloading an artifact from the remote.