Search in sources :

Example 1 with CheckoutLicenseRequest

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;
}
Also used : CheckoutLicenseRequest(com.amazonaws.services.licensemanager.model.CheckoutLicenseRequest) SdkBaseException(com.amazonaws.SdkBaseException) CheckoutLicenseResult(com.amazonaws.services.licensemanager.model.CheckoutLicenseResult)

Aggregations

SdkBaseException (com.amazonaws.SdkBaseException)1 CheckoutLicenseRequest (com.amazonaws.services.licensemanager.model.CheckoutLicenseRequest)1 CheckoutLicenseResult (com.amazonaws.services.licensemanager.model.CheckoutLicenseResult)1