Before Property 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 Property Replication worker.

export default async (context: PlatformContext, data: BeforePropertyReplicationRequest): Promise<ReplicationResponse> => {
    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 property replication details sent by Artifactory.

{
  "targetRepoPath": {
    "key": "target-repo",
    "path": "new_folder/my-file",
    "id": "target-repo:new_folder/my-file",
    "isRoot": false,
    "isFolder": false
  },
  "userContext": {
    "id": "id",
    "isToken": false,
    "realm": "realm"
  },
  "targetInfo": {
    "instanceUrl": "artInstance1.jfrog.com",
    "repoKey": "testRepoKey"
  }
}
Response
{
  "data": {
    "message": "proceed",
    "status": 1
  },
  "executionStatus": "STATUS_SUCCESS"
}

Possible Statuses
  • ActionStatus.PROCEED - The worker allows Artifactory to proceed with replicating a property.

  • ActionStatus.STOP - The worker does not allow Artifactory to replicate a property.

  • ActionStatus.WARN - The worker provides a warning before Artifactory can proceed with replicating a property.