How can I attach a license from a License Bucket to an Artifactory using REST APIs for automation?

Joshua Han
2019-09-28 03:36

Summary

You may use this solution for automation of Artifactory license provisioning. Also, this solution can be used for provisioning the license when Artifactory cannot be added to Mission Control.
 

Affected Versions

Artifactory 6.x, Mission Control 3.x
 

Details

JFrog Mission Control provides a number of functions for effectively managing multiple JFrog Platform Deployments (JPD) – a combination of Artifactory, Edge, Distribution, and Xray. Thus it is the best practice if those JPDs to be managed by the Mission Control. Although most of the JPD services are required to be connected to the Mission Control, you have an option for setting up Artifactory (both Edge and Enterprise+) without connecting to the Mission Control if you have any network or security restrictions. This solution describes how to attach a license using REST APIs, which is useful for automating the process.

This solution can also be used for general automation of the license provisioning flow using each REST API.
 

Resolution

1. Add license buckets to Mission Control. Below are some screenshots that were taken while configuring this via UI, which can also be done via REST APIs.

2. (Recommended but not required; This is step can be skipped if Artifactory cannot be added to the Mission Control.) Please bear in mind, that it is best to add the Artifactory to Mission Control, so you can easily track and manage licenses instead of manually assigning and tracking them. These steps can also be done via UI or SITES and SERVICES REST APIs.

3. Use Mission Control REST API: Attach License to attach a license from the license bucket to an Artifactory.

a. In order to output the license key as a file, set "deploy":false

b. make sure to provide a unique name as a service_name. You'll need to manually track following because Artifactory is not connected to the Mission Control:

b1. service_name that was used with the attach-license REST API. You will need the service_name for detaching the license back to the license bucket using Detach License REST API as below:

DELETE /api/v3/detach_lic/bucket/{BUCKET NAME} with following JSON

{

  "service_name" : "{ServiceName}"

}

For example,

curl -X DELETE -uadmin:password

 http://mill.jfrog.team:12160/api/v3/detach_lic/buckets/edge

 -H 'Content-Type: application/json'

 -d '{

  "service_name" : "my-edge-in-kansas"

}'

b2. which Artifactory the license was manually deployed to since the license file is used only once per active node. Use of the same license in multiple Artifactory violates license usage agreement.

c. The Json that is needed for updating Artifactory licenses uses licenseKey (notice that K is uppercase) as the key, which is different than what the Mission Control REST API provides as the key (license_key). Thus, you may use sed command to replace this. For example,

curl -X POST -uadmin:password http://mill.jfrog.team:12160/api/v3/attach_lic/buckets/999748414 -H 'Content-Type: application/json' -H 'cache-control: no-cache' -d '{

  "service_name" : "EdgeKansasCity",

  "deploy" : false

}' > license.json && sed -i -e 's/license_key/licenseKey/g' license.json

 

4. Use the license.json to provision the license to an Artifactory node. For example, 

curl -XPOST http://mill.jfrog.team:37654/artifactory/api/system/licenses -d@license.json -H "Content-Type: application/json" -uadmin:password

Below is a list of REST APIs that can be used for managing Artifactory licenses :