After Copy Worker Code Sample

JFrog Platform Administration Documentation

Content Type
Administration / Platform
ft:sourceType
Paligo

The following section provides a sample code for an After Copy worker.

export default async (context: PlatformContext, data: AfterCopyRequest): Promise<AfterCopyResponse> => {

  try {
      // The HTTP client facilitates calls to the JFrog Platform 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) {
          console.log("Artifactory ping success");
      } else {
          console.warn(`Request was successful and returned status code : ${ res.status }`);
      }
  } catch(error) {
      // The platformHttp client throws PlatformHttpClientError if the HTTP request status is 400 or higher
      console.error(`Request failed with status code ${ error.status || '<none>' } caused by : ${ error.message }`)
  }

  return {
      message: 'proceed'
  }
}

Input Parameters

context

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

data

The request with copy details sent by Artifactory.

{
  "metadata": {  // Metadata information about the repository and file
    "repoPath": {  // Path information for the repository
      "key": "local-repo",  // The key or identifier for the local repository
      "path": "folder/subfolder/my-file",  // The location of the file within the repository
      "id": "local-repo:folder/subfolder/my-file",  // Unique identifier combining repo key and path
      "isRoot": false,  // Indicates whether this path is the root of the repository (true/false)
      "isFolder": false  // Indicates whether this is a folder (true) or a file (false)
    },
    "contentLength": 100,  // Length of the content in bytes
    "lastModified": 0,  // Timestamp of the last modification (0 means not modified)
    "trustServerChecksums": false,  // Indicates whether server checksums are trusted (true/false)
    "servletContextUrl": "servlet.com",  // URL context for servlet, useful for API interactions
    "skipJarIndexing": false,  // Flag to skip indexing for JAR files (true/false)
    "disableRedirect": false,  // Flag to disable HTTP redirects (true/false)
    "repoType": 1  // Indicates the type of repository (e.g., binary, docker, etc. based on a defined scheme)
  },
  "targetRepoPath": {  // Destination path information for the target repository
    "key": "target-repo",  // The key or identifier for the target repository
    "path": "new_folder/my-file",  // The desired location of the file in the target repository
    "id": "target-repo:new_folder/my-file",  // Unique identifier for the target path
    "isRoot": false,  // Indicates whether this path is the root of the repository (true/false)
    "isFolder": false  // Indicates whether this is a folder (true) or a file (false)
  },
  "properties": {  // Custom properties associated with the file
    "prop1": {  // A custom property named "prop1"
      "value": [  // An array of values for this property
        "value1",  // First value for prop1
        "value2"   // Second value for prop1
      ]
    },
    "size": {  // Custom property representing the size of the file
      "value": "50Gb"  // The size value for this property
    },
    "shaResolution": {  // Custom property for hash resolution
      "value": "sha256"  // Specifies the SHA algorithm used (e.g., sha256)
    }
  },
  "userContext": {  // Contextual information about the user making the request
    "id": "id",  // Unique identifier for the user
    "isToken": false,  // Indicates if the user is authenticated via a token (true/false)
    "realm": "realm"  // The realm in which the user is authenticated (used for authorization)
  }
}
Response
{
  "data": {
    /** Message to print to the log, in case of an error it will be printed as a warning */
    "message": "proceed"
  },
  "executionStatus": "STATUS_SUCCESS"
}

message : This is a mandatory field.