diff --git a/src/main/java/gyro/aws/wafv2/IpSetForwardedIpConfigResource.java b/src/main/java/gyro/aws/wafv2/IpSetForwardedIpConfigResource.java new file mode 100644 index 000000000..904b0f9d9 --- /dev/null +++ b/src/main/java/gyro/aws/wafv2/IpSetForwardedIpConfigResource.java @@ -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 { + + 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(); + } +} diff --git a/src/main/java/gyro/aws/wafv2/IpSetReferenceStatementResource.java b/src/main/java/gyro/aws/wafv2/IpSetReferenceStatementResource.java index b77042ba2..8acdb2858 100644 --- a/src/main/java/gyro/aws/wafv2/IpSetReferenceStatementResource.java +++ b/src/main/java/gyro/aws/wafv2/IpSetReferenceStatementResource.java @@ -25,6 +25,7 @@ public class IpSetReferenceStatementResource extends Diffable implements Copyable { private IpSetResource ipSet; + private IpSetForwardedIpConfigResource ipSetForwardedIpConfig; /** * The ip set resource to associate with. @@ -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 @@ -51,6 +72,7 @@ public String primaryKey() { IPSetReferenceStatement toIpSetReferenceStatement() { return IPSetReferenceStatement.builder() + .ipSetForwardedIPConfig(getIpSetForwardedIpConfig() != null ? getIpSetForwardedIpConfig().toForwardedIPConfig() : null) .arn(getIpSet().getArn()) .build(); }