The following section provides a sample code for a Execute Worker for Generic Event worker.
This sample code calls an API and fetches its data into a response object. The worker could be potentially be used to enable non-Platform Admin users to run an API which requires Platform Admin permissions.
export default async (context: PlatformContext, data: { repoKey: string }): Promise<{ error: string | undefined, repository: any }> => { const response = { error: undefined, repository: {}, }; try { // Ref: https://jfrog.com/help/r/jfrog-rest-apis/repository-configuration const res = await context.clients.platformHttp.get(`/artifactory/api/repositories/${data.repoKey}`); if (res.status === 200) { response.repository = res.data; console.log("Repository fetch success"); } else { response.error = `Request is successful but returned an unexpected status : ${ res.status }`; console.warn(response.error); } } catch(error) { response.error = `Request failed with status code ${ error.status || '<none>' }`; console.error(response.error); } return response; }
Input Parameters
context
Provides baseUrl, token, and clients to communicate with the JFrog Platform (for more information, see PlatformContext).
data
The request with upload details sent by Artifactory.
{ "foo": "one" }
Response
{ "data": { "repository": { "key": "type", "packageType": "type", "description": "", "notes": "", "includesPattern": "**/*", "excludesPattern": "", "repoLayoutRef": "simple-default", "signedUrlTtl": 90, "enableComposerSupport": false, "enableNuGetSupport": false, "enableGemsSupport": false, "enableNpmSupport": false, "enableBowerSupport": false, "enableChefSupport": false, "enableCocoaPodsSupport": false, "enableConanSupport": false, "enableDebianSupport": true, "debianTrivialLayout": false, "ddebSupported": false, "enablePypiSupport": false, "enablePuppetSupport": false, "enableDockerSupport": false, "dockerApiVersion": "V2", "blockPushingSchema1": true, "forceNugetAuthentication": false, "forceP2Authentication": false, "forceConanAuthentication": false, "enableVagrantSupport": false, "enableGitLfsSupport": false, "enableDistRepoSupport": false, "dockerProjectId": "", "priorityResolution": false, "environments": [], "checksumPolicyType": "client-checksums", "handleReleases": true, "handleSnapshots": true, "maxUniqueSnapshots": 0, "maxUniqueTags": 0, "snapshotVersionBehavior": "unique", "suppressPomConsistencyChecks": false, "blackedOut": false, "propertySets": [ "artifactory" ], "optionalIndexCompressionFormats": [ "bz2" ], "archiveBrowsingEnabled": false, "calculateYumMetadata": false, "enableFileListsIndexing": false, "yumRootDepth": 0, "dockerTagRetention": 1, "enableComposerV1Indexing": false, "terraformType": "MODULE", "encryptStates": true, "cargoInternalIndex": false, "cargoAnonymousAccess": false, "xrayDataTtl": 90, "downloadRedirect": false, "cdnRedirect": false, "xrayIndex": true, "rclass": "local" } }, "executionStatus": "STATUS_SUCCESS" }
Example
curl --location '<JDP_BASE_URL>/worker/api/v1/execute/<WORKER_KEY>' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer <BEARER>' \ --data '{ "repoKey": "my-repository" }'