use of com.amazonaws.services.securitytoken.model.AssumeRoleResult in project Gatekeeper by FINRAOS.
the class AwsSessionServiceTests method before.
@Before
public void before() {
awsEnvironment = new AWSEnvironment("Dev", "us-west-2");
Mockito.when(gatekeeperAwsProperties.getSessionTimeout()).thenReturn(900000);
Mockito.when(gatekeeperAwsProperties.getSessionTimeoutPad()).thenReturn(60000);
Mockito.when(gatekeeperAwsProperties.getProxyHost()).thenReturn("testproxy");
Mockito.when(gatekeeperAwsProperties.getProxyPort()).thenReturn("100");
List<Region> regions = new ArrayList<>();
Region testRegion1 = new Region();
Region testRegion2 = new Region();
testRegion1.setName("us-west-2");
testRegion2.setName("us-east-1");
regions.add(testRegion1);
regions.add(testRegion2);
Account fakeAccount = new Account();
fakeAccount.setAccountId(123L);
fakeAccount.setAlias("hello");
fakeAccount.setRegions(regions);
fakeAccount.setSdlc("Test");
fakeAccount.setName("Test Account");
AssumeRoleResult fakeRoleResult = new AssumeRoleResult();
// ( ͡° ͜ʖ ͡°)
Credentials fakeFreshCredentials = new Credentials();
fakeFreshCredentials.setAccessKeyId("testing");
fakeFreshCredentials.setSecretAccessKey("s3cr3t");
fakeFreshCredentials.setSessionToken("s35510nt0k3n");
fakeRoleResult.setCredentials(fakeFreshCredentials);
when(accountInformationService.getAccountByAlias("Dev")).thenReturn(fakeAccount);
when(awsSecurityTokenServiceClient.assumeRole(any())).thenReturn(fakeRoleResult);
when(awsSessionFactory.createEc2Session(any())).thenReturn(amazonEC2Client);
when(awsSessionFactory.createSsmSession(any())).thenReturn(awsSimpleSystemsManagementClient);
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleResult in project ice by Netflix.
the class AwsUtils method getAssumedCredentials.
/**
* Get assumes IAM credentials.
* @param accountId
* @param assumeRole
* @return assumes IAM credentials
*/
public static Credentials getAssumedCredentials(String accountId, String assumeRole, String externalId) {
AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withRoleArn("arn:aws:iam::" + accountId + ":role/" + assumeRole).withRoleSessionName(assumeRole.substring(0, Math.min(assumeRole.length(), 32)));
if (!StringUtils.isEmpty(externalId))
assumeRoleRequest.setExternalId(externalId);
AssumeRoleResult roleResult = securityClient.assumeRole(assumeRoleRequest);
return roleResult.getCredentials();
}
Aggregations