Search in sources :

Example 6 with S3bucketDataStorage

use of com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage 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);
}
Also used : Arrays(java.util.Arrays) S3Constants(com.epam.pipeline.manager.datastorage.providers.aws.s3.S3Constants) LoggerFactory(org.slf4j.LoggerFactory) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) StoragePolicy(com.epam.pipeline.entity.datastorage.StoragePolicy) StringUtils(org.apache.commons.lang3.StringUtils) DataStorageVO(com.epam.pipeline.controller.vo.DataStorageVO) Folder(com.epam.pipeline.entity.pipeline.Folder) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) MessageHelper(com.epam.pipeline.common.MessageHelper) ListUtils(org.apache.commons.collections4.ListUtils) Map(java.util.Map) DataStorageItemContent(com.epam.pipeline.entity.datastorage.DataStorageItemContent) DataStorageListing(com.epam.pipeline.entity.datastorage.DataStorageListing) AntPathMatcher(org.springframework.util.AntPathMatcher) SecuredEntityManager(com.epam.pipeline.manager.security.SecuredEntityManager) DataStorageItemType(com.epam.pipeline.entity.datastorage.DataStorageItemType) DataStorageLink(com.epam.pipeline.entity.pipeline.run.parameter.DataStorageLink) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) RoleManager(com.epam.pipeline.manager.user.RoleManager) DataStorageDownloadFileUrl(com.epam.pipeline.entity.datastorage.DataStorageDownloadFileUrl) Collection(java.util.Collection) Set(java.util.Set) StorageContainer(com.epam.pipeline.entity.user.StorageContainer) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) Collectors(java.util.stream.Collectors) AbstractDataStorageFactory(com.epam.pipeline.entity.datastorage.AbstractDataStorageFactory) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) Objects(java.util.Objects) List(java.util.List) UserManager(com.epam.pipeline.manager.user.UserManager) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) AclSync(com.epam.pipeline.manager.security.acl.AclSync) Optional(java.util.Optional) EntityVO(com.epam.pipeline.controller.vo.EntityVO) AbstractTemporaryCredentials(com.epam.pipeline.entity.datastorage.AbstractTemporaryCredentials) DataStorageDao(com.epam.pipeline.dao.datastorage.DataStorageDao) MessageConstants(com.epam.pipeline.common.MessageConstants) DataStorageAction(com.epam.pipeline.entity.datastorage.DataStorageAction) HashMap(java.util.HashMap) Function(java.util.function.Function) DataStorageFolder(com.epam.pipeline.entity.datastorage.DataStorageFolder) ArrayList(java.util.ArrayList) MetadataManager(com.epam.pipeline.manager.metadata.MetadataManager) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) BaseEntity(com.epam.pipeline.entity.BaseEntity) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Logger(org.slf4j.Logger) FolderManager(com.epam.pipeline.manager.pipeline.FolderManager) MapUtils(org.apache.commons.collections.MapUtils) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageType(com.epam.pipeline.entity.datastorage.DataStorageType) AbstractDataStorageItem(com.epam.pipeline.entity.datastorage.AbstractDataStorageItem) Paths(java.nio.file.Paths) NumberUtils(org.apache.commons.lang3.math.NumberUtils) AclClass(com.epam.pipeline.entity.security.acl.AclClass) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) AuthManager(com.epam.pipeline.manager.security.AuthManager) UpdateDataStorageItemVO(com.epam.pipeline.controller.vo.data.storage.UpdateDataStorageItemVO) Collections(java.util.Collections) AwsRegionManager(com.epam.pipeline.manager.region.AwsRegionManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) InputStream(java.io.InputStream) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)

Example 7 with S3bucketDataStorage

use of com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage in project cloud-pipeline by epam.

the class FolderManagerGetProjectTest method getProjectShouldWorkWithDataStorageAsInputEntity.

@Test
public void getProjectShouldWorkWithDataStorageAsInputEntity() {
    S3bucketDataStorage dataStorage = new S3bucketDataStorage(1L, "dataStorage", "path_to_bucket");
    dataStorage.setParent(folder3);
    Mockito.when(entityManager.load(Matchers.any(AclClass.class), Matchers.any(Long.class))).thenReturn(dataStorage);
    Folder actualFolder = folderManager.getProject(dataStorage.getId(), AclClass.DATA_STORAGE);
    assertFolders(folder2, actualFolder);
}
Also used : S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) Folder(com.epam.pipeline.entity.pipeline.Folder) AclClass(com.epam.pipeline.entity.security.acl.AclClass) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test)

Example 8 with S3bucketDataStorage

use of com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage in project cloud-pipeline by epam.

the class PipelineConfigurationManagerTest method setUp.

@Before
public void setUp() throws Exception {
    registry = new DockerRegistry();
    registry.setPath(TEST_REPO);
    registry.setOwner(TEST_USER);
    dockerRegistryDao.createDockerRegistry(registry);
    library = new ToolGroup();
    library.setName(TOOL_GROUP_NAME);
    library.setRegistryId(registry.getId());
    library.setOwner(TEST_USER);
    toolGroupDao.createToolGroup(library);
    tool = new Tool();
    tool.setImage(TEST_IMAGE);
    tool.setRam(TEST_RAM);
    tool.setCpu(TEST_CPU);
    tool.setOwner(TEST_USER);
    tool.setRegistryId(registry.getId());
    tool.setToolGroupId(library.getId());
    toolDao.createTool(tool);
    // Data storages of user 1
    NFSDataStorage dataStorage = new NFSDataStorage(dataStorageDao.createDataStorageId(), "testNFS", "test/path1");
    dataStorage.setMountOptions("testMountOptions1");
    dataStorage.setMountPoint("/some/other/path");
    dataStorage.setOwner(TEST_OWNER1);
    dataStorageDao.createDataStorage(dataStorage);
    dataStorages.add(dataStorage);
    S3bucketDataStorage bucketDataStorage = new S3bucketDataStorage(dataStorageDao.createDataStorageId(), "testBucket", "test/path2");
    bucketDataStorage.setOwner(TEST_OWNER1);
    dataStorageDao.createDataStorage(bucketDataStorage);
    dataStorages.add(bucketDataStorage);
    // Data storages of user 2
    dataStorage = new NFSDataStorage(dataStorageDao.createDataStorageId(), "testNFS2", "test/path3");
    dataStorage.setMountOptions("testMountOptions2");
    dataStorage.setOwner(TEST_OWNER2);
    dataStorageDao.createDataStorage(dataStorage);
    dataStorages.add(dataStorage);
    bucketDataStorage = new S3bucketDataStorage(dataStorageDao.createDataStorageId(), "testBucket2", "test/path4");
    bucketDataStorage.setOwner(TEST_OWNER2);
    dataStorageDao.createDataStorage(bucketDataStorage);
    dataStorages.add(bucketDataStorage);
    dataStorages.forEach(ds -> aclTestDao.createAclForObject(ds));
    aclTestDao.grantPermissions(dataStorage, TEST_OWNER1, Collections.singletonList((AclPermission) AclPermission.READ));
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) AclPermission(com.epam.pipeline.security.acl.AclPermission) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) NFSDataStorage(com.epam.pipeline.entity.datastorage.nfs.NFSDataStorage) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) Tool(com.epam.pipeline.entity.pipeline.Tool) Before(org.junit.Before)

Example 9 with S3bucketDataStorage

use of com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage in project cloud-pipeline by epam.

the class AbstractDataStorageMapper method fillS3Fields.

@AfterMapping
public void fillS3Fields(AbstractDataStorage dataStorage, @MappingTarget DataStorageVO dataStorageVO) {
    if (dataStorage instanceof S3bucketDataStorage) {
        S3bucketDataStorage s3bucketDataStorage = (S3bucketDataStorage) dataStorage;
        dataStorageVO.setAllowedCidrs(s3bucketDataStorage.getAllowedCidrs());
        dataStorageVO.setRegionId(s3bucketDataStorage.getRegionId());
    }
}
Also used : S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) AfterMapping(org.mapstruct.AfterMapping)

Example 10 with S3bucketDataStorage

use of com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage in project cloud-pipeline by epam.

the class DataStorageDaoTest method setUp.

@Before
public void setUp() {
    testFolder = buildFolder(null);
    awsRegion = new AwsRegion();
    awsRegion.setName("Default");
    awsRegion.setDefault(true);
    awsRegion.setAwsRegionName("us-east-1");
    awsRegionDao.create(awsRegion);
    s3Bucket = new S3bucketDataStorage(null, TEST_STORAGE_NAME, TEST_STORAGE_PATH);
    s3Bucket.setDescription("testDescription");
    s3Bucket.setParentFolderId(testFolder.getId());
    s3Bucket.setRegionId(awsRegion.getId());
    s3Bucket.setOwner(TEST_OWNER);
    s3Bucket.setMountPoint("testMountPoint");
    s3Bucket.setMountOptions("testMountOptions");
    s3Bucket.setShared(true);
    s3Bucket.setAllowedCidrs(Arrays.asList("test1", "test2"));
    policy = new StoragePolicy();
    policy.setBackupDuration(BACKUP_DURATION);
    policy.setLongTermStorageDuration(LTS_DURATION);
    policy.setShortTermStorageDuration(STS_DURATION);
    policy.setVersioningEnabled(true);
    s3Bucket.setStoragePolicy(policy);
    nfsStorage = new NFSDataStorage(null, "NFS_STORAGE", "nfs_path");
    nfsStorage.setOwner(TEST_OWNER);
    nfsStorage.setDescription("NFS");
    nfsStorage.setParentFolderId(testFolder.getId());
    nfsStorage.setMountOptions("-s");
    nfsStorage.setMountPoint("nfs");
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) NFSDataStorage(com.epam.pipeline.entity.datastorage.nfs.NFSDataStorage) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) StoragePolicy(com.epam.pipeline.entity.datastorage.StoragePolicy) Before(org.junit.Before)

Aggregations

S3bucketDataStorage (com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)14 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)7 Test (org.junit.Test)7 Folder (com.epam.pipeline.entity.pipeline.Folder)3 SecuredEntityManager (com.epam.pipeline.manager.security.SecuredEntityManager)3 Transactional (org.springframework.transaction.annotation.Transactional)3 StoragePolicy (com.epam.pipeline.entity.datastorage.StoragePolicy)2 NFSDataStorage (com.epam.pipeline.entity.datastorage.nfs.NFSDataStorage)2 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)2 AclClass (com.epam.pipeline.entity.security.acl.AclClass)2 MessageConstants (com.epam.pipeline.common.MessageConstants)1 MessageHelper (com.epam.pipeline.common.MessageHelper)1 DataStorageVO (com.epam.pipeline.controller.vo.DataStorageVO)1 EntityVO (com.epam.pipeline.controller.vo.EntityVO)1 UpdateDataStorageItemVO (com.epam.pipeline.controller.vo.data.storage.UpdateDataStorageItemVO)1 DataStorageDao (com.epam.pipeline.dao.datastorage.DataStorageDao)1 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)1 BaseEntity (com.epam.pipeline.entity.BaseEntity)1 RunConfiguration (com.epam.pipeline.entity.configuration.RunConfiguration)1 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)1