The following section provides a sample code for a Before Create Property worker.
export default async (context: PlatformContext, data: BeforePropertyCreateRequest): Promise<BeforePropertyCreateResponse> => { let status: BeforePropertyCreateStatus = BeforePropertyCreateStatus.BEFORE_PROPERTY_CREATE_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 = BeforePropertyCreateStatus.BEFORE_PROPERTY_CREATE_PROCEED; console.log("Artifactory ping success"); } else { status = BeforePropertyCreateStatus.BEFORE_PROPERTY_CREATE_WARN; console.warn(`Request is successful but returned status other than 200. Status code : ${ res.status }`); } } catch(error) { // The platformHttp client throws PlatformHttpClientError if the HTTP request status is 400 or higher status = BeforePropertyCreateStatus.BEFORE_PROPERTY_CREATE_STOP; 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 create 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 }, "userContext": { "id": "id", "isToken": false, "realm": "realm" }, "itemInfo": { "repoPath": { "key": "local-repo", "path": "folder/subfolder/my-file", "id": "local-repo:folder/subfolder/my-file", "isRoot": false, "isFolder": false }, "name": "my-artifact", "created": 1, "lastModified": 0 }, "name": "property-name", "values": [ "value1", "value2" ] }
Response
{ status: BeforePropertyCreateStatus.BEFORE_PROPERTY_CREATE_PROCEED, message: 'proceed', }
Possible Statuses
BeforePropertyCreateStatus.BEFORE_PROPERTY_CREATE_PROCEED
- The worker allows Artifactory to proceed with creating a property.BeforePropertyCreateStatus.BEFORE_PROPERTY_CREATE_STOP
- The worker does not allow Artifactory to create a property.BeforePropertyCreateStatus.BEFORE_PROPERTY_CREATE_WARN
- The worker provides a warning before Artifactory can proceed with creating a property.