How to call ResolveCustomer and GetEntitlements from aws-marketplace?

假装没事ソ 提交于 2020-03-22 09:13:50

问题


I find java sdk but I can't find example of usage.

I need to call ResolveCustomer (produces a token for the product and user) and GetEntitlements (gives a list of rights for the product and the user).

Has anyone used this service?


回答1:


Here is full example to get information about client from aws marketplace. You should to use this librarys:

 <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-marketplacemeteringservice</artifactId>
            <version>1.11.192</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-marketplaceentitlement</artifactId>
            <version>1.11.194</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>

Java code:

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.marketplaceentitlement.AWSMarketplaceEntitlementClient;
import com.amazonaws.services.marketplaceentitlement.AWSMarketplaceEntitlementClientBuilder;
import com.amazonaws.services.marketplaceentitlement.model.GetEntitlementsRequest;
import com.amazonaws.services.marketplaceentitlement.model.GetEntitlementsResult;
import com.amazonaws.services.marketplacemetering.*;
import com.amazonaws.services.marketplacemetering.model.*;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class R
{
    @Test
    public void test() throws Exception
    {
        AWSCredentialsProvider provider = new AWSCredentialsProvider()
        {
            public AWSCredentials getCredentials()
            {
                return new AWSCredentials()
                {
                    public String getAWSAccessKeyId()
                    {
                        return "<YOUR ACCESS KEY>";
                    }

                    public String getAWSSecretKey()
                    {
                        return "YOUR SECRET KEY";
                    }
                };
            }

            public void refresh()
            {

            }
        };


        AWSMarketplaceMeteringClientBuilder b = AWSMarketplaceMeteringClient.builder();
        b.setRegion("us-east-1");  // YOUR AWS REGION
        b.setCredentials(provider);
        AWSMarketplaceMetering c = b.build();

        ResolveCustomerRequest r = new ResolveCustomerRequest();
        r.setRegistrationToken(<YOUR "x-amzn-marketplace-token">); // it comes to your application in the url parameter when the user clicks the buy button in the aws market
        final ResolveCustomerResult response = c.resolveCustomer(r);


        AWSMarketplaceEntitlementClientBuilder entitlementClientBuilder = AWSMarketplaceEntitlementClient.builder();
        entitlementClientBuilder.setRegion("us-east-1");
        entitlementClientBuilder.setCredentials(provider);

        GetEntitlementsRequest getEntitlementsRequest = new GetEntitlementsRequest();
        getEntitlementsRequest.setProductCode(response.getProductCode());

        getEntitlementsRequest.setFilter(new HashMap<String, List<String>>()
        {{
            put("CUSTOMER_IDENTIFIER", new ArrayList<String>()
            {{
                add(response.getCustomerIdentifier());
            }});
        }});
        GetEntitlementsResult entitlementsResult = entitlementClientBuilder.build().getEntitlements(getEntitlementsRequest);
        entitlementsResult = null;
    }
}

Also your should add policy in your aws account:



来源:https://stackoverflow.com/questions/45975754/how-to-call-resolvecustomer-and-getentitlements-from-aws-marketplace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!