mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat(s3): preserve explicit object SSE headers (#515)
* feat(s3): preserve explicit object SSE headers * refactor(s3): validate and encapsulate SSE write options * fix(s3): make notification filter parsing deterministic * fix(ses): harden identity deletion lookups * fix(ses): reject padded identities literally * fix(secretsmanager): keep a single previous stage
This commit is contained in:
1 parent
1b53e53dba
commit
2efb483390
15 files changed
+610
-75
No files matched your search
@@ -13,9 +13,11 @@ import io.github.hectorvent.floci.services.s3.model.MultipartUpload;
|
||||
import io.github.hectorvent.floci.services.s3.model.FilterRule;
|
||||
import io.github.hectorvent.floci.services.s3.model.NotificationConfiguration;
|
||||
import io.github.hectorvent.floci.services.s3.model.ObjectAttributeName;
|
||||
import io.github.hectorvent.floci.services.s3.model.CopyObjectOptions;
|
||||
import io.github.hectorvent.floci.services.s3.model.QueueNotification;
|
||||
import io.github.hectorvent.floci.services.s3.model.ObjectLockRetention;
|
||||
import io.github.hectorvent.floci.services.s3.model.Part;
|
||||
import io.github.hectorvent.floci.services.s3.model.PutObjectOptions;
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Checksum;
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Object;
|
||||
import io.github.hectorvent.floci.services.s3.model.TopicNotification;
|
||||
@@ -28,6 +30,7 @@ import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.StringReader;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
@@ -42,6 +45,10 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -59,9 +66,17 @@ public class S3Controller {
|
||||
private static final DateTimeFormatter RFC_822 = DateTimeFormatter
|
||||
.ofPattern("EEE, dd MMM yyyy HH:mm:ss z", Locale.US)
|
||||
.withZone(ZoneId.of("GMT"));
|
||||
private static final XMLInputFactory NOTIFICATION_XML_FACTORY;
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
static {
|
||||
NOTIFICATION_XML_FACTORY = XMLInputFactory.newInstance();
|
||||
NOTIFICATION_XML_FACTORY.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
|
||||
NOTIFICATION_XML_FACTORY.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
|
||||
NOTIFICATION_XML_FACTORY.setProperty(XMLInputFactory.SUPPORT_DTD, false);
|
||||
}
|
||||
|
||||
private final S3Service s3Service;
|
||||
private final S3SelectService s3SelectService;
|
||||
private final RegionResolver regionResolver;
|
||||
@@ -444,14 +459,19 @@ public class S3Controller {
|
||||
String persistedEncoding = toPersistedContentEncoding(contentEncoding);
|
||||
String contentDisposition = httpHeaders.getHeaderString("Content-Disposition");
|
||||
String cacheControl = httpHeaders.getHeaderString("Cache-Control");
|
||||
String serverSideEncryption = httpHeaders.getHeaderString("x-amz-server-side-encryption");
|
||||
String cannedAcl = httpHeaders.getHeaderString("x-amz-acl");
|
||||
S3Object obj = s3Service.putObject(bucket, key, data, contentType, extractUserMetadata(httpHeaders),
|
||||
httpHeaders.getHeaderString("x-amz-storage-class"),
|
||||
persistedEncoding,
|
||||
lockMode, retainUntil, legalHold,
|
||||
contentDisposition,
|
||||
cacheControl,
|
||||
cannedAcl);
|
||||
new PutObjectOptions()
|
||||
.withStorageClass(httpHeaders.getHeaderString("x-amz-storage-class"))
|
||||
.withContentEncoding(persistedEncoding)
|
||||
.withObjectLockMode(lockMode)
|
||||
.withRetainUntilDate(retainUntil)
|
||||
.withLegalHoldStatus(legalHold)
|
||||
.withContentDisposition(contentDisposition)
|
||||
.withCacheControl(cacheControl)
|
||||
.withServerSideEncryption(serverSideEncryption)
|
||||
.withAcl(cannedAcl));
|
||||
var resp = Response.ok().header("ETag", obj.getETag());
|
||||
if (obj.getVersionId() != null) {
|
||||
resp.header("x-amz-version-id", obj.getVersionId());
|
||||
@@ -779,6 +799,7 @@ public class S3Controller {
|
||||
extractUserMetadata(httpHeaders),
|
||||
httpHeaders.getHeaderString("x-amz-storage-class"),
|
||||
httpHeaders.getHeaderString("Content-Disposition"),
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption"),
|
||||
httpHeaders.getHeaderString("x-amz-acl"));
|
||||
String xml = new XmlBuilder()
|
||||
.raw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
||||
@@ -1095,27 +1116,92 @@ public class S3Controller {
|
||||
|
||||
private static List<ParsedNotificationGroup> parseNotificationGroups(
|
||||
String xml, String groupElement, String arnElement) {
|
||||
var groups = XmlParser.extractGroupsMulti(xml, groupElement);
|
||||
var filters = XmlParser.extractPairsPerGroup(xml, groupElement,
|
||||
"FilterRule", "Name", "Value");
|
||||
List<ParsedNotificationGroup> result = new ArrayList<>();
|
||||
for (int i = 0; i < groups.size(); i++) {
|
||||
var group = groups.get(i);
|
||||
String id = group.getOrDefault("Id", List.of("")).getFirst();
|
||||
List<String> arns = group.get(arnElement);
|
||||
List<String> events = group.get("Event");
|
||||
if (arns != null && !arns.isEmpty() && events != null && !events.isEmpty()) {
|
||||
List<FilterRule> rules = i < filters.size()
|
||||
? filters.get(i).entrySet().stream()
|
||||
.map(e -> new FilterRule(e.getKey(), e.getValue()))
|
||||
.toList()
|
||||
: List.of();
|
||||
result.add(new ParsedNotificationGroup(id, arns.getFirst(), events, rules));
|
||||
if (xml == null || xml.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
try {
|
||||
XMLStreamReader reader = NOTIFICATION_XML_FACTORY.createXMLStreamReader(new StringReader(xml));
|
||||
while (reader.hasNext()) {
|
||||
int event = reader.next();
|
||||
if (event == XMLStreamConstants.START_ELEMENT && groupElement.equals(reader.getLocalName())) {
|
||||
ParsedNotificationGroup parsed = readNotificationGroup(reader, groupElement, arnElement);
|
||||
if (parsed.arn() != null && !parsed.events().isEmpty()) {
|
||||
result.add(parsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ParsedNotificationGroup readNotificationGroup(
|
||||
XMLStreamReader reader, String groupElement, String arnElement) throws XMLStreamException {
|
||||
String id = "";
|
||||
String arn = null;
|
||||
List<String> events = new ArrayList<>();
|
||||
List<FilterRule> filterRules = new ArrayList<>();
|
||||
int depth = 1;
|
||||
|
||||
while (reader.hasNext()) {
|
||||
int event = reader.next();
|
||||
if (event == XMLStreamConstants.START_ELEMENT) {
|
||||
String local = reader.getLocalName();
|
||||
if (depth == 1 && "Id".equals(local)) {
|
||||
id = reader.getElementText();
|
||||
} else if (depth == 1 && arnElement.equals(local)) {
|
||||
arn = reader.getElementText();
|
||||
} else if (depth == 1 && "Event".equals(local)) {
|
||||
events.add(reader.getElementText());
|
||||
} else if ("FilterRule".equals(local)) {
|
||||
FilterRule rule = readFilterRule(reader);
|
||||
if (rule != null) {
|
||||
filterRules.add(rule);
|
||||
}
|
||||
} else {
|
||||
depth++;
|
||||
}
|
||||
} else if (event == XMLStreamConstants.END_ELEMENT) {
|
||||
String local = reader.getLocalName();
|
||||
if (groupElement.equals(local) && depth == 1) {
|
||||
break;
|
||||
}
|
||||
depth--;
|
||||
}
|
||||
}
|
||||
|
||||
return new ParsedNotificationGroup(id, arn, events, filterRules);
|
||||
}
|
||||
|
||||
private static FilterRule readFilterRule(XMLStreamReader reader) throws XMLStreamException {
|
||||
String name = null;
|
||||
String value = null;
|
||||
int depth = 1;
|
||||
|
||||
while (reader.hasNext()) {
|
||||
int event = reader.next();
|
||||
if (event == XMLStreamConstants.START_ELEMENT) {
|
||||
String local = reader.getLocalName();
|
||||
if (depth == 1 && "Name".equals(local)) {
|
||||
name = reader.getElementText();
|
||||
} else if (depth == 1 && "Value".equals(local)) {
|
||||
value = reader.getElementText();
|
||||
} else {
|
||||
depth++;
|
||||
}
|
||||
} else if (event == XMLStreamConstants.END_ELEMENT) {
|
||||
if ("FilterRule".equals(reader.getLocalName()) && depth == 1) {
|
||||
break;
|
||||
}
|
||||
depth--;
|
||||
}
|
||||
}
|
||||
|
||||
return name != null && value != null ? new FilterRule(name, value) : null;
|
||||
}
|
||||
|
||||
private static void appendFilterRules(XmlBuilder xml, List<FilterRule> rules) {
|
||||
if (rules == null || rules.isEmpty()) return;
|
||||
xml.start("Filter").start("S3Key");
|
||||
@@ -1361,6 +1447,9 @@ public class S3Controller {
|
||||
if (obj.getCacheControl() != null) {
|
||||
resp.header("Cache-Control", obj.getCacheControl());
|
||||
}
|
||||
if (obj.getServerSideEncryption() != null) {
|
||||
resp.header("x-amz-server-side-encryption", obj.getServerSideEncryption());
|
||||
}
|
||||
if (obj.getMetadata() != null) {
|
||||
for (Map.Entry<String, String> entry : obj.getMetadata().entrySet()) {
|
||||
resp.header("x-amz-meta-" + entry.getKey(), entry.getValue());
|
||||
@@ -1407,16 +1496,19 @@ public class S3Controller {
|
||||
String copyContentEncoding = toPersistedContentEncoding(httpHeaders.getHeaderString("Content-Encoding"));
|
||||
String copyContentDisposition = httpHeaders.getHeaderString("Content-Disposition");
|
||||
String copyCacheControl = httpHeaders.getHeaderString("Cache-Control");
|
||||
String copyServerSideEncryption = httpHeaders.getHeaderString("x-amz-server-side-encryption");
|
||||
String cannedAcl = httpHeaders.getHeaderString("x-amz-acl");
|
||||
S3Object copy = s3Service.copyObject(sourceBucket, sourceKey, destBucket, destKey,
|
||||
httpHeaders.getHeaderString("x-amz-metadata-directive"),
|
||||
extractUserMetadata(httpHeaders),
|
||||
httpHeaders.getHeaderString("x-amz-storage-class"),
|
||||
contentType,
|
||||
copyContentEncoding,
|
||||
copyContentDisposition,
|
||||
copyCacheControl,
|
||||
cannedAcl);
|
||||
new CopyObjectOptions()
|
||||
.withMetadataDirective(httpHeaders.getHeaderString("x-amz-metadata-directive"))
|
||||
.withReplacementMetadata(extractUserMetadata(httpHeaders))
|
||||
.withStorageClass(httpHeaders.getHeaderString("x-amz-storage-class"))
|
||||
.withContentType(contentType)
|
||||
.withContentEncoding(copyContentEncoding)
|
||||
.withContentDisposition(copyContentDisposition)
|
||||
.withCacheControl(copyCacheControl)
|
||||
.withServerSideEncryption(copyServerSideEncryption)
|
||||
.withAcl(cannedAcl));
|
||||
String xml = new XmlBuilder()
|
||||
.raw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
||||
.start("CopyObjectResult", AwsNamespaces.S3)
|
||||
|
||||
@@ -42,6 +42,7 @@ public class S3Service {
|
||||
private static final String DEFAULT_OWNER_DISPLAY_NAME = "floci";
|
||||
private static final String ALL_USERS_GROUP_URI = "http://acs.amazonaws.com/groups/global/AllUsers";
|
||||
private static final String AUTHENTICATED_USERS_GROUP_URI = "http://acs.amazonaws.com/groups/global/AuthenticatedUsers";
|
||||
private static final Set<String> SUPPORTED_SERVER_SIDE_ENCRYPTION_VALUES = Set.of("AES256", "aws:kms", "aws:kms:dsse", "aws:fsx");
|
||||
|
||||
@FunctionalInterface
|
||||
interface LambdaInvoker {
|
||||
@@ -193,30 +194,51 @@ public class S3Service {
|
||||
|
||||
public S3Object putObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata) {
|
||||
return putObject(bucketName, key, data, contentType, metadata, null, null, null, null, null, null, null, null);
|
||||
return putObject(bucketName, key, data, contentType, metadata, new PutObjectOptions());
|
||||
}
|
||||
|
||||
public S3Object putObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata,
|
||||
String objectLockMode, Instant retainUntilDate, String legalHoldStatus) {
|
||||
return putObject(bucketName, key, data, contentType, metadata, null, null,
|
||||
objectLockMode, retainUntilDate, legalHoldStatus, null, null, null);
|
||||
return putObject(bucketName, key, data, contentType, metadata,
|
||||
new PutObjectOptions()
|
||||
.withObjectLockMode(objectLockMode)
|
||||
.withRetainUntilDate(retainUntilDate)
|
||||
.withLegalHoldStatus(legalHoldStatus));
|
||||
}
|
||||
|
||||
public S3Object putObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata, String storageClass,
|
||||
String objectLockMode, Instant retainUntilDate, String legalHoldStatus) {
|
||||
return putObject(bucketName, key, data, contentType, metadata, storageClass, null,
|
||||
objectLockMode, retainUntilDate, legalHoldStatus, null, null, null);
|
||||
return putObject(bucketName, key, data, contentType, metadata,
|
||||
new PutObjectOptions()
|
||||
.withStorageClass(storageClass)
|
||||
.withObjectLockMode(objectLockMode)
|
||||
.withRetainUntilDate(retainUntilDate)
|
||||
.withLegalHoldStatus(legalHoldStatus));
|
||||
}
|
||||
|
||||
public S3Object putObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata, String storageClass,
|
||||
String contentEncoding,
|
||||
String objectLockMode, Instant retainUntilDate, String legalHoldStatus,
|
||||
String contentDisposition, String cacheControl, String acl) {
|
||||
S3Object object = storeObject(bucketName, key, data, contentType, metadata, storageClass, null, null,
|
||||
objectLockMode, retainUntilDate, legalHoldStatus, contentEncoding, contentDisposition, cacheControl, acl);
|
||||
String contentDisposition, String cacheControl, String serverSideEncryption, String acl) {
|
||||
return putObject(bucketName, key, data, contentType, metadata,
|
||||
new PutObjectOptions()
|
||||
.withStorageClass(storageClass)
|
||||
.withContentEncoding(contentEncoding)
|
||||
.withObjectLockMode(objectLockMode)
|
||||
.withRetainUntilDate(retainUntilDate)
|
||||
.withLegalHoldStatus(legalHoldStatus)
|
||||
.withContentDisposition(contentDisposition)
|
||||
.withCacheControl(cacheControl)
|
||||
.withServerSideEncryption(serverSideEncryption)
|
||||
.withAcl(acl));
|
||||
}
|
||||
|
||||
public S3Object putObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata, PutObjectOptions options) {
|
||||
S3Object object = storeObject(bucketName, key, data, contentType, metadata, null, null, options);
|
||||
fireNotifications(bucketName, key, "ObjectCreated:Put", object);
|
||||
return object;
|
||||
}
|
||||
@@ -226,38 +248,42 @@ public class S3Service {
|
||||
*/
|
||||
private S3Object storeObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata) {
|
||||
return storeObject(bucketName, key, data, contentType, metadata, null, null, null,
|
||||
null, null, null, null, null, null, null);
|
||||
return storeObject(bucketName, key, data, contentType, metadata, null, null, new PutObjectOptions());
|
||||
}
|
||||
|
||||
private S3Object storeObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata, String storageClass,
|
||||
S3Checksum checksum, List<Part> parts,
|
||||
String objectLockMode, Instant retainUntilDate, String legalHoldStatus) {
|
||||
return storeObject(bucketName, key, data, contentType, metadata, storageClass, checksum, parts,
|
||||
objectLockMode, retainUntilDate, legalHoldStatus, null, null, null, null);
|
||||
return storeObject(bucketName, key, data, contentType, metadata, checksum, parts,
|
||||
new PutObjectOptions()
|
||||
.withStorageClass(storageClass)
|
||||
.withObjectLockMode(objectLockMode)
|
||||
.withRetainUntilDate(retainUntilDate)
|
||||
.withLegalHoldStatus(legalHoldStatus));
|
||||
}
|
||||
|
||||
private S3Object storeObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata, String storageClass,
|
||||
S3Checksum checksum, List<Part> parts,
|
||||
String objectLockMode, Instant retainUntilDate, String legalHoldStatus,
|
||||
String contentEncoding, String contentDisposition, String cacheControl, String acl) {
|
||||
String contentType, Map<String, String> metadata,
|
||||
S3Checksum checksum, List<Part> parts, PutObjectOptions options) {
|
||||
Bucket bucket = bucketStore.get(bucketName)
|
||||
.orElseThrow(() -> new AwsException("NoSuchBucket",
|
||||
"The specified bucket does not exist.", 404));
|
||||
PutObjectOptions effectiveOptions = options != null ? options : new PutObjectOptions();
|
||||
String normalizedServerSideEncryption = normalizeServerSideEncryption(effectiveOptions.getServerSideEncryption());
|
||||
|
||||
S3Object object = new S3Object(bucketName, key, data, contentType);
|
||||
if (metadata != null) {
|
||||
object.getMetadata().putAll(metadata);
|
||||
}
|
||||
object.setStorageClass(ObjectAttributeName.normalizeStorageClass(storageClass));
|
||||
object.setStorageClass(ObjectAttributeName.normalizeStorageClass(effectiveOptions.getStorageClass()));
|
||||
object.setChecksum(checksum != null ? copyChecksum(checksum) : buildChecksum(data, parts, false));
|
||||
object.setParts(copyParts(parts));
|
||||
object.setContentEncoding(contentEncoding);
|
||||
object.setContentDisposition(contentDisposition);
|
||||
object.setCacheControl(cacheControl);
|
||||
object.setAcl(cannedObjectAclXml(acl));
|
||||
object.setContentEncoding(effectiveOptions.getContentEncoding());
|
||||
object.setContentDisposition(effectiveOptions.getContentDisposition());
|
||||
object.setCacheControl(effectiveOptions.getCacheControl());
|
||||
object.setServerSideEncryption(normalizedServerSideEncryption);
|
||||
object.setAcl(cannedObjectAclXml(effectiveOptions.getAcl()));
|
||||
|
||||
if (bucket.isVersioningEnabled()) {
|
||||
String versionId = UUID.randomUUID().toString();
|
||||
@@ -277,7 +303,10 @@ public class S3Service {
|
||||
});
|
||||
|
||||
// Apply lock fields from request or bucket default
|
||||
applyObjectLock(object, bucket, objectLockMode, retainUntilDate, legalHoldStatus);
|
||||
applyObjectLock(object, bucket,
|
||||
effectiveOptions.getObjectLockMode(),
|
||||
effectiveOptions.getRetainUntilDate(),
|
||||
effectiveOptions.getLegalHoldStatus());
|
||||
|
||||
// Store versioned copy and update latest pointer
|
||||
objectStore.put(versionedKey(bucketName, key, versionId), object);
|
||||
@@ -296,7 +325,10 @@ public class S3Service {
|
||||
}
|
||||
|
||||
// Apply lock fields from request or bucket default
|
||||
applyObjectLock(object, bucket, objectLockMode, retainUntilDate, legalHoldStatus);
|
||||
applyObjectLock(object, bucket,
|
||||
effectiveOptions.getObjectLockMode(),
|
||||
effectiveOptions.getRetainUntilDate(),
|
||||
effectiveOptions.getLegalHoldStatus());
|
||||
|
||||
objectStore.put(objectKey(bucketName, key), object);
|
||||
writeFile(bucketName, key, data);
|
||||
@@ -601,40 +633,79 @@ public class S3Service {
|
||||
|
||||
public S3Object copyObject(String sourceBucket, String sourceKey,
|
||||
String destBucket, String destKey) {
|
||||
return copyObject(sourceBucket, sourceKey, destBucket, destKey,
|
||||
null, null, null, null);
|
||||
return copyObject(sourceBucket, sourceKey, destBucket, destKey, new CopyObjectOptions());
|
||||
}
|
||||
|
||||
public S3Object copyObject(String sourceBucket, String sourceKey,
|
||||
String destBucket, String destKey,
|
||||
String metadataDirective, Map<String, String> replacementMetadata,
|
||||
String storageClass, String contentType) {
|
||||
return copyObject(sourceBucket, sourceKey, destBucket, destKey, metadataDirective,
|
||||
replacementMetadata, storageClass, contentType, null, null, null, null);
|
||||
return copyObject(sourceBucket, sourceKey, destBucket, destKey,
|
||||
new CopyObjectOptions()
|
||||
.withMetadataDirective(metadataDirective)
|
||||
.withReplacementMetadata(replacementMetadata)
|
||||
.withStorageClass(storageClass)
|
||||
.withContentType(contentType));
|
||||
}
|
||||
|
||||
public S3Object copyObject(String sourceBucket, String sourceKey,
|
||||
String destBucket, String destKey,
|
||||
String metadataDirective, Map<String, String> replacementMetadata,
|
||||
String storageClass, String contentType, String contentEncoding,
|
||||
String contentDisposition, String cacheControl, String acl) {
|
||||
String contentDisposition, String cacheControl, String serverSideEncryption, String acl) {
|
||||
return copyObject(sourceBucket, sourceKey, destBucket, destKey,
|
||||
new CopyObjectOptions()
|
||||
.withMetadataDirective(metadataDirective)
|
||||
.withReplacementMetadata(replacementMetadata)
|
||||
.withStorageClass(storageClass)
|
||||
.withContentType(contentType)
|
||||
.withContentEncoding(contentEncoding)
|
||||
.withContentDisposition(contentDisposition)
|
||||
.withCacheControl(cacheControl)
|
||||
.withServerSideEncryption(serverSideEncryption)
|
||||
.withAcl(acl));
|
||||
}
|
||||
|
||||
public S3Object copyObject(String sourceBucket, String sourceKey,
|
||||
String destBucket, String destKey, CopyObjectOptions options) {
|
||||
S3Object source = getObject(sourceBucket, sourceKey);
|
||||
ensureBucketExists(destBucket);
|
||||
CopyObjectOptions effectiveOptions = options != null ? options : new CopyObjectOptions();
|
||||
String normalizedServerSideEncryption = normalizeServerSideEncryption(effectiveOptions.getServerSideEncryption());
|
||||
|
||||
boolean replaceMetadata = "REPLACE".equalsIgnoreCase(metadataDirective);
|
||||
boolean replaceMetadata = "REPLACE".equalsIgnoreCase(effectiveOptions.getMetadataDirective());
|
||||
Map<String, String> metadata = replaceMetadata ? new LinkedHashMap<>() : new LinkedHashMap<>(source.getMetadata());
|
||||
if (replaceMetadata && replacementMetadata != null) {
|
||||
metadata.putAll(replacementMetadata);
|
||||
if (replaceMetadata && effectiveOptions.getReplacementMetadata() != null) {
|
||||
metadata.putAll(effectiveOptions.getReplacementMetadata());
|
||||
}
|
||||
|
||||
String effectiveContentType = replaceMetadata && contentType != null ? contentType : source.getContentType();
|
||||
String effectiveStorageClass = storageClass != null ? storageClass : source.getStorageClass();
|
||||
String effectiveContentEncoding = replaceMetadata && contentEncoding != null ? contentEncoding : source.getContentEncoding();
|
||||
String effectiveContentDisposition = replaceMetadata && contentDisposition != null ? contentDisposition : source.getContentDisposition();
|
||||
String effectiveCacheControl = replaceMetadata && cacheControl != null ? cacheControl : source.getCacheControl();
|
||||
String effectiveContentType = replaceMetadata && effectiveOptions.getContentType() != null
|
||||
? effectiveOptions.getContentType()
|
||||
: source.getContentType();
|
||||
String effectiveStorageClass = effectiveOptions.getStorageClass() != null
|
||||
? effectiveOptions.getStorageClass()
|
||||
: source.getStorageClass();
|
||||
String effectiveContentEncoding = replaceMetadata && effectiveOptions.getContentEncoding() != null
|
||||
? effectiveOptions.getContentEncoding()
|
||||
: source.getContentEncoding();
|
||||
String effectiveContentDisposition = replaceMetadata && effectiveOptions.getContentDisposition() != null
|
||||
? effectiveOptions.getContentDisposition()
|
||||
: source.getContentDisposition();
|
||||
String effectiveCacheControl = replaceMetadata && effectiveOptions.getCacheControl() != null
|
||||
? effectiveOptions.getCacheControl()
|
||||
: source.getCacheControl();
|
||||
String effectiveServerSideEncryption = normalizedServerSideEncryption != null
|
||||
? normalizedServerSideEncryption
|
||||
: source.getServerSideEncryption();
|
||||
S3Object copy = storeObject(destBucket, destKey, source.getData(), effectiveContentType, metadata,
|
||||
effectiveStorageClass, source.getChecksum(), source.getParts(), null, null, null,
|
||||
effectiveContentEncoding, effectiveContentDisposition, effectiveCacheControl, acl);
|
||||
source.getChecksum(), source.getParts(),
|
||||
new PutObjectOptions()
|
||||
.withStorageClass(effectiveStorageClass)
|
||||
.withContentEncoding(effectiveContentEncoding)
|
||||
.withContentDisposition(effectiveContentDisposition)
|
||||
.withCacheControl(effectiveCacheControl)
|
||||
.withServerSideEncryption(effectiveServerSideEncryption)
|
||||
.withAcl(effectiveOptions.getAcl()));
|
||||
copy.setETag(source.getETag());
|
||||
LOG.debugv("Copied object: {0}/{1} -> {2}/{3}", sourceBucket, sourceKey, destBucket, destKey);
|
||||
fireNotifications(destBucket, destKey, "ObjectCreated:Copy", copy);
|
||||
@@ -951,27 +1022,29 @@ public class S3Service {
|
||||
// --- Multipart Upload Operations ---
|
||||
|
||||
public MultipartUpload initiateMultipartUpload(String bucket, String key, String contentType) {
|
||||
return initiateMultipartUpload(bucket, key, contentType, null, null, null, null);
|
||||
return initiateMultipartUpload(bucket, key, contentType, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public MultipartUpload initiateMultipartUpload(String bucket, String key, String contentType,
|
||||
Map<String, String> metadata, String storageClass) {
|
||||
return initiateMultipartUpload(bucket, key, contentType, metadata, storageClass, null, null);
|
||||
return initiateMultipartUpload(bucket, key, contentType, metadata, storageClass, null, null, null);
|
||||
}
|
||||
|
||||
public MultipartUpload initiateMultipartUpload(String bucket, String key, String contentType,
|
||||
Map<String, String> metadata, String storageClass,
|
||||
String contentDisposition, String acl) {
|
||||
String contentDisposition, String serverSideEncryption, String acl) {
|
||||
ensureBucketExists(bucket);
|
||||
if (acl != null && !acl.isBlank()) {
|
||||
cannedObjectAclXml(acl);
|
||||
}
|
||||
String normalizedServerSideEncryption = normalizeServerSideEncryption(serverSideEncryption);
|
||||
MultipartUpload upload = new MultipartUpload(bucket, key, contentType);
|
||||
if (metadata != null) {
|
||||
upload.getMetadata().putAll(metadata);
|
||||
}
|
||||
upload.setStorageClass(ObjectAttributeName.normalizeStorageClass(storageClass));
|
||||
upload.setContentDisposition(contentDisposition);
|
||||
upload.setServerSideEncryption(normalizedServerSideEncryption);
|
||||
upload.setAcl(acl);
|
||||
|
||||
if (inMemory) {
|
||||
@@ -1078,8 +1151,12 @@ public class S3Service {
|
||||
.toList();
|
||||
S3Checksum checksum = buildChecksum(allData, completedParts, true);
|
||||
S3Object object = storeObject(bucket, key, allData, upload.getContentType(), upload.getMetadata(),
|
||||
upload.getStorageClass(), checksum, completedParts, null, null, null,
|
||||
null, upload.getContentDisposition(), null, upload.getAcl());
|
||||
checksum, completedParts,
|
||||
new PutObjectOptions()
|
||||
.withStorageClass(upload.getStorageClass())
|
||||
.withContentDisposition(upload.getContentDisposition())
|
||||
.withServerSideEncryption(upload.getServerSideEncryption())
|
||||
.withAcl(upload.getAcl()));
|
||||
// Override the ETag with the composite multipart ETag
|
||||
object.setETag(compositeETag);
|
||||
objectStore.put(objectKey(bucket, key), object);
|
||||
@@ -1451,6 +1528,24 @@ public class S3Service {
|
||||
};
|
||||
}
|
||||
|
||||
static String normalizeServerSideEncryption(String serverSideEncryption) {
|
||||
if (serverSideEncryption == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String normalized = serverSideEncryption.trim();
|
||||
if (normalized.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!SUPPORTED_SERVER_SIDE_ENCRYPTION_VALUES.contains(normalized)) {
|
||||
throw new AwsException("InvalidArgument",
|
||||
"Unsupported x-amz-server-side-encryption value: " + normalized, 400);
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private static String ownerFullControlGrant() {
|
||||
return canonicalUserGrant(DEFAULT_OWNER_ID, DEFAULT_OWNER_DISPLAY_NAME, "FULL_CONTROL");
|
||||
}
|
||||
@@ -1722,6 +1817,7 @@ public class S3Service {
|
||||
copy.setContentEncoding(source.getContentEncoding());
|
||||
copy.setContentDisposition(source.getContentDisposition());
|
||||
copy.setCacheControl(source.getCacheControl());
|
||||
copy.setServerSideEncryption(source.getServerSideEncryption());
|
||||
copy.setSize(source.getSize());
|
||||
copy.setLastModified(source.getLastModified());
|
||||
copy.setETag(source.getETag());
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package io.github.hectorvent.floci.services.s3.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CopyObjectOptions {
|
||||
private String metadataDirective;
|
||||
private Map<String, String> replacementMetadata;
|
||||
private String storageClass;
|
||||
private String contentType;
|
||||
private String contentEncoding;
|
||||
private String contentDisposition;
|
||||
private String cacheControl;
|
||||
private String serverSideEncryption;
|
||||
private String acl;
|
||||
|
||||
public String getMetadataDirective() { return metadataDirective; }
|
||||
public CopyObjectOptions withMetadataDirective(String metadataDirective) { this.metadataDirective = metadataDirective; return this; }
|
||||
|
||||
public Map<String, String> getReplacementMetadata() { return replacementMetadata; }
|
||||
public CopyObjectOptions withReplacementMetadata(Map<String, String> replacementMetadata) { this.replacementMetadata = replacementMetadata; return this; }
|
||||
|
||||
public String getStorageClass() { return storageClass; }
|
||||
public CopyObjectOptions withStorageClass(String storageClass) { this.storageClass = storageClass; return this; }
|
||||
|
||||
public String getContentType() { return contentType; }
|
||||
public CopyObjectOptions withContentType(String contentType) { this.contentType = contentType; return this; }
|
||||
|
||||
public String getContentEncoding() { return contentEncoding; }
|
||||
public CopyObjectOptions withContentEncoding(String contentEncoding) { this.contentEncoding = contentEncoding; return this; }
|
||||
|
||||
public String getContentDisposition() { return contentDisposition; }
|
||||
public CopyObjectOptions withContentDisposition(String contentDisposition) { this.contentDisposition = contentDisposition; return this; }
|
||||
|
||||
public String getCacheControl() { return cacheControl; }
|
||||
public CopyObjectOptions withCacheControl(String cacheControl) { this.cacheControl = cacheControl; return this; }
|
||||
|
||||
public String getServerSideEncryption() { return serverSideEncryption; }
|
||||
public CopyObjectOptions withServerSideEncryption(String serverSideEncryption) { this.serverSideEncryption = serverSideEncryption; return this; }
|
||||
|
||||
public String getAcl() { return acl; }
|
||||
public CopyObjectOptions withAcl(String acl) { this.acl = acl; return this; }
|
||||
}
|
||||
@@ -17,6 +17,7 @@ public class MultipartUpload {
|
||||
private String contentType;
|
||||
private String storageClass;
|
||||
private String contentDisposition;
|
||||
private String serverSideEncryption;
|
||||
private String acl;
|
||||
private Map<String, String> metadata;
|
||||
private Instant initiated;
|
||||
@@ -55,6 +56,9 @@ public class MultipartUpload {
|
||||
public String getContentDisposition() { return contentDisposition; }
|
||||
public void setContentDisposition(String contentDisposition) { this.contentDisposition = contentDisposition; }
|
||||
|
||||
public String getServerSideEncryption() { return serverSideEncryption; }
|
||||
public void setServerSideEncryption(String serverSideEncryption) { this.serverSideEncryption = serverSideEncryption; }
|
||||
|
||||
public String getAcl() { return acl; }
|
||||
public void setAcl(String acl) { this.acl = acl; }
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package io.github.hectorvent.floci.services.s3.model;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public class PutObjectOptions {
|
||||
private String storageClass;
|
||||
private String contentEncoding;
|
||||
private String objectLockMode;
|
||||
private Instant retainUntilDate;
|
||||
private String legalHoldStatus;
|
||||
private String contentDisposition;
|
||||
private String cacheControl;
|
||||
private String serverSideEncryption;
|
||||
private String acl;
|
||||
|
||||
public String getStorageClass() { return storageClass; }
|
||||
public PutObjectOptions withStorageClass(String storageClass) { this.storageClass = storageClass; return this; }
|
||||
|
||||
public String getContentEncoding() { return contentEncoding; }
|
||||
public PutObjectOptions withContentEncoding(String contentEncoding) { this.contentEncoding = contentEncoding; return this; }
|
||||
|
||||
public String getObjectLockMode() { return objectLockMode; }
|
||||
public PutObjectOptions withObjectLockMode(String objectLockMode) { this.objectLockMode = objectLockMode; return this; }
|
||||
|
||||
public Instant getRetainUntilDate() { return retainUntilDate; }
|
||||
public PutObjectOptions withRetainUntilDate(Instant retainUntilDate) { this.retainUntilDate = retainUntilDate; return this; }
|
||||
|
||||
public String getLegalHoldStatus() { return legalHoldStatus; }
|
||||
public PutObjectOptions withLegalHoldStatus(String legalHoldStatus) { this.legalHoldStatus = legalHoldStatus; return this; }
|
||||
|
||||
public String getContentDisposition() { return contentDisposition; }
|
||||
public PutObjectOptions withContentDisposition(String contentDisposition) { this.contentDisposition = contentDisposition; return this; }
|
||||
|
||||
public String getCacheControl() { return cacheControl; }
|
||||
public PutObjectOptions withCacheControl(String cacheControl) { this.cacheControl = cacheControl; return this; }
|
||||
|
||||
public String getServerSideEncryption() { return serverSideEncryption; }
|
||||
public PutObjectOptions withServerSideEncryption(String serverSideEncryption) { this.serverSideEncryption = serverSideEncryption; return this; }
|
||||
|
||||
public String getAcl() { return acl; }
|
||||
public PutObjectOptions withAcl(String acl) { this.acl = acl; return this; }
|
||||
}
|
||||
@@ -24,6 +24,7 @@ public class S3Object {
|
||||
private String contentEncoding;
|
||||
private String contentDisposition;
|
||||
private String cacheControl;
|
||||
private String serverSideEncryption;
|
||||
private long size;
|
||||
private Instant lastModified;
|
||||
private String eTag;
|
||||
@@ -89,6 +90,9 @@ public class S3Object {
|
||||
public String getCacheControl() { return cacheControl; }
|
||||
public void setCacheControl(String cacheControl) { this.cacheControl = cacheControl; }
|
||||
|
||||
public String getServerSideEncryption() { return serverSideEncryption; }
|
||||
public void setServerSideEncryption(String serverSideEncryption) { this.serverSideEncryption = serverSideEncryption; }
|
||||
|
||||
public long getSize() { return size; }
|
||||
public void setSize(long size) { this.size = size; }
|
||||
|
||||
|
||||
+18
-3
@@ -153,20 +153,35 @@ public class SecretsManagerService {
|
||||
stages = List.of(AWSCURRENT);
|
||||
}
|
||||
|
||||
SecretVersion previousCurrent = stages.contains(AWSCURRENT) ? findVersionByStage(secret, AWSCURRENT) : null;
|
||||
|
||||
for (String stage : stages) {
|
||||
SecretVersion version = findVersionByStage(secret, stage);
|
||||
if (version == null) {
|
||||
continue;
|
||||
}
|
||||
List<String> newStages = new ArrayList<>(version.getVersionStages());
|
||||
if (stage.equals(AWSCURRENT)) {
|
||||
newStages.add(AWSPREVIOUS);
|
||||
}
|
||||
newStages.remove(stage);
|
||||
|
||||
version.setVersionStages(newStages);
|
||||
}
|
||||
|
||||
if (previousCurrent != null) {
|
||||
for (SecretVersion version : secret.getVersions().values()) {
|
||||
List<String> assignedStages = version.getVersionStages();
|
||||
if (assignedStages == null || !assignedStages.contains(AWSPREVIOUS)) {
|
||||
continue;
|
||||
}
|
||||
List<String> newStages = new ArrayList<>(assignedStages);
|
||||
newStages.removeIf(AWSPREVIOUS::equals);
|
||||
version.setVersionStages(newStages);
|
||||
}
|
||||
|
||||
List<String> newStages = new ArrayList<>(previousCurrent.getVersionStages());
|
||||
newStages.add(AWSPREVIOUS);
|
||||
previousCurrent.setVersionStages(newStages);
|
||||
}
|
||||
|
||||
SecretVersion newVersion = new SecretVersion();
|
||||
newVersion.setVersionId(newVersionId);
|
||||
newVersion.setSecretString(secretString);
|
||||
|
||||
@@ -44,6 +44,7 @@ public class SesService {
|
||||
}
|
||||
|
||||
public Identity verifyEmailIdentity(String emailAddress, String region) {
|
||||
validateIdentityWhitespace(emailAddress, "Email address");
|
||||
if (emailAddress == null || emailAddress.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "Email address is required.", 400);
|
||||
}
|
||||
@@ -58,6 +59,7 @@ public class SesService {
|
||||
}
|
||||
|
||||
public Identity verifyDomainIdentity(String domain, String region) {
|
||||
validateIdentityWhitespace(domain, "Domain");
|
||||
if (domain == null || domain.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "Domain is required.", 400);
|
||||
}
|
||||
@@ -72,8 +74,23 @@ public class SesService {
|
||||
}
|
||||
|
||||
public void deleteIdentity(String identityValue, String region) {
|
||||
if (identityValue == null || identityValue.isBlank()) {
|
||||
return;
|
||||
}
|
||||
String key = identityKey(region, identityValue);
|
||||
identityStore.delete(key);
|
||||
|
||||
String prefix = "identity::" + region + "::";
|
||||
List<String> keys = new ArrayList<>(identityStore.keys().stream()
|
||||
.filter(k -> k.startsWith(prefix))
|
||||
.toList());
|
||||
for (String storedKey : keys) {
|
||||
Identity storedIdentity = identityStore.get(storedKey).orElse(null);
|
||||
if (storedIdentity != null && identityValue.equals(storedIdentity.getIdentity())) {
|
||||
identityStore.delete(storedKey);
|
||||
}
|
||||
}
|
||||
|
||||
LOG.infov("Deleted identity: {0}", identityValue);
|
||||
}
|
||||
|
||||
@@ -214,6 +231,16 @@ public class SesService {
|
||||
}
|
||||
|
||||
private static String identityKey(String region, String identity) {
|
||||
validateIdentityWhitespace(identity, "Identity");
|
||||
return "identity::" + region + "::" + identity;
|
||||
}
|
||||
|
||||
private static void validateIdentityWhitespace(String identity, String fieldName) {
|
||||
if (identity == null || identity.isBlank()) {
|
||||
return;
|
||||
}
|
||||
if (Character.isWhitespace(identity.charAt(0)) || Character.isWhitespace(identity.charAt(identity.length() - 1))) {
|
||||
throw new AwsException("InvalidParameterValue", fieldName + " must not contain leading or trailing whitespace.", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user