Before Upload Worker Code Sample

JFrog Platform Administration Documentation

Content Type
Administration / Platform
ft:sourceType
Paligo

The following section provides a sample code for an Before Upload worker.

export default async (context: PlatformContext, data: BeforeUploadRequest): Promise<BeforeUploadResponse> => {

   console.log(await context.clients.platformHttp.get('/artifactory/api/system/ping'));
   console.log(await axios.get('https://my.external.resource'));

   return {
       status: 'UPLOAD_PROCEED',
       message: 'proceed',
       modifiedRepoPath: {
           "key": "key",
           "path": "path",
           "id": "key:path",
           "isRoot": false,
           "isFolder": false
       }
   }
}

Input Parameters

context

Provides baseUrl, token, and clients to communicate with the JFrog Platform (for more information, see PlatformContext).

data

The request with upload details sent by Artifactory.

{
 "metadata": { // Various immutable upload metadata
   "repoPath": { // The repository path object of the request
     "key": "key", // The repository key
     "path": "path", // The path itself
     "id": "key:path", // The key:path combination
     "isRoot": false, // Is the path the root?
     "isFolder": false // Is the path a folder?
   },
   "contentLength": 0, // The deploy request content length
   "lastModified": 1, // Last modification time that occurred
   "trustServerChecksums": false, // Is the request trusting the server checksums?
   "servletContextUrl": "base", // The URL that points to Artifactory
   "skipJarIndexing": false, // Is it a request that skips jar indexing?
   "disableRedirect": false, // Is redirect disabled on this request?
   "repoType": 1 // Repository type
 },
 "headers": { // The immutable request headers
   "key": {
     "value": []
   }
 },
 "userContext": { // The user context which sends the request
   "id": "id", // The username or subject
   "isToken": false, // Is the context an access token?
   "realm": "realm" // The realm of the user
 },
 "artifactProperties": {  // The properties of the request
   "key": {
     "value": []
   }
 }
}

Response

{
       status: 'UPLOAD_PROCEED', // The instruction on how to proceed
       message: 'proceed', // Message to print to the log. If there is an error it will be printed as a warning.
       modifiedRepoPath: { // The modified repository path from the worker)
           "key": "key", // The repository key
           "path": "path", // The path itself
           "id": "key:path", // The key:path combination
           "isRoot": false, // Is the path the root?
           "isFolder": false // Is the path a folder?
       }
}

Possible Statuses

  • UploadStatus.UPLOAD_PROCEED - The worker allows to proceed with the upload.

  • UploadStatus.UPLOAD_STOP - The worker forbids upload. Upload will be aborted.

  • UploadStatus.UPLOAD_WARN - The worker allows to proceed with the upload. A warning log with the provided message will be recorded in Artifactory.