use of com.amazonaws.services.licensemanager.model.CheckoutLicenseRequest in project aws-appflow-custom-connector-java by awslabs.
the class EntitlementUtil method checkEntitlement.
/**
* Checks if the Connector subscribed from Marketplace has entitlement to use or not for an AWS account.
*
* @param productSKU - ProductSKU generated by marketplace at the time of connector registration.
* @return - True if the entitlement is successful otherwise false.
*/
public boolean checkEntitlement(final String productSKU) {
final CheckoutLicenseRequest request = new CheckoutLicenseRequest().withCheckoutType(CheckoutType.PROVISIONAL).withProductSKU(productSKU).withKeyFingerprint(KEY_FINGERPRINT).withEntitlements(Collections.singleton(getMarketplaceUsageEntitlement())).withClientToken(UUID.randomUUID().toString());
try {
final CheckoutLicenseResult result = client.checkoutLicense(request);
final List<String> entitlements = result.getEntitlementsAllowed().stream().map(EntitlementData::getName).collect(Collectors.toList());
if (entitlements.contains(AWS_MARKETPLACE_USAGE_ENTITLEMENT_NAME)) {
return true;
}
} catch (SdkBaseException ex) {
LOGGER.error("Entitlement check failed with exception" + ExceptionUtils.getStackTrace(ex));
}
return false;
}
Aggregations