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: "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 move details sent by Artifactory.
For Artifactory Versions before 7.122
{
"metadata": { // Object containing metadata information about the artifact
"repoPath": { // Repository path information for the current location of the artifact
"key": "local-repo", // Unique key identifier for the repository
"path": "folder/subfolder/my-file", // Path to the specific artifact 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)
},
"contentLength": 100, // Length of the artifact's content in bytes
"lastModified": 0, // Timestamp of the last modification (0 indicates no modifications)
"trustServerChecksums": false, // Indicates whether server checksums should be trusted for validation
"servletContextUrl": "https://jpd.jfrog.io/artifactory", // URL for accessing the servlet context in Artifactory
"skipJarIndexing": false, // Indicates whether to skip indexing for JAR files (false means indexing will occur)
"disableRedirect": false, // Indicates whether HTTP redirects should be disabled
"repoType": 1 // Numeric identifier for the type of repository (1 typically denotes a local repository)
},
"targetRepoPath": { // Object containing information about the target repository path
"key": "target-repo", // Unique key identifier for the target repository
"path": "new_folder/my-file", // New path to the specific artifact within the target repository
"id": "target-repo:new_folder/my-file", // Unique identifier for the target path
"isRoot": false, // Indicates if the target path is a root directory (false means it is nested)
"isFolder": false // Indicates if the target path is a folder (false means it is a file)
},
"properties": { // Object containing properties associated with the artifact
"prop1": { // Custom property name
"value": [ // Array of values for the property
"value1", // First value of the property
"value2" // Second value of the property
]
},
"size": { // Property related to the size of the artifact
"value": "50Gb" // Size of the artifact specified as a string
},
"shaResolution": { // Property indicating the hashing algorithm used
"value": "sha256" // Value indicating the SHA resolution (hashing algorithm)
}
},
"userContext": { // Object containing information about the user making the request
"id": "id", // Unique identifier for the user
"isToken": false, // Indicates if the user is authenticated using a token (false means not)
"realm": "realm" // Realm for user authentication context
}
}
For Artifactory Versions from 7.122
{
"metadata": { // Object containing metadata information about the artifact
"repoPath": { // Repository path information for the current location of the artifact
"key": "local-repo", // Unique key identifier for the repository
"path": "folder/subfolder/my-file", // Path to the specific artifact 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)
},
"lastModified": 0, // Timestamp of the last modification (0 indicates no modifications)
"repoType": 1 // Numeric identifier for the type of repository (1 typically denotes a local repository)
},
"targetRepoPath": { // Object containing information about the target repository path
"key": "target-repo", // Unique key identifier for the target repository
"path": "new_folder/my-file", // New path to the specific artifact within the target repository
"id": "target-repo:new_folder/my-file", // Unique identifier for the target path
"isRoot": false, // Indicates if the target path is a root directory (false means it is nested)
"isFolder": false // Indicates if the target path is a folder (false means it is a file)
},
"properties": { // Object containing properties associated with the artifact
"prop1": { // Custom property name
"value": [ // Array of values for the property
"value1", // First value of the property
"value2" // Second value of the property
]
},
"userContext": { // Object containing information about the user making the request
"id": "id", // Unique identifier for the user
"isToken": false, // Indicates if the user is authenticated using a token (false means not)
"realm": "realm" // Realm for user authentication context
}
}
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 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.