Search in sources :

Example 6 with ResourceException

use of com.yahoo.athenz.zts.ResourceException in project athenz by yahoo.

the class CloudStore method assumeAWSRole.

public AWSTemporaryCredentials assumeAWSRole(String account, String roleName, String principal) {
    if (!awsEnabled) {
        throw new ResourceException(ResourceException.INTERNAL_SERVER_ERROR, "AWS Support not enabled");
    }
    AssumeRoleRequest req = getAssumeRoleRequest(account, roleName, principal);
    AWSTemporaryCredentials tempCreds = null;
    try {
        AWSSecurityTokenServiceClient client = getTokenServiceClient();
        AssumeRoleResult res = client.assumeRole(req);
        Credentials awsCreds = res.getCredentials();
        tempCreds = new AWSTemporaryCredentials().setAccessKeyId(awsCreds.getAccessKeyId()).setSecretAccessKey(awsCreds.getSecretAccessKey()).setSessionToken(awsCreds.getSessionToken()).setExpiration(Timestamp.fromMillis(awsCreds.getExpiration().getTime()));
    } catch (Exception ex) {
        LOGGER.error("CloudStore: assumeAWSRole - unable to assume role: " + ex.getMessage());
        return null;
    }
    return tempCreds;
}
Also used : AssumeRoleRequest(com.amazonaws.services.securitytoken.model.AssumeRoleRequest) AWSSecurityTokenServiceClient(com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient) ResourceException(com.yahoo.athenz.zts.ResourceException) AssumeRoleResult(com.amazonaws.services.securitytoken.model.AssumeRoleResult) AWSTemporaryCredentials(com.yahoo.athenz.zts.AWSTemporaryCredentials) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) Credentials(com.amazonaws.services.securitytoken.model.Credentials) AWSTemporaryCredentials(com.yahoo.athenz.zts.AWSTemporaryCredentials) TimeoutException(java.util.concurrent.TimeoutException) ResourceException(com.yahoo.athenz.zts.ResourceException) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with ResourceException

use of com.yahoo.athenz.zts.ResourceException in project athenz by yahoo.

the class JDBCCertRecordStoreConnectionTest method testSqlError.

@Test
public void testSqlError() throws SQLException {
    JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
    SQLException ex = new SQLException("sql-reason", "08S01", 9999);
    ResourceException rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
    assertEquals(ResourceException.INTERNAL_SERVER_ERROR, rEx.getCode());
    ex = new SQLException("sql-reason", "40001", 9999);
    rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
    assertEquals(ResourceException.INTERNAL_SERVER_ERROR, rEx.getCode());
    SQLTimeoutException tex = new SQLTimeoutException();
    rEx = (ResourceException) jdbcConn.sqlError(tex, "sqlError");
    assertEquals(ResourceException.SERVICE_UNAVAILABLE, rEx.getCode());
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) SQLTimeoutException(java.sql.SQLTimeoutException) ResourceException(com.yahoo.athenz.zts.ResourceException) Test(org.testng.annotations.Test)

Example 8 with ResourceException

use of com.yahoo.athenz.zts.ResourceException in project athenz by yahoo.

the class CloudStoreTest method testAssumeAWSRoleAWSNotEnabled.

@Test
public void testAssumeAWSRoleAWSNotEnabled() {
    CloudStore cloudStore = new CloudStore(null);
    try {
        cloudStore.assumeAWSRole("account", "sycner", "athenz.syncer");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 500);
    }
    cloudStore.close();
}
Also used : CloudStore(com.yahoo.athenz.zts.store.CloudStore) ResourceException(com.yahoo.athenz.zts.ResourceException) Test(org.testng.annotations.Test)

Aggregations

ResourceException (com.yahoo.athenz.zts.ResourceException)8 Test (org.testng.annotations.Test)6 CloudStore (com.yahoo.athenz.zts.store.CloudStore)5 SQLException (java.sql.SQLException)2 HttpClient (org.eclipse.jetty.client.HttpClient)2 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)2 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 AWSSecurityTokenServiceClient (com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient)1 AssumeRoleRequest (com.amazonaws.services.securitytoken.model.AssumeRoleRequest)1 AssumeRoleResult (com.amazonaws.services.securitytoken.model.AssumeRoleResult)1 Credentials (com.amazonaws.services.securitytoken.model.Credentials)1 AWSTemporaryCredentials (com.yahoo.athenz.zts.AWSTemporaryCredentials)1 SQLTimeoutException (java.sql.SQLTimeoutException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1