Before Delete Replication Worker Code Sample

JFrog Platform Administration Documentation

Content Type
Administration / Platform

The following section provides a sample code for a Before Delete Replication worker.

export default async (
  context: PlatformContext,
  data: BeforeDeleteReplicationRequest
): Promise<BeforeDeleteReplicationResponse> => {
  let status: ActionStatus = ActionStatus.UNSPECIFIED;
  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;
      console.log("Artifactory ping success");
    } else {
      status = ActionStatus.WARN;
      console.warn(
        `Request was successful and returned status code : ${res.status}`
      );
    }
  } catch (error) {
    status = ActionStatus.STOP;
    // 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",
    status,
  };
};

Input Parameters

context

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

data

The request with delete replication details sent by Artifactory.

{
  "metadata": {  // Object containing metadata about the artifact
    "repoPath": {  // Current repository path information for the artifact
      "key": "local-repo",  // Unique key identifier for the repository
      "path": "folder/subfolder/my-file",  // Path to the specific file within the repository
      "id": "local-repo:folder/subfolder/my-file",  // Unique identifier combining the repository key and path
      "isRoot": false,  // Indicates if the path is a root directory (false means it is nested)
      "isFolder": false  // Indicates if the path is a folder (false means it is a file)
    },
    "repoType": 1  // Numeric identifier for the type of repository (1 typically denotes a local repository)
  },
  "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)
  },
  "targetInfo": {  // Object containing information about the target instance and repository
    "instanceUrl": "artInstance1.jfrog.com",  // URL of the target JFrog Artifactory instance
    "repoKey": "testRepoKey"  // Key identifier for the target repository
  }
}
Response
{
 "message": "proceed", // Message to print to the log, in case of an error, it will be printed as a warning
 "status": "proceed" // The instruction of how to proceed
}
  • message and status : These are mandatory fields.

Possible Statuses
  • ActionStatus.PROCEED - The worker allows Artifactory to proceed with deleting a replication.

  • ActionStatus.STOP - The worker does not allow Artifactory to delete a replication.

  • ActionStatus.WARN - The worker provides a warning before Artifactory can proceed with deleting a replication.