mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(s3): support bucket logging configuration (#1510)
This commit is contained in:
1 parent
a3f3bf8fe1
commit
2583c3d61e
4 files changed
+118
No files matched your search
@@ -179,6 +179,10 @@ public class S3Controller {
|
||||
if (hasQueryParam(uriInfo, "website")) {
|
||||
return handlePutBucketWebsite(bucket, body);
|
||||
}
|
||||
if (hasQueryParam(uriInfo, "logging")) {
|
||||
s3Service.putBucketLogging(bucket, new String(body, StandardCharsets.UTF_8));
|
||||
return Response.ok().build();
|
||||
}
|
||||
if (hasQueryParam(uriInfo, "policy")) {
|
||||
s3Service.putBucketPolicy(bucket, new String(body, StandardCharsets.UTF_8));
|
||||
return Response.ok().build();
|
||||
@@ -330,6 +334,11 @@ public class S3Controller {
|
||||
if (hasQueryParam(uriInfo, "website")) {
|
||||
return handleGetBucketWebsite(bucket);
|
||||
}
|
||||
if (hasQueryParam(uriInfo, "logging")) {
|
||||
return Response.ok(s3Service.getBucketLogging(bucket))
|
||||
.type("application/xml")
|
||||
.build();
|
||||
}
|
||||
if (hasQueryParam(uriInfo, "policy")) {
|
||||
return Response.ok(s3Service.getBucketPolicy(bucket)).build();
|
||||
}
|
||||
|
||||
@@ -206,6 +206,39 @@ public class S3Service {
|
||||
return bucketStore.scan(key -> true);
|
||||
}
|
||||
|
||||
public void putBucketLogging(String bucketName, String loggingConfigurationXml) {
|
||||
Bucket bucket = bucketStore.get(bucketName)
|
||||
.orElseThrow(() -> new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404));
|
||||
|
||||
if (loggingConfigurationXml == null || loggingConfigurationXml.isBlank()) {
|
||||
bucket.setLoggingConfiguration(null);
|
||||
} else {
|
||||
String targetBucket = XmlParser.extractFirst(loggingConfigurationXml, "TargetBucket", null);
|
||||
if (targetBucket == null) {
|
||||
bucket.setLoggingConfiguration(null);
|
||||
} else {
|
||||
bucket.setLoggingConfiguration(loggingConfigurationXml);
|
||||
}
|
||||
}
|
||||
|
||||
bucketStore.put(bucketName, bucket);
|
||||
}
|
||||
|
||||
public String getBucketLogging(String bucketName) {
|
||||
Bucket bucket = bucketStore.get(bucketName)
|
||||
.orElseThrow(() -> new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404));
|
||||
|
||||
if (bucket.getLoggingConfiguration() == null || bucket.getLoggingConfiguration().isBlank()) {
|
||||
return new XmlBuilder()
|
||||
.raw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
||||
.start("BucketLoggingStatus", AwsNamespaces.S3)
|
||||
.end("BucketLoggingStatus")
|
||||
.build();
|
||||
}
|
||||
|
||||
return bucket.getLoggingConfiguration();
|
||||
}
|
||||
|
||||
public S3Object putObject(String bucketName, String key, byte[] data,
|
||||
String contentType, Map<String, String> metadata) {
|
||||
return putObject(bucketName, key, data, contentType, metadata, new PutObjectOptions());
|
||||
|
||||
@@ -14,6 +14,7 @@ public class Bucket {
|
||||
private String name;
|
||||
private Instant creationDate;
|
||||
private String versioningStatus; // null (never enabled), "Enabled", "Suspended"
|
||||
private String loggingConfiguration;
|
||||
private Map<String, String> tags;
|
||||
private NotificationConfiguration notificationConfiguration;
|
||||
private boolean objectLockEnabled;
|
||||
@@ -49,6 +50,14 @@ public class Bucket {
|
||||
public String getVersioningStatus() { return versioningStatus; }
|
||||
public void setVersioningStatus(String versioningStatus) { this.versioningStatus = versioningStatus; }
|
||||
|
||||
public String getLoggingConfiguration() {
|
||||
return loggingConfiguration;
|
||||
}
|
||||
|
||||
public void setLoggingConfiguration(String loggingConfiguration) {
|
||||
this.loggingConfiguration = loggingConfiguration;
|
||||
}
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user