Before Delete Replication Worker Code Sample

JFrog Platform Administration Documentation

Content Type
Administration / Platform
ft:sourceType
Paligo

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.

{
  "targetRepoPath": {  // Object containing information about the target repository path
    "key": "target-repo",  // Unique key identifier for the target repository
    "path": "new_folder/my-file",  // Path to the specific target file within the repository
    "id": "target-repo:new_folder/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)
  },
  "userContext": {  // Object containing information about the user making the request
    "id": "id",  // Unique identifier for the user
    "isToken": false,  // Indicates whether the user is authenticated using a token (false means not)
    "realm": "realm"  // Realm for user authentication context
  },
  "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
{
  "data": {
    "message": "proceed", // Message to print to the log. In case of an error, it will be printed as a warning.
    "status": 1 // The instruction of how to proceed
  },
  "executionStatus": "STATUS_SUCCESS"
}

  • 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.