Alt Remote Path Worker Code Sample

JFrog Platform Administration Documentation

Content Type
Administration / Platform
ft:sourceType
Paligo

The following section provides a sample code for an alt remote path worker.

export default async (context: PlatformContext, data: AltRemotePathRequest): Promise<AltRemotePathResponse> => {
    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) {
            console.log("Artifactory ping success");
            status = ActionStatus.PROCEED;
        } else {
            console.warn(`Request is successful but returned status other than 200. Status code : ${res.status}`);
            status = ActionStatus.WARN;
        }
    } 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}`)
        status = ActionStatus.STOP;
    }

    return {
        message: "proceed",
        status: 1,
        modifiedRepoPath: data.repoPath
    }
}

Input Parameters

context

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

data

The request with alt remote path details sent by Artifactory.

{
  "repoPath": {  // Object containing information about the path of the artifact in the repository
    "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 not)
    "isFolder": false  // Indicates if the path is a folder (false means it is a file)
  },
  "repoType": 1,  // Numeric identifier representing the type of repository (e.g., 1 for local, 2 for remote, etc.)
  "userContext": {  // Object containing information about the user making the request
    "id": "jffe@00xxxxxxxxxxxxxxxxxxxxxxxx/users/bob",  // Unique identifier for the user
    "isToken": true,  // Indicates if the user is authenticated with a token (true means they are)
    "realm": "realm"  // Realm for user authentication context
  }
}
Response
{
  "data": {  // Main data object containing the response information
    "message": "proceed",  // Message to print to the log. If there is an error it will be printed as a warning
    "status": 1,  // Numeric status indicating the result of the operation (1 typically signifies success)
    "modifiedRepoPath": {  // Object containing details about the modified repository path
      "key": "local-repo",  // Unique key identifier for the repository
      "path": "folder/subfolder/my-file",  // Path to the modified file within the repository
      "id": "local-repo:folder/subfolder/my-file",  // Unique identifier combining the repository key and path
      "isRoot": false,  // Indicates whether the path is a root directory (false means it is nested)
      "isFolder": false  // Indicates whether the path is a folder (false means it is a file)
    }
  },
  "executionStatus": "STATUS_SUCCESS"  // Status indicating that the execution was successful
}
  • message and status : These are mandatory fields.

  • modifiedRepoPath: This is an optional field.

Possible Statuses
  • ActionStatus.PROCEED - The worker allows Artifactory to proceed with copying an artifact in storage.

  • ActionStatus.STOP - The worker does not allow Artifactory to copy an artifact in storage.

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