Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support in WafV2 for forwarded ip config in IP Ref Statement #629

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading