After Delete Property Worker Code Sample

JFrog Platform Administration Documentation

Content Type
Administration / Platform
ft:sourceType
Paligo

The following section provides a sample code for an After Delete Property worker.

export default async (context: PlatformContext, data: AfterPropertyDeleteRequest): Promise<AfterPropertyDeleteResponse> => {
    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");
        } else {
            console.warn(`Request was successful and returned status code : ${res.status}`);
        }
    } 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}`);
    }

    return {
        message: "proceed",
        modifiedRepoPath: data.metadata.repoPath
    };
};

Input Parameters

context

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

data

The request with delete property details sent by Artifactory.

{
  "metadata": {  // Object containing metadata information about the artifact
    "repoPath": {  // Information about the repository path for the artifact
      "key": "local-repo",  // Unique key identifier for the repository
      "path": "folder/subfolder/my-file",  // Path to the file within the repository
      "id": "local-repo:folder/subfolder/my-file",  // Unique identifier combining the repo 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)
    },
    "contentLength": 100,  // Length of the content in bytes
    "lastModified": 0,  // Timestamp of the last modification (0 indicates no modification)
    "trustServerChecksums": false,  // Indicates whether server checksums should be trusted
    "servletContextUrl": "https://jpd.jfrog.io/artifactory",  // URL for the servlet context
    "skipJarIndexing": false,  // Indicates whether to skip indexing for JAR files
    "disableRedirect": false,  // Indicates whether HTTP redirects should be disabled
    "repoType": 1  // Numeric type identifier for the repository (e.g., local, remote, virtual)
  },
  "userContext": {  // Object containing information about the user context
    "id": "id",  // Unique identifier for the user
    "isToken": false,  // Indicates if the user is authenticated via a token
    "realm": "realm"  // Realm for user authentication context
  },
  "itemInfo": {  // Object containing information about the item (artifact)
    "repoPath": {  // Information about the repository path of the item
      "key": "local-repo",  // Unique key identifier for the repository
      "path": "folder/subfolder/my-file",  // Path to the file within the repository
      "id": "local-repo:folder/subfolder/my-file",  // Unique identifier combining the repo 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)
    },
    "name": "my-artifact",  // Name of the artifact
    "created": 1,  // Timestamp of when the artifact was created (assuming Unix timestamp)
    "lastModified": 0  // Timestamp of the last modification (0 indicates no modification)
  },
  "name": "property-name"  // Name of a specific property associated with the artifact
}
Response
{
  "data": {  // Main data object containing response information
    "message": "proceed",  // Message to print to the log. If there is an error it will be printed as a warning.
    "modifiedRepoPath": {  // Object containing details about the modified repository path
      "key": "local-repo",  // Unique 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 repo key and path
      "isRoot": false,  // Indicates whether the path is a root directory (false means it is a file within a subdirectory)
      "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 : This is a mandatory field.