/** * Gets attribute value by name from the storage entity while specifying whether the attribute value is required (i.e. it must exist and must have a value * configured). This is a convenience method when a value must be returned (i.e. the attribute must be configured and have a value present) or is totally * optional (i.e. the attribute can not exist or it can exist and have a blank value). * * @param attributeName the attribute name (case insensitive) * @param storageEntity the storage entity * @param attributeValueRequired specifies whether the attribute value is mandatory * * @return the attribute value from the attribute with the attribute name. * @throws IllegalArgumentException if the attribute is mandatory and this storage contains no attribute with this attribute name */ public String getStorageAttributeValueByName(String attributeName, StorageEntity storageEntity, boolean attributeValueRequired) throws IllegalArgumentException { return getStorageAttributeValueByName(attributeName, storageEntity, attributeValueRequired, attributeValueRequired); }
storageHelper.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), storageEntity, true); .getBooleanStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX), storageEntity, false, true)) .getBooleanStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE), storageEntity, false, true))
/** * Returns a new instance of S3FileTransferRequestParamsDto populated with all parameters, required to access an S3 bucket. * * @param storageEntity the storage entity that contains attributes to access an S3 bucket * * @return the S3FileTransferRequestParamsDto instance that can be used to access S3 bucket */ public S3FileTransferRequestParamsDto getS3BucketAccessParams(StorageEntity storageEntity) { // Get S3 bucket specific configuration settings. // Please note that since those values are required we pass a "true" flag. String s3BucketName = getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), storageEntity, true); S3FileTransferRequestParamsDto params = getS3FileTransferRequestParamsDto(); params.setS3Endpoint(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT)); params.setS3BucketName(s3BucketName); return params; }
/** * Asserts that the given target storage entity has valid attributes. * * @param targetStorageEntity Target storage entity. */ private void assertTargetStorageEntityValid(StorageEntity targetStorageEntity) { try { // Assert that the target storage has a bucket name storageHelper.getStorageBucketName(targetStorageEntity); } catch (IllegalStateException e) { throw new IllegalArgumentException(e.getMessage(), e); } try { // Assert that the target storage has a KMS key ID storageHelper.getStorageKmsKeyId(targetStorageEntity); } catch (IllegalStateException e) { throw new IllegalArgumentException(e.getMessage(), e); } }
String s3BucketName = storageHelper.getStorageBucketName(storageEntity); String s3ObjectKey = businessObjectDataStorageFileKey.getFilePath(); .getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KMS_KEY_ID), storageEntity, false, true); S3FileTransferRequestParamsDto s3BucketAccessParams = storageHelper.getS3BucketAccessParams(storageEntity); String preSignedUrl = s3Dao.generateGetObjectPresignedUrl(s3BucketName, s3ObjectKey, expiration, s3BucketAccessParams);
.getBooleanStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX), storageEntity, false, true); .getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), storageEntity, false); S3FileTransferRequestParamsDto params = storageHelper.getS3BucketAccessParams(storageEntity); S3FileTransferRequestParamsDto params = storageHelper.getS3BucketAccessParams(storageEntity);
/** * Executes S3 specific steps required for initiation of a business object data destroy. * * @param businessObjectDataDestroyDto the DTO that holds various parameters needed to initiate a business object data destroy */ void executeS3SpecificStepsImpl(BusinessObjectDataDestroyDto businessObjectDataDestroyDto) { // Create an S3 file transfer parameters DTO to access the S3 bucket. // Since the S3 key prefix represents a directory, we add a trailing '/' character to it. S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = storageHelper.getS3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3Endpoint(businessObjectDataDestroyDto.getS3Endpoint()); s3FileTransferRequestParamsDto.setS3BucketName(businessObjectDataDestroyDto.getS3BucketName()); s3FileTransferRequestParamsDto.setS3KeyPrefix(StringUtils.appendIfMissing(businessObjectDataDestroyDto.getS3KeyPrefix(), "/")); // Create an S3 file transfer parameters DTO to be used for S3 object tagging operation. S3FileTransferRequestParamsDto s3ObjectTaggerParamsDto = storageHelper .getS3FileTransferRequestParamsDtoByRole(businessObjectDataDestroyDto.getS3ObjectTaggerRoleArn(), businessObjectDataDestroyDto.getS3ObjectTaggerRoleSessionName()); s3ObjectTaggerParamsDto.setS3Endpoint(businessObjectDataDestroyDto.getS3Endpoint()); // Get all S3 objects matching the S3 key prefix from the S3 bucket. List<S3VersionSummary> s3VersionSummaries = s3Service.listVersions(s3FileTransferRequestParamsDto); // Tag the S3 objects to initiate the deletion. s3Service.tagVersions(s3FileTransferRequestParamsDto, s3ObjectTaggerParamsDto, s3VersionSummaries, new Tag(businessObjectDataDestroyDto.getS3ObjectTagKey(), businessObjectDataDestroyDto.getS3ObjectTagValue())); }
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(StorageEntity.SAMPLE_DATA_FILE_STORAGE); String s3BucketName = storageHelper.getStorageBucketName(storageEntity); String s3EndPoint = storageHelper.getS3BucketAccessParams(storageEntity).getS3Endpoint(); String awsRoleArn = getStorageUploadRoleArn(storageEntity); String sessionID = UUID.randomUUID().toString();
/** * Gets a storage attribute value by name. If the attribute does not exist, returns the default value. If the attribute exists, and is defined, the value * MUST be an integer, otherwise a exception is thrown. * * @param attributeName The name of attribute * @param storageEntity The storage entity * @param defaultValue The default value * * @return The integer value */ public Integer getStorageAttributeIntegerValueByName(String attributeName, StorageEntity storageEntity, Integer defaultValue) { Integer value = getStorageAttributeIntegerValueByName(attributeName, storageEntity, false, false); if (value == null) { value = defaultValue; } return value; }
/** * Gets a Java properties from the given S3 location, and puts the key-value pairs into the given parameters. If either bucket name or object key is null, * this method does nothing. * * @param s3BucketName S3 bucket name * @param s3ObjectKey S3 object key * @param parameters parameters to merge */ private void putParametersFromS3(String s3BucketName, String s3ObjectKey, Map<String, Object> parameters) { if (s3BucketName != null && s3ObjectKey != null) { S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = storageHelper.getS3FileTransferRequestParamsDto(); Properties properties = s3Dao.getProperties(s3BucketName, s3ObjectKey, s3FileTransferRequestParamsDto); parameters.putAll(javaPropertiesHelper.toMap(properties)); } }
/** * Returns a list of S3 object keys associated with the given format, data key, and storage. The keys are found by matching the prefix. The result may be * empty if there are not matching keys found. * * @param businessObjectFormatEntity {@link BusinessObjectFormatEntity} * @param businessObjectDataKey {@link BusinessObjectDataKey} * @param storageEntity {@link StorageEntity} * * @return list of S3 object keys */ private List<String> getS3ObjectKeys(BusinessObjectFormatEntity businessObjectFormatEntity, BusinessObjectDataKey businessObjectDataKey, StorageEntity storageEntity) { String s3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey); S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = storageHelper.getS3BucketAccessParams(storageEntity); s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix + '/'); return storageFileHelper.getFilePathsFromS3ObjectSummaries(s3Dao.listDirectory(s3FileTransferRequestParamsDto)); }
/** * Validates the storage. * * @param storageEntity the storage entity */ void validateStorage(StorageEntity storageEntity) { // Validate that storage policy filter storage has the S3 path prefix validation enabled. if (!storageHelper .getBooleanStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX), storageEntity, false, true)) { throw new IllegalStateException(String.format("Path prefix validation must be enabled on \"%s\" storage.", storageEntity.getName())); } } }
/** * Gets a temporary session token that is only good for downloading the specified object key from the given bucket for a limited amount of time. * * @param storageEntity The storage entity of the external storage. * @param sessionName The session name to use for the temporary credentials. * @param s3ObjectKey The S3 object key of the path to the data in the bucket. * * @return {@link Credentials} temporary session token */ private Credentials getDownloaderCredentialsNoKmsKey(StorageEntity storageEntity, String sessionName, String s3ObjectKey) { return stsDao.getTemporarySecurityCredentials(awsHelper.getAwsParamsDto(), sessionName, getStorageDownloadRoleArn(storageEntity), getStorageDownloadSessionDuration(storageEntity), createDownloaderPolicy(storageHelper.getStorageBucketName(storageEntity), s3ObjectKey)); }
/** * Asserts that the given target storage entity has valid attributes. * * @param targetStorageEntity Target storage entity. */ private void assertTargetStorageEntityValid(StorageEntity targetStorageEntity) { try { // Assert that the target storage has a bucket name storageHelper.getStorageBucketName(targetStorageEntity); } catch (IllegalStateException e) { throw new IllegalArgumentException(e.getMessage(), e); } try { // Assert that the target storage has a KMS key ID storageHelper.getStorageKmsKeyId(targetStorageEntity); } catch (IllegalStateException e) { throw new IllegalArgumentException(e.getMessage(), e); } }
String s3BucketName = storageHelper.getStorageBucketName(storageEntity); String s3ObjectKey = businessObjectDataStorageFileKey.getFilePath(); .getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KMS_KEY_ID), storageEntity, false, true); S3FileTransferRequestParamsDto s3BucketAccessParams = storageHelper.getS3BucketAccessParams(storageEntity); String preSignedUrl = s3Dao.generateGetObjectPresignedUrl(s3BucketName, s3ObjectKey, expiration, s3BucketAccessParams);
.getBooleanStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX), storageEntity, false, true); .getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), storageEntity, false); S3FileTransferRequestParamsDto params = storageHelper.getS3BucketAccessParams(storageEntity); S3FileTransferRequestParamsDto params = storageHelper.getS3BucketAccessParams(storageEntity);
/** * Executes S3 specific steps required for initiation of a business object data destroy. * * @param businessObjectDataDestroyDto the DTO that holds various parameters needed to initiate a business object data destroy */ void executeS3SpecificStepsImpl(BusinessObjectDataDestroyDto businessObjectDataDestroyDto) { // Create an S3 file transfer parameters DTO to access the S3 bucket. // Since the S3 key prefix represents a directory, we add a trailing '/' character to it. S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = storageHelper.getS3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3Endpoint(businessObjectDataDestroyDto.getS3Endpoint()); s3FileTransferRequestParamsDto.setS3BucketName(businessObjectDataDestroyDto.getS3BucketName()); s3FileTransferRequestParamsDto.setS3KeyPrefix(StringUtils.appendIfMissing(businessObjectDataDestroyDto.getS3KeyPrefix(), "/")); // Create an S3 file transfer parameters DTO to be used for S3 object tagging operation. S3FileTransferRequestParamsDto s3ObjectTaggerParamsDto = storageHelper .getS3FileTransferRequestParamsDtoByRole(businessObjectDataDestroyDto.getS3ObjectTaggerRoleArn(), businessObjectDataDestroyDto.getS3ObjectTaggerRoleSessionName()); s3ObjectTaggerParamsDto.setS3Endpoint(businessObjectDataDestroyDto.getS3Endpoint()); // Get all S3 objects matching the S3 key prefix from the S3 bucket. List<S3VersionSummary> s3VersionSummaries = s3Service.listVersions(s3FileTransferRequestParamsDto); // Tag the S3 objects to initiate the deletion. s3Service.tagVersions(s3FileTransferRequestParamsDto, s3ObjectTaggerParamsDto, s3VersionSummaries, new Tag(businessObjectDataDestroyDto.getS3ObjectTagKey(), businessObjectDataDestroyDto.getS3ObjectTagValue())); }
String s3BucketName = storageHelper.getStorageBucketName(storageEntity); String s3ObjectKey = businessObjectDefinitionSampleDataFileKey.getDirectoryPath() + businessObjectDefinitionSampleDataFileKey.getFileName(); S3FileTransferRequestParamsDto s3BucketAccessParams = storageHelper.getS3BucketAccessParams(storageEntity); String presignedUrl = s3Dao.generateGetObjectPresignedUrl(s3BucketName, s3ObjectKey, expiration, s3BucketAccessParams);
/** * Gets a storage attribute value by name. If the attribute does not exist, returns the default value. If the attribute exists, and is defined, the value * MUST be an integer, otherwise a exception is thrown. * * @param attributeName The name of attribute * @param storageEntity The storage entity * @param defaultValue The default value * * @return The integer value */ public Integer getStorageAttributeIntegerValueByName(String attributeName, StorageEntity storageEntity, Integer defaultValue) { Integer value = getStorageAttributeIntegerValueByName(attributeName, storageEntity, false, false); if (value == null) { value = defaultValue; } return value; }
/** * Gets a Java properties from the given S3 location, and puts the key-value pairs into the given parameters. If either bucket name or object key is null, * this method does nothing. * * @param s3BucketName S3 bucket name * @param s3ObjectKey S3 object key * @param parameters parameters to merge */ private void putParametersFromS3(String s3BucketName, String s3ObjectKey, Map<String, Object> parameters) { if (s3BucketName != null && s3ObjectKey != null) { S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = storageHelper.getS3FileTransferRequestParamsDto(); Properties properties = s3Dao.getProperties(s3BucketName, s3ObjectKey, s3FileTransferRequestParamsDto); parameters.putAll(javaPropertiesHelper.toMap(properties)); } }