use of com.epam.pipeline.entity.region.AwsRegion in project cloud-pipeline by epam.
the class S3StorageProviderTest method setUp.
@Before
public void setUp() {
when(bucket.getName()).thenReturn(bucketName);
when(amazonClient.createBucket(any(CreateBucketRequest.class))).thenReturn(bucket);
when(s3Helper.getDefaultS3Client()).thenReturn(amazonClient);
AwsRegion region = new AwsRegion();
region.setId(REGION_ID);
region.setAwsRegionName("us-east-1");
region.setCorsRules("[" + " {" + " \"AllowedOrigins\": [\"string\"]," + " \"AllowedMethods\": [\"PUT\", \"GET\"]," + " \"AllowedHeaders\": [\"string\"]," + " \"MaxAgeSeconds\": 3000," + " \"ExposeHeaders\": [\"string\"]" + " }" + "]");
when(awsRegionManager.getAwsRegion(any())).thenReturn(region);
doReturn(s3Helper).when(s3StorageProvider).getS3Helper(any());
}
use of com.epam.pipeline.entity.region.AwsRegion in project cloud-pipeline by epam.
the class DataStorageManager method generateTemporaryCredentials.
public AbstractTemporaryCredentials generateTemporaryCredentials(List<DataStorageAction> actions) {
AbstractDataStorage dataStorage = ListUtils.emptyIfNull(actions).stream().findFirst().map(action -> load(action.getId())).orElseThrow(() -> new IllegalArgumentException("Actions are not provided"));
Assert.isTrue(dataStorage instanceof S3bucketDataStorage, "Temporary credentials are supported only for S3 Buckets.");
S3bucketDataStorage bucket = (S3bucketDataStorage) dataStorage;
AwsRegion awsRegion = awsRegionManager.getAwsRegion(bucket);
actions.forEach(action -> {
AbstractDataStorage loaded = action.getId().equals(dataStorage.getId()) ? dataStorage : load(action.getId());
Assert.isTrue(loaded instanceof S3bucketDataStorage, "Temporary credentials are supported only for S3 Buckets.");
action.setBucketName(loaded.getPath());
Long regionId = ((S3bucketDataStorage) loaded).getRegionId();
Assert.isTrue(Objects.equals(regionId, bucket.getRegionId()), "Actions shall be requested for buckets from the same region");
});
return dataStorageFactory.temporaryCredentials(bucket.getType()).withRole(preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_TEMP_CREDENTIALS_ROLE)).withDurationSeconds(preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_TEMP_CREDENTIALS_DURATION)).withKmsArn(awsRegion.getKmsKeyArn()).withRegionId(awsRegion.getAwsRegionName()).generate(actions);
}
use of com.epam.pipeline.entity.region.AwsRegion in project cloud-pipeline by epam.
the class S3StorageProvider method checkStorage.
@Override
public boolean checkStorage(S3bucketDataStorage dataStorage) {
if (dataStorage.getRegionId() == null) {
AwsRegion awsRegion = awsRegionManager.getAwsRegion(dataStorage);
dataStorage.setRegionId(awsRegion.getId());
}
return getS3Helper(dataStorage).checkBucket(dataStorage.getPath());
}
use of com.epam.pipeline.entity.region.AwsRegion in project cloud-pipeline by epam.
the class PipelineRunManagerTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
notScannedTool = new Tool();
notScannedTool.setId(1L);
notScannedTool.setImage(TEST_IMAGE);
notScannedTool.setDefaultCommand("sleep");
configuration = new PipelineConfiguration();
configuration.setDockerImage(TEST_IMAGE);
configuration.setInstanceDisk("1");
configuration.setIsSpot(true);
price = new InstancePrice(configuration.getInstanceType(), Integer.valueOf(configuration.getInstanceDisk()), PRICE_PER_HOUR);
when(toolManager.loadByNameOrId(TEST_IMAGE)).thenReturn(notScannedTool);
when(instanceOfferManager.isInstanceAllowed(anyString())).thenReturn(true);
when(instanceOfferManager.isToolInstanceAllowed(anyString(), any())).thenReturn(true);
when(instanceOfferManager.isPriceTypeAllowed(anyString(), any())).thenReturn(true);
when(instanceOfferManager.getAllInstanceTypesObservable()).thenReturn(BehaviorSubject.create());
when(instanceOfferManager.getInstanceEstimatedPrice(anyString(), anyInt(), anyBoolean(), anyString())).thenReturn(price);
when(pipelineLauncher.launch(any(PipelineRun.class), any(), any(), anyString(), anyString())).thenReturn("sleep");
when(toolManager.loadToolVersionScan(notScannedTool.getId(), null)).thenReturn(Optional.empty());
when(toolVersionManager.loadToolVersion(anyLong(), anyString())).thenReturn(ToolVersion.builder().size(1L).build());
doReturn(configuration).when(pipelineConfigurationManager).getPipelineConfiguration(any());
doReturn(configuration).when(pipelineConfigurationManager).getPipelineConfiguration(any(), any());
AwsRegion region = new AwsRegion();
region.setAwsRegionName("us-east-1");
doReturn(region).when(awsRegionManager).loadDefaultRegion();
doNothing().when(entityManager).setManagers(any());
doNothing().when(resourceMonitoringManager).monitorResourceUsage();
}
use of com.epam.pipeline.entity.region.AwsRegion in project cloud-pipeline by epam.
the class AwsRegionManagerTest method createShouldSetCorsRulesToDefaultValueIfMissing.
@Test
public void createShouldSetCorsRulesToDefaultValueIfMissing() {
final String corsRulesAsString = "[{" + "\"id\":\"id1\"," + "\"allowedOrigins\":[\"origin1\",\"origin2\"]," + "\"maxAgeSeconds\":0" + "},{" + "\"id\":\"id2\"," + "\"maxAgeSeconds\":0," + "\"allowedHeaders\":[\"header1\"]" + "}]";
Preference corsPolicy = new Preference();
corsPolicy.setValue(corsRulesAsString);
doReturn(Optional.of(corsPolicy)).when(preferenceManager).load(eq(SystemPreferences.DATA_STORAGE_CORS_POLICY.getKey()));
final AwsRegionVO regionVO = getAwsRegionVoBuilder().policy(EMPTY_POLICY).kmsKeyId(KMS_KEY_ID).kmsKeyArn(KMS_KEY_ARN).awsRegionName(VALID_REGION_ID).isDefault(false).build();
awsRegionManager.create(regionVO);
final ArgumentCaptor<AwsRegion> regionCaptor = ArgumentCaptor.forClass(AwsRegion.class);
verify(awsRegionDao).create(regionCaptor.capture());
final AwsRegion actualRegion = regionCaptor.getValue();
assertThat(actualRegion.getCorsRules(), is(corsRulesAsString));
}
Aggregations