The following section provides a sample code for an Alt Remote Content worker.
Note
Authorized JFrog Advanced Security (JAS) users can block download of remote content. For users without JAS, a warning will be logged.
export default async (
context: PlatformContext,
data: AltRemoteContentRequest
): Promise<AltRemoteContentResponse> => {
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,
};
};
Input Parameters
context
Provides baseUrl, token, and clients to communicate with the JFrog Platform (for more information, see PlatformContext).
data
The request with download request details sent by Artifactory.
{
"repoPath": {
"key": "local-repo",
"path": "folder/subfolder/my-file",
"id": "local-repo:folder/subfolder/my-file",
"isRoot": false,
"isFolder": false
},
"repoType": 1,
"userContext": {
"id": "jffe@00xxxxxxxxxxxxxxxxxxxxxxxx/users/bob",
"isToken": true,
"realm": "realm"
}
}
Response
{
"message": "proceed", // Message to print to the log. In case of an error, it will be printed as a warning.
"status": ActionStatus.PROCEED // Numeric status indicating the result of the operation (1 could signify success)
}
message : This is a mandatory field.
Possible Statuses
ActionStatus.PROCEED- The worker allows Artifactory to proceed with alt remote content events.ActionStatus.STOP- The worker does not allow Artifactory to alt remote content events.ActionStatus.WARN- The worker provides a warning before Artifactory can proceed with alt remote content events.