Search in sources :

Example 6 with EntityPermissionVO

use of com.epam.pipeline.vo.EntityPermissionVO in project cloud-pipeline by epam.

the class S3Synchronizer method createIndexAndDocuments.

@SuppressWarnings("PMD.AvoidCatchingGenericException")
void createIndexAndDocuments(final AbstractDataStorage dataStorage) {
    EntityPermissionVO entityPermission = cloudPipelineAPIClient.loadPermissionsForEntity(dataStorage.getId(), dataStorage.getAclClass());
    PermissionsContainer permissionsContainer = new PermissionsContainer();
    if (entityPermission != null) {
        permissionsContainer.add(entityPermission.getPermissions(), dataStorage.getOwner());
    }
    String alias = indexPrefix + indexName + String.format("-%d", dataStorage.getId());
    String indexName = generateRandomString(5).toLowerCase() + "-" + alias;
    try {
        String currentIndexName = elasticsearchServiceClient.getIndexNameByAlias(alias);
        elasticIndexService.createIndexIfNotExist(indexName, indexSettingsPath);
        DataStorageAction action = new DataStorageAction();
        action.setBucketName(dataStorage.getPath());
        action.setId(dataStorage.getId());
        action.setWrite(false);
        action.setRead(true);
        AbstractTemporaryCredentials credentials = cloudPipelineAPIClient.generateTemporaryCredentials(Collections.singletonList(action));
        BulkRequestCreator bulkRequestCreator = requests -> elasticsearchServiceClient.sendRequests(indexName, requests);
        S3Helper s3Helper = new S3Helper(enableTags, credentials, bulkRequestCreator, dataStorage, indexName, bulkInsertSize, permissionsContainer);
        s3Helper.addItems();
        elasticsearchServiceClient.createIndexAlias(indexName, alias);
        if (StringUtils.hasText(currentIndexName)) {
            elasticsearchServiceClient.deleteIndex(currentIndexName);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        if (elasticsearchServiceClient.isIndexExists(indexName)) {
            elasticsearchServiceClient.deleteIndex(indexName);
        }
    }
}
Also used : AbstractTemporaryCredentials(com.epam.pipeline.entity.datastorage.AbstractTemporaryCredentials) DataStorageAction(com.epam.pipeline.entity.datastorage.DataStorageAction) LocalDateTime(java.time.LocalDateTime) ElasticsearchSynchronizer(com.epam.pipeline.elasticsearchagent.service.ElasticsearchSynchronizer) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageType(com.epam.pipeline.entity.datastorage.DataStorageType) ElasticsearchServiceClient(com.epam.pipeline.elasticsearchagent.service.ElasticsearchServiceClient) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) S3Helper(com.epam.pipeline.elasticsearchagent.utils.S3Helper) Value(org.springframework.beans.factory.annotation.Value) BulkRequestCreator(com.epam.pipeline.elasticsearchagent.service.BulkRequestCreator) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Service(org.springframework.stereotype.Service) PermissionsContainer(com.epam.pipeline.elasticsearchagent.model.PermissionsContainer) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) Collections(java.util.Collections) EntityPermissionVO(com.epam.pipeline.vo.EntityPermissionVO) StringUtils(org.springframework.util.StringUtils) S3Helper(com.epam.pipeline.elasticsearchagent.utils.S3Helper) EntityPermissionVO(com.epam.pipeline.vo.EntityPermissionVO) DataStorageAction(com.epam.pipeline.entity.datastorage.DataStorageAction) PermissionsContainer(com.epam.pipeline.elasticsearchagent.model.PermissionsContainer) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) AbstractTemporaryCredentials(com.epam.pipeline.entity.datastorage.AbstractTemporaryCredentials) BulkRequestCreator(com.epam.pipeline.elasticsearchagent.service.BulkRequestCreator)

Example 7 with EntityPermissionVO

use of com.epam.pipeline.vo.EntityPermissionVO in project cloud-pipeline by epam.

the class ObjectCreationUtils method buildEntityPermissionVO.

public static EntityPermissionVO buildEntityPermissionVO(final String owner, final Set<String> allowedUsers, final Set<String> deniedUsers, final Set<String> allowedGroups, final Set<String> deniedGroups) {
    Set<AclPermissionEntry> permissions = new HashSet<>();
    allowedUsers.forEach(user -> permissions.add(getPermissionEntry(user, true, 1)));
    deniedUsers.forEach(user -> permissions.add(getPermissionEntry(user, true, 2)));
    allowedGroups.forEach(group -> permissions.add(getPermissionEntry(group, false, 1)));
    deniedGroups.forEach(group -> permissions.add(getPermissionEntry(group, false, 2)));
    EntityPermissionVO entityPermissionVO = new EntityPermissionVO();
    entityPermissionVO.setOwner(owner);
    entityPermissionVO.setPermissions(permissions);
    return entityPermissionVO;
}
Also used : EntityPermissionVO(com.epam.pipeline.vo.EntityPermissionVO) AclPermissionEntry(com.epam.pipeline.entity.security.acl.AclPermissionEntry) HashSet(java.util.HashSet)

Example 8 with EntityPermissionVO

use of com.epam.pipeline.vo.EntityPermissionVO in project cloud-pipeline by epam.

the class FolderLoaderTest method setup.

@BeforeEach
void setup() {
    EntityPermissionVO entityPermissionVO = buildEntityPermissionVO(USER_NAME, ALLOWED_USERS, DENIED_USERS, ALLOWED_GROUPS, DENIED_GROUPS);
    MetadataEntry metadataEntry = buildMetadataEntry(AclClass.FOLDER, 1L, TEST_KEY + " " + TEST_VALUE);
    when(apiClient.loadUserByName(anyString())).thenReturn(USER);
    when(apiClient.loadPermissionsForEntity(anyLong(), any())).thenReturn(entityPermissionVO);
    when(apiClient.loadMetadataEntry(any())).thenReturn(Collections.singletonList(metadataEntry));
}
Also used : ObjectCreationUtils.buildEntityPermissionVO(com.epam.pipeline.elasticsearchagent.ObjectCreationUtils.buildEntityPermissionVO) EntityPermissionVO(com.epam.pipeline.vo.EntityPermissionVO) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) ObjectCreationUtils.buildMetadataEntry(com.epam.pipeline.elasticsearchagent.ObjectCreationUtils.buildMetadataEntry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with EntityPermissionVO

use of com.epam.pipeline.vo.EntityPermissionVO in project cloud-pipeline by epam.

the class IssueLoaderTest method setup.

@BeforeEach
void setup() {
    EntityPermissionVO entityPermissionVO = buildEntityPermissionVO(USER_NAME, ALLOWED_USERS, DENIED_USERS, ALLOWED_GROUPS, DENIED_GROUPS);
    MetadataEntry metadataEntry = buildMetadataEntry(AclClass.TOOL, 1L, TEST_KEY + " " + TEST_VALUE);
    when(apiClient.loadUserByName(anyString())).thenReturn(USER);
    when(apiClient.loadPermissionsForEntity(anyLong(), any())).thenReturn(entityPermissionVO);
    when(apiClient.loadMetadataEntry(any())).thenReturn(Collections.singletonList(metadataEntry));
}
Also used : ObjectCreationUtils.buildEntityPermissionVO(com.epam.pipeline.elasticsearchagent.ObjectCreationUtils.buildEntityPermissionVO) EntityPermissionVO(com.epam.pipeline.vo.EntityPermissionVO) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) ObjectCreationUtils.buildMetadataEntry(com.epam.pipeline.elasticsearchagent.ObjectCreationUtils.buildMetadataEntry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with EntityPermissionVO

use of com.epam.pipeline.vo.EntityPermissionVO in project cloud-pipeline by epam.

the class MetadataEntityLoaderTest method setup.

@BeforeEach
void setup() {
    EntityPermissionVO entityPermissionVO = buildEntityPermissionVO(USER_NAME, ALLOWED_USERS, DENIED_USERS, ALLOWED_GROUPS, DENIED_GROUPS);
    MetadataEntry metadataEntry = buildMetadataEntry(AclClass.METADATA_ENTITY, 1L, TEST_KEY + " " + TEST_VALUE);
    when(apiClient.loadPermissionsForEntity(anyLong(), any())).thenReturn(entityPermissionVO);
    when(apiClient.loadMetadataEntry(any())).thenReturn(Collections.singletonList(metadataEntry));
}
Also used : ObjectCreationUtils.buildEntityPermissionVO(com.epam.pipeline.elasticsearchagent.ObjectCreationUtils.buildEntityPermissionVO) EntityPermissionVO(com.epam.pipeline.vo.EntityPermissionVO) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) ObjectCreationUtils.buildMetadataEntry(com.epam.pipeline.elasticsearchagent.ObjectCreationUtils.buildMetadataEntry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

EntityPermissionVO (com.epam.pipeline.vo.EntityPermissionVO)14 ObjectCreationUtils.buildEntityPermissionVO (com.epam.pipeline.elasticsearchagent.ObjectCreationUtils.buildEntityPermissionVO)10 BeforeEach (org.junit.jupiter.api.BeforeEach)10 ObjectCreationUtils.buildMetadataEntry (com.epam.pipeline.elasticsearchagent.ObjectCreationUtils.buildMetadataEntry)9 MetadataEntry (com.epam.pipeline.entity.metadata.MetadataEntry)9 PermissionsContainer (com.epam.pipeline.elasticsearchagent.model.PermissionsContainer)3 PasswordGenerator.generateRandomString (com.epam.pipeline.utils.PasswordGenerator.generateRandomString)2 BulkRequestCreator (com.epam.pipeline.elasticsearchagent.service.BulkRequestCreator)1 ElasticsearchServiceClient (com.epam.pipeline.elasticsearchagent.service.ElasticsearchServiceClient)1 ElasticsearchSynchronizer (com.epam.pipeline.elasticsearchagent.service.ElasticsearchSynchronizer)1 S3Helper (com.epam.pipeline.elasticsearchagent.utils.S3Helper)1 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)1 AbstractTemporaryCredentials (com.epam.pipeline.entity.datastorage.AbstractTemporaryCredentials)1 DataStorageAction (com.epam.pipeline.entity.datastorage.DataStorageAction)1 DataStorageType (com.epam.pipeline.entity.datastorage.DataStorageType)1 AclPermissionEntry (com.epam.pipeline.entity.security.acl.AclPermissionEntry)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 LocalDateTime (java.time.LocalDateTime)1 Collections (java.util.Collections)1