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;
}
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();
}
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();
}
Aggregations