Search in sources :

Example 1 with FunctionComputeClient

use of com.aliyuncs.fc.client.FunctionComputeClient in project fc-java-sdk by aliyun.

the class FunctionComputeClientTest method testCreateServiceStsTokenNoPassRole.

@Test
public void testCreateServiceStsTokenNoPassRole() throws com.aliyuncs.exceptions.ClientException {
    // Use a policy that does not have ram:PassRole, this policy will intersect with the role policy
    // Access denied is expected if using STS without PassRole allowed
    // Policy intersection doc: https://help.aliyun.com/document_detail/31935.html
    String policy = "{\"Version\": \"1\",\"Statement\": [{\"Effect\": \"Allow\",\"Action\": [\"fc:*\"],\"Resource\": [\"*\"]}]}";
    Credentials creds = getAssumeRoleCredentials(policy);
    client = new FunctionComputeClient(new Config(REGION, ACCOUNT_ID, creds.getAccessKeyId(), creds.getAccessKeySecret(), creds.getSecurityToken(), false));
    try {
        createService(SERVICE_NAME);
        fail("ClientException is expected");
    } catch (ClientException e) {
        assertTrue(e.getErrorMessage().contains("the caller is not authorized to perform 'ram:PassRole'"));
    }
}
Also used : Config(com.aliyuncs.fc.config.Config) OSSTriggerConfig(com.aliyuncs.fc.model.OSSTriggerConfig) ClientException(com.aliyuncs.fc.exceptions.ClientException) FunctionComputeClient(com.aliyuncs.fc.client.FunctionComputeClient) Credentials(com.aliyuncs.sts.model.v20150401.AssumeRoleResponse.Credentials) Test(org.junit.Test)

Example 2 with FunctionComputeClient

use of com.aliyuncs.fc.client.FunctionComputeClient in project fc-java-sdk by aliyun.

the class FunctionComputeClientTest method setup.

@Before
public void setup() {
    // Create or clean up everything under the test service
    client = new FunctionComputeClient(REGION, ACCOUNT_ID, ACCESS_KEY, SECRET_KEY);
    GetServiceRequest getSReq = new GetServiceRequest(SERVICE_NAME);
    try {
        client.getService(getSReq);
        ListFunctionsRequest listFReq = new ListFunctionsRequest(SERVICE_NAME);
        ListFunctionsResponse listFResp = client.listFunctions(listFReq);
        cleanUpFunctions(SERVICE_NAME, listFResp.getFunctions());
        cleanupService(SERVICE_NAME);
    } catch (ClientException e) {
        if (!ErrorCodes.SERVICE_NOT_FOUND.equals(e.getErrorCode())) {
            throw e;
        }
    }
}
Also used : ListFunctionsResponse(com.aliyuncs.fc.response.ListFunctionsResponse) GetServiceRequest(com.aliyuncs.fc.request.GetServiceRequest) ListFunctionsRequest(com.aliyuncs.fc.request.ListFunctionsRequest) ClientException(com.aliyuncs.fc.exceptions.ClientException) FunctionComputeClient(com.aliyuncs.fc.client.FunctionComputeClient) Before(org.junit.Before)

Aggregations

FunctionComputeClient (com.aliyuncs.fc.client.FunctionComputeClient)2 ClientException (com.aliyuncs.fc.exceptions.ClientException)2 Config (com.aliyuncs.fc.config.Config)1 OSSTriggerConfig (com.aliyuncs.fc.model.OSSTriggerConfig)1 GetServiceRequest (com.aliyuncs.fc.request.GetServiceRequest)1 ListFunctionsRequest (com.aliyuncs.fc.request.ListFunctionsRequest)1 ListFunctionsResponse (com.aliyuncs.fc.response.ListFunctionsResponse)1 Credentials (com.aliyuncs.sts.model.v20150401.AssumeRoleResponse.Credentials)1 Before (org.junit.Before)1 Test (org.junit.Test)1