mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(redshift): accept s3table log destination and reject mutual snapshot restore params (#4340)
* fix(redshift): accept s3table log destination and reject mutual snapshot restore params Closes #4242 * fix(redshift): preserve S3-table logging configuration and report status Pass S3TableKmsKeyId and S3TableGranularity through EnableLogging, store them on Cluster, and serialize S3Tables in LoggingStatus responses. * fix(redshift): validate S3-table logging settings * fix(redshift): complete S3 table logging status
This commit is contained in:
1 parent
41d07f6e3b
commit
6bdf14210e
7 files changed
+343
-7
No files matched your search
+27
-3
@@ -667,7 +667,9 @@ public class RedshiftQueryHandler {
|
||||
String clusterIdentifier = requireParam(params, "ClusterIdentifier");
|
||||
Cluster cluster = service.enableLogging(clusterIdentifier, params.getFirst("BucketName"),
|
||||
params.getFirst("S3KeyPrefix"), params.getFirst("LogDestinationType"),
|
||||
memberList(params, "LogExports"));
|
||||
memberList(params, "LogExports"),
|
||||
params.getFirst("S3TableKmsKeyId"),
|
||||
params.getFirst("S3TableGranularity"));
|
||||
return loggingStatusResponse(action, cluster);
|
||||
}
|
||||
case "DisableLogging" -> {
|
||||
@@ -871,10 +873,16 @@ public class RedshiftQueryHandler {
|
||||
|
||||
// RestoreFromClusterSnapshot accepts SnapshotIdentifier or SnapshotArn.
|
||||
private String resolveSnapshotIdentifier(String snapshotIdentifier, String snapshotArn, String authorizationHeader) {
|
||||
if (snapshotIdentifier != null && !snapshotIdentifier.isBlank()) {
|
||||
boolean hasIdentifier = snapshotIdentifier != null && !snapshotIdentifier.isBlank();
|
||||
boolean hasArn = snapshotArn != null && !snapshotArn.isBlank();
|
||||
if (hasIdentifier && hasArn) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"You must specify either SnapshotIdentifier or SnapshotArn, but not both.", 400);
|
||||
}
|
||||
if (hasIdentifier) {
|
||||
return snapshotIdentifier;
|
||||
}
|
||||
if (snapshotArn == null || snapshotArn.isBlank()) {
|
||||
if (!hasArn) {
|
||||
throw new AwsException("InvalidParameterValue", "SnapshotIdentifier or SnapshotArn is required", 400);
|
||||
}
|
||||
AwsArnUtils.Arn arn;
|
||||
@@ -944,6 +952,22 @@ public class RedshiftQueryHandler {
|
||||
}
|
||||
builder.end("LogExports");
|
||||
}
|
||||
if ("s3table".equalsIgnoreCase(cluster.getLoggingDestinationType())) {
|
||||
builder.start("S3Tables");
|
||||
List<String> exports = cluster.getLoggingExports();
|
||||
if (exports != null && !exports.isEmpty()) {
|
||||
builder.start("S3Tables");
|
||||
for (String export : exports) {
|
||||
builder.elem("member", export);
|
||||
}
|
||||
builder.end("S3Tables");
|
||||
}
|
||||
if (cluster.getLoggingS3TableGranularity() != null) {
|
||||
builder.elem("S3TableGranularity", cluster.getLoggingS3TableGranularity());
|
||||
}
|
||||
builder.elem("EnabledAll", exports == null || exports.isEmpty() || exports.contains("all"));
|
||||
builder.end("S3Tables");
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -732,10 +732,26 @@ public class RedshiftService {
|
||||
|
||||
public synchronized Cluster enableLogging(String clusterIdentifier, String bucketName, String s3KeyPrefix,
|
||||
String logDestinationType, List<String> logExports) {
|
||||
return enableLogging(clusterIdentifier, bucketName, s3KeyPrefix, logDestinationType, logExports, null, null);
|
||||
}
|
||||
|
||||
public synchronized Cluster enableLogging(String clusterIdentifier, String bucketName, String s3KeyPrefix,
|
||||
String logDestinationType, List<String> logExports,
|
||||
String s3TableKmsKeyId, String s3TableGranularity) {
|
||||
Cluster cluster = clusters.get(clusterIdentifier)
|
||||
.orElseThrow(() -> new AwsException("ClusterNotFound", "Cluster " + clusterIdentifier + " not found", 404));
|
||||
boolean cloudWatch = "cloudwatch".equalsIgnoreCase(logDestinationType);
|
||||
if (!cloudWatch && (bucketName == null || bucketName.isBlank())) {
|
||||
boolean s3Table = "s3table".equalsIgnoreCase(logDestinationType);
|
||||
if (s3Table && s3TableGranularity != null
|
||||
&& !List.of("cluster", "account").contains(s3TableGranularity)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"S3TableGranularity must be cluster or account", 400);
|
||||
}
|
||||
if (!s3Table && (s3TableKmsKeyId != null || s3TableGranularity != null)) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"S3-table logging settings are valid only when LogDestinationType is s3table", 400);
|
||||
}
|
||||
if (!cloudWatch && !s3Table && (bucketName == null || bucketName.isBlank())) {
|
||||
throw new AwsException("InvalidParameterValue", "BucketName is required for an S3 log destination", 400);
|
||||
}
|
||||
cluster.setLoggingEnabled(true);
|
||||
@@ -743,6 +759,8 @@ public class RedshiftService {
|
||||
cluster.setLoggingDestinationType(logDestinationType);
|
||||
cluster.setLoggingExports(logExports == null || logExports.isEmpty() ? null : List.copyOf(logExports));
|
||||
cluster.setLoggingS3KeyPrefix(s3KeyPrefix);
|
||||
cluster.setLoggingS3TableKmsKeyId(s3TableKmsKeyId);
|
||||
cluster.setLoggingS3TableGranularity(s3TableGranularity);
|
||||
clusters.put(clusterIdentifier, cluster);
|
||||
clusters.flush();
|
||||
return cluster;
|
||||
@@ -756,6 +774,8 @@ public class RedshiftService {
|
||||
cluster.setLoggingS3KeyPrefix(null);
|
||||
cluster.setLoggingDestinationType(null);
|
||||
cluster.setLoggingExports(null);
|
||||
cluster.setLoggingS3TableKmsKeyId(null);
|
||||
cluster.setLoggingS3TableGranularity(null);
|
||||
clusters.put(clusterIdentifier, cluster);
|
||||
clusters.flush();
|
||||
return cluster;
|
||||
|
||||
@@ -60,11 +60,17 @@ public class Cluster {
|
||||
|
||||
private String loggingDestinationType;
|
||||
private List<String> loggingExports;
|
||||
private String loggingS3TableKmsKeyId;
|
||||
private String loggingS3TableGranularity;
|
||||
|
||||
public String getLoggingDestinationType() { return loggingDestinationType; }
|
||||
public void setLoggingDestinationType(String loggingDestinationType) { this.loggingDestinationType = loggingDestinationType; }
|
||||
public List<String> getLoggingExports() { return loggingExports; }
|
||||
public void setLoggingExports(List<String> loggingExports) { this.loggingExports = loggingExports; }
|
||||
public String getLoggingS3TableKmsKeyId() { return loggingS3TableKmsKeyId; }
|
||||
public void setLoggingS3TableKmsKeyId(String loggingS3TableKmsKeyId) { this.loggingS3TableKmsKeyId = loggingS3TableKmsKeyId; }
|
||||
public String getLoggingS3TableGranularity() { return loggingS3TableGranularity; }
|
||||
public void setLoggingS3TableGranularity(String loggingS3TableGranularity) { this.loggingS3TableGranularity = loggingS3TableGranularity; }
|
||||
|
||||
private boolean multiAZ = false;
|
||||
|
||||
|
||||
Reference in new issue
Block a user