Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
feature: enable s3 prefix in waf logging (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayitbeegh authored Apr 17, 2020
1 parent d0649e7 commit 191b581
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public boolean isSkipStackCreation() {
return skipStackCreation;
}

@Parameter(names = {"--s3-prefix"}, description = "The prefix of WAF logs in S3 bucket.")
private String s3Prefix = "firehose/";

public String getS3Prefix() {
return s3Prefix;
}

public CloudFormationParametersDelegate getCloudFormationParametersDelegate() {
return cloudFormationParametersDelegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
public class WafLoggingParameters {
private String environmentName;

private String s3Prefix;

public String getS3Prefix() {
return s3Prefix;
}

public WafLoggingParameters setS3Prefix(String s3Prefix) {
this.s3Prefix = s3Prefix;
return this;
}

public String getEnvironmentName() {
return environmentName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,18 @@ public CreateWafLoggingOperation(@Named(ENV_NAME) String environmentName,
public void run(CreateWafLoggingCommand command) {
Regions region = command.getCloudFormationParametersDelegate().getStackRegion()
.orElse(configStore.getPrimaryRegion());
String s3Prefix = command.getS3Prefix();
if (!s3Prefix.endsWith("/")) {
s3Prefix += "/";
}
if (s3Prefix.startsWith("/")) {
s3Prefix = s3Prefix.substring(1);
}

if (!command.isSkipStackCreation()) {
WafLoggingParameters wafLoggingParameters = new WafLoggingParameters()
.setEnvironmentName(environmentName);
.setEnvironmentName(environmentName)
.setS3Prefix(s3Prefix);

Map<String, String> parameters = cloudFormationObjectMapper.convertValue(wafLoggingParameters);

Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/cloudformation/waf-logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Parameters:
environmentName:
Description: The Cerberus environment name.
Type: String
s3Prefix:
Description: The prefix of WAF logs in S3 bucket.
Type: String
Resources:
KinesisFirehoseDeliveryStream:
Type: 'AWS::KinesisFirehose::DeliveryStream'
Expand All @@ -28,7 +31,7 @@ Resources:
IntervalInSeconds: 300
SizeInMBs: 5
CompressionFormat: UNCOMPRESSED
Prefix: firehose/
Prefix: !Ref s3Prefix
RoleARN: !GetAtt DeliveryRole.Arn
S3DestinationBucket:
Type: AWS::S3::Bucket
Expand Down

0 comments on commit 191b581

Please sign in to comment.