10Duke Scale C++ Client
Loading...
Searching...
No Matches
Using License Key for Licensing Operations

For overview of using License Key to authenticate requests, see following sections in 10 Duke Scale Documentation:

One way to authenticate device or user is to use license key, which might be embedded to a device or prompted from the user. Following licensing operations can be executed with the license key without having to do login:

Note that you don't need to provide the license key to heartbeat or release: The client remembers that the lease was checked out with license key and will automatically fill-in the license key.

If you only need the above operations, you can use tenduke::se::TendukeClient: This service works with license keys only. To create instance of the service, use factory function tenduke::se::createTendukeClientForLicenseKeyUsage(const std::string &,const tenduke::se::BackendConfiguration &,const tenduke::se::ClientProperties &,const std::string &initialStateAsJson,const ::tenduke::ServiceConfiguration &).

See also client concepts.

Examples

Following examples demonstrate, how to perform typical operations with license key.

Create the client:

auto tendukeClient = ::tenduke::se::createTendukeClientForLicenseKeyUsage(
"licensekey-demo/0.0.1-alpha-1",
::tenduke::se::BackendConfiguration(API_BASE_URL), // you can find the API url from 10Duke Scale console
tenduke::se::ClientPropertiesBuilder()
.hwId("simulated-hardware-id")
.version("0.0.1-alpha-1")
.build()
);

Checkout licenses:

std::string licenseKey = ...; // License key
auto checkoutResponse = tendukeClient->licensing->checkoutLicensesWithKey(licenseKey)
.version("1.0.0") // Set default version to check out, this applies to all following licenses,
// unless overridden at license level. Version is optional.
.seat("sample-product") // Check out one seat of "sample-product" with default version
.execute();
// Check for failures:
if (checkoutResponse.hasErrors) {
// handle errors
}

Heartbeart the lease (note how you don't need to provide the license key)

auto heartbeatResponse = tendukeClient->licensing->heartbeatLicenses()
.leases(checkoutResponse.leases)
.execute();
// Check for failures:
if (heartbearResponse.hasErrors) {
// handle errors
}

NOTE: Heartbeat generates new ids for the leases.

To release the licenses after heartbeat (note how you don't need to provide the license key):

auto releaseResponse = tendukeClient->licensing->releaseLicenses()
.leases(heartbeatResponse.leases)
.execute();

The licensing client has a memory cache, which holds leases of checked out licenses and manages the leases automatically after heartbeat or release request. To list all leases currently in cache:

auto allLeases = tendukeClient->leases->getAllLeases();

The client allows you to only operate (heartbeat or release) on leases, which are present in the cache. If you want to release all checked out licenses, you can do:

auto releaseResponse = tendukeClient->licenses->releaseLicenses()
.leases(tendukeClient->leases->getAllLeases()
.execute();

For all available services, see tenduke::se::TendukeClient.