Before Move Worker Code Sample

JFrog Platform Administration Documentation

Content Type
Administration / Platform
ft:sourceType
Paligo

The following section provides a sample code for a Before Move worker.

export default async (context: PlatformContext, data: BeforeMoveRequest): Promise<BeforeMoveResponse> => {
    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: ActionStatus.PROCEED,
        status: "proceed"
    };
};

Input Parameters

context

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

data

The request with move details sent by Artifactory.

{
  "metadata": {
    "repoPath": {
      "key": "local-repo",
      "path": "folder/subfolder/my-file",
      "id": "local-repo:folder/subfolder/my-file",
      "isRoot": false,
      "isFolder": false
    },
    "contentLength": 100,
    "lastModified": 0,
    "trustServerChecksums": false,
    "servletContextUrl": "https://jpd.jfrog.io/artifactory",
    "skipJarIndexing": false,
    "disableRedirect": false,
    "repoType": 1
  },
  "targetRepoPath": {
    "key": "target-repo",
    "path": "new_folder/my-file",
    "id": "target-repo:new_folder/my-file",
    "isRoot": false,
    "isFolder": false
  },
  "properties": {
    "prop1": {
      "value": [
        "value1",
        "value2"
      ]
    },
    "size": {
      "value": "50Gb"
    },
    "shaResolution": {
      "value": "sha256"
    }
  },
  "userContext": {
    "id": "id",
    "isToken": false,
    "realm": "realm"
  }
}
Response
{
  "data": {
    "status": "proceed",
    "message": "proceed"
  },
  "executionStatus": "STATUS_SUCCESS"
}
Possible Statuses
  • ActionStatus.PROCEED - The worker allows Artifactory to proceed with moving an artifact.

  • ActionStatus.STOP - The worker does not allow Artifactory to move an artifact.

  • ActionStatus.WARN - The worker provides a warning before Artifactory can proceed with moving an artifact.