Skip to content

Commit

Permalink
Merge pull request #629 from perfectsense/feature/support-fwd-ip-config
Browse files Browse the repository at this point in the history
Add support in WafV2 for forwarded ip config in IP Ref Statement
  • Loading branch information
deepanjan90 authored Mar 4, 2024
2 parents 2a9d79f + d03116a commit 137411c
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
94 changes: 94 additions & 0 deletions src/main/java/gyro/aws/wafv2/IpSetForwardedIpConfigResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 2024, Brightspot.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package gyro.aws.wafv2;

import gyro.aws.Copyable;
import gyro.core.resource.Diffable;
import gyro.core.resource.Updatable;
import gyro.core.validation.Required;
import gyro.core.validation.ValidStrings;
import software.amazon.awssdk.services.wafv2.model.FallbackBehavior;
import software.amazon.awssdk.services.wafv2.model.ForwardedIPPosition;
import software.amazon.awssdk.services.wafv2.model.IPSetForwardedIPConfig;

public class IpSetForwardedIpConfigResource extends Diffable implements Copyable<IPSetForwardedIPConfig> {

private String headerName;
private FallbackBehavior fallbackBehavior;
private ForwardedIPPosition position;

/**
* The name of the header to use for the forwarded IP.
*/
@Required
@Updatable
public String getHeaderName() {
return headerName;
}

public void setHeaderName(String headerName) {
this.headerName = headerName;
}

/**
* The fallback behavior for the forwarded IP.
*/
@Required
@Updatable
@ValidStrings({ "MATCH", "NO_MATCH" })
public FallbackBehavior getFallbackBehavior() {
return fallbackBehavior;
}

public void setFallbackBehavior(FallbackBehavior fallbackBehavior) {
this.fallbackBehavior = fallbackBehavior;
}

/**
* The position of the forwarded IP.
*/
@Required
@Updatable
@ValidStrings({ "FIRST", "LAST", "ANY" })
public ForwardedIPPosition getPosition() {
return position;
}

public void setPosition(ForwardedIPPosition position) {
this.position = position;
}

@Override
public void copyFrom(IPSetForwardedIPConfig model) {
setHeaderName(model.headerName());
setFallbackBehavior(model.fallbackBehavior());
setPosition(model.position());
}

@Override
public String primaryKey() {
return "";
}

public IPSetForwardedIPConfig toForwardedIPConfig() {
return IPSetForwardedIPConfig.builder()
.headerName(getHeaderName())
.fallbackBehavior(getFallbackBehavior())
.position(getPosition() != null ? getPosition() : null)
.build();
}
}
22 changes: 22 additions & 0 deletions src/main/java/gyro/aws/wafv2/IpSetReferenceStatementResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class IpSetReferenceStatementResource extends Diffable implements Copyable<IPSetReferenceStatement> {

private IpSetResource ipSet;
private IpSetForwardedIpConfigResource ipSetForwardedIpConfig;

/**
* The ip set resource to associate with.
Expand All @@ -39,9 +40,29 @@ public void setIpSet(IpSetResource ipSet) {
this.ipSet = ipSet;
}

/**
* The forwarded IP configuration for the ip set.
*
* @subresource gyro.aws.wafv2.IpSetForwardedIpConfigResource
*/
@Updatable
public IpSetForwardedIpConfigResource getIpSetForwardedIpConfig() {
return ipSetForwardedIpConfig;
}

public void setIpSetForwardedIpConfig(IpSetForwardedIpConfigResource ipSetForwardedIpConfig) {
this.ipSetForwardedIpConfig = ipSetForwardedIpConfig;
}

@Override
public void copyFrom(IPSetReferenceStatement ipSetReferenceStatement) {
setIpSet(findById(IpSetResource.class, ipSetReferenceStatement.arn()));
setIpSetForwardedIpConfig(null);
if (ipSetReferenceStatement.ipSetForwardedIPConfig() != null) {
IpSetForwardedIpConfigResource ipSetForwardedIpConfigResource = newSubresource(IpSetForwardedIpConfigResource.class);
ipSetForwardedIpConfigResource.copyFrom(ipSetReferenceStatement.ipSetForwardedIPConfig());
setIpSetForwardedIpConfig(ipSetForwardedIpConfigResource);
}
}

@Override
Expand All @@ -51,6 +72,7 @@ public String primaryKey() {

IPSetReferenceStatement toIpSetReferenceStatement() {
return IPSetReferenceStatement.builder()
.ipSetForwardedIPConfig(getIpSetForwardedIpConfig() != null ? getIpSetForwardedIpConfig().toForwardedIPConfig() : null)
.arn(getIpSet().getArn())
.build();
}
Expand Down

0 comments on commit 137411c

Please sign in to comment.