All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.securityhub.model.AwsWafRateBasedRuleDetails Maven / Gradle / Ivy

/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.services.securityhub.model;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;

/**
 * 

* Details about a rate-based rule for global resources. A rate-based rule provides settings to indicate when to allow, * block, or count a request. Rate-based rules include the number of requests that arrive over a specified period of * time. *

*/ @Generated("software.amazon.awssdk:codegen") public final class AwsWafRateBasedRuleDetails implements SdkPojo, Serializable, ToCopyableBuilder { private static final SdkField METRIC_NAME_FIELD = SdkField. builder(MarshallingType.STRING) .memberName("MetricName").getter(getter(AwsWafRateBasedRuleDetails::metricName)).setter(setter(Builder::metricName)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("MetricName").build()).build(); private static final SdkField NAME_FIELD = SdkField. builder(MarshallingType.STRING).memberName("Name") .getter(getter(AwsWafRateBasedRuleDetails::name)).setter(setter(Builder::name)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Name").build()).build(); private static final SdkField RATE_KEY_FIELD = SdkField. builder(MarshallingType.STRING) .memberName("RateKey").getter(getter(AwsWafRateBasedRuleDetails::rateKey)).setter(setter(Builder::rateKey)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("RateKey").build()).build(); private static final SdkField RATE_LIMIT_FIELD = SdkField. builder(MarshallingType.LONG).memberName("RateLimit") .getter(getter(AwsWafRateBasedRuleDetails::rateLimit)).setter(setter(Builder::rateLimit)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("RateLimit").build()).build(); private static final SdkField RULE_ID_FIELD = SdkField. builder(MarshallingType.STRING).memberName("RuleId") .getter(getter(AwsWafRateBasedRuleDetails::ruleId)).setter(setter(Builder::ruleId)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("RuleId").build()).build(); private static final SdkField> MATCH_PREDICATES_FIELD = SdkField .> builder(MarshallingType.LIST) .memberName("MatchPredicates") .getter(getter(AwsWafRateBasedRuleDetails::matchPredicates)) .setter(setter(Builder::matchPredicates)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("MatchPredicates").build(), ListTrait .builder() .memberLocationName(null) .memberFieldInfo( SdkField. builder(MarshallingType.SDK_POJO) .constructor(AwsWafRateBasedRuleMatchPredicate::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD) .locationName("member").build()).build()).build()).build(); private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(METRIC_NAME_FIELD, NAME_FIELD, RATE_KEY_FIELD, RATE_LIMIT_FIELD, RULE_ID_FIELD, MATCH_PREDICATES_FIELD)); private static final long serialVersionUID = 1L; private final String metricName; private final String name; private final String rateKey; private final Long rateLimit; private final String ruleId; private final List matchPredicates; private AwsWafRateBasedRuleDetails(BuilderImpl builder) { this.metricName = builder.metricName; this.name = builder.name; this.rateKey = builder.rateKey; this.rateLimit = builder.rateLimit; this.ruleId = builder.ruleId; this.matchPredicates = builder.matchPredicates; } /** *

* The name of the metrics for the rate-based rule. *

* * @return The name of the metrics for the rate-based rule. */ public final String metricName() { return metricName; } /** *

* The name of the rate-based rule. *

* * @return The name of the rate-based rule. */ public final String name() { return name; } /** *

* The field that WAF uses to determine whether requests are likely arriving from single source and are subject to * rate monitoring. *

* * @return The field that WAF uses to determine whether requests are likely arriving from single source and are * subject to rate monitoring. */ public final String rateKey() { return rateKey; } /** *

* The maximum number of requests that have an identical value for the field specified in RateKey that * are allowed within a five-minute period. If the number of requests exceeds RateLimit and the other * predicates specified in the rule are met, WAF triggers the action for the rule. *

* * @return The maximum number of requests that have an identical value for the field specified in * RateKey that are allowed within a five-minute period. If the number of requests exceeds * RateLimit and the other predicates specified in the rule are met, WAF triggers the action * for the rule. */ public final Long rateLimit() { return rateLimit; } /** *

* The unique identifier for the rate-based rule. *

* * @return The unique identifier for the rate-based rule. */ public final String ruleId() { return ruleId; } /** * For responses, this returns true if the service returned a value for the MatchPredicates property. This DOES NOT * check that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). * This is useful because the SDK will never return a null collection or map, but you may need to differentiate * between the service returning nothing (or null) and the service returning an empty collection or map. For * requests, this returns true if a value for the property was specified in the request builder, and false if a * value was not specified. */ public final boolean hasMatchPredicates() { return matchPredicates != null && !(matchPredicates instanceof SdkAutoConstructList); } /** *

* The predicates to include in the rate-based rule. *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

*

* This method will never return null. If you would like to know whether the service returned this field (so that * you can differentiate between null and empty), you can use the {@link #hasMatchPredicates} method. *

* * @return The predicates to include in the rate-based rule. */ public final List matchPredicates() { return matchPredicates; } @Override public Builder toBuilder() { return new BuilderImpl(this); } public static Builder builder() { return new BuilderImpl(); } public static Class serializableBuilderClass() { return BuilderImpl.class; } @Override public final int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(metricName()); hashCode = 31 * hashCode + Objects.hashCode(name()); hashCode = 31 * hashCode + Objects.hashCode(rateKey()); hashCode = 31 * hashCode + Objects.hashCode(rateLimit()); hashCode = 31 * hashCode + Objects.hashCode(ruleId()); hashCode = 31 * hashCode + Objects.hashCode(hasMatchPredicates() ? matchPredicates() : null); return hashCode; } @Override public final boolean equals(Object obj) { return equalsBySdkFields(obj); } @Override public final boolean equalsBySdkFields(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof AwsWafRateBasedRuleDetails)) { return false; } AwsWafRateBasedRuleDetails other = (AwsWafRateBasedRuleDetails) obj; return Objects.equals(metricName(), other.metricName()) && Objects.equals(name(), other.name()) && Objects.equals(rateKey(), other.rateKey()) && Objects.equals(rateLimit(), other.rateLimit()) && Objects.equals(ruleId(), other.ruleId()) && hasMatchPredicates() == other.hasMatchPredicates() && Objects.equals(matchPredicates(), other.matchPredicates()); } /** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. */ @Override public final String toString() { return ToString.builder("AwsWafRateBasedRuleDetails").add("MetricName", metricName()).add("Name", name()) .add("RateKey", rateKey()).add("RateLimit", rateLimit()).add("RuleId", ruleId()) .add("MatchPredicates", hasMatchPredicates() ? matchPredicates() : null).build(); } public final Optional getValueForField(String fieldName, Class clazz) { switch (fieldName) { case "MetricName": return Optional.ofNullable(clazz.cast(metricName())); case "Name": return Optional.ofNullable(clazz.cast(name())); case "RateKey": return Optional.ofNullable(clazz.cast(rateKey())); case "RateLimit": return Optional.ofNullable(clazz.cast(rateLimit())); case "RuleId": return Optional.ofNullable(clazz.cast(ruleId())); case "MatchPredicates": return Optional.ofNullable(clazz.cast(matchPredicates())); default: return Optional.empty(); } } @Override public final List> sdkFields() { return SDK_FIELDS; } private static Function getter(Function g) { return obj -> g.apply((AwsWafRateBasedRuleDetails) obj); } private static BiConsumer setter(BiConsumer s) { return (obj, val) -> s.accept((Builder) obj, val); } public interface Builder extends SdkPojo, CopyableBuilder { /** *

* The name of the metrics for the rate-based rule. *

* * @param metricName * The name of the metrics for the rate-based rule. * @return Returns a reference to this object so that method calls can be chained together. */ Builder metricName(String metricName); /** *

* The name of the rate-based rule. *

* * @param name * The name of the rate-based rule. * @return Returns a reference to this object so that method calls can be chained together. */ Builder name(String name); /** *

* The field that WAF uses to determine whether requests are likely arriving from single source and are subject * to rate monitoring. *

* * @param rateKey * The field that WAF uses to determine whether requests are likely arriving from single source and are * subject to rate monitoring. * @return Returns a reference to this object so that method calls can be chained together. */ Builder rateKey(String rateKey); /** *

* The maximum number of requests that have an identical value for the field specified in RateKey * that are allowed within a five-minute period. If the number of requests exceeds RateLimit and * the other predicates specified in the rule are met, WAF triggers the action for the rule. *

* * @param rateLimit * The maximum number of requests that have an identical value for the field specified in * RateKey that are allowed within a five-minute period. If the number of requests exceeds * RateLimit and the other predicates specified in the rule are met, WAF triggers the action * for the rule. * @return Returns a reference to this object so that method calls can be chained together. */ Builder rateLimit(Long rateLimit); /** *

* The unique identifier for the rate-based rule. *

* * @param ruleId * The unique identifier for the rate-based rule. * @return Returns a reference to this object so that method calls can be chained together. */ Builder ruleId(String ruleId); /** *

* The predicates to include in the rate-based rule. *

* * @param matchPredicates * The predicates to include in the rate-based rule. * @return Returns a reference to this object so that method calls can be chained together. */ Builder matchPredicates(Collection matchPredicates); /** *

* The predicates to include in the rate-based rule. *

* * @param matchPredicates * The predicates to include in the rate-based rule. * @return Returns a reference to this object so that method calls can be chained together. */ Builder matchPredicates(AwsWafRateBasedRuleMatchPredicate... matchPredicates); /** *

* The predicates to include in the rate-based rule. *

* This is a convenience method that creates an instance of the * {@link software.amazon.awssdk.services.securityhub.model.AwsWafRateBasedRuleMatchPredicate.Builder} avoiding * the need to create one manually via * {@link software.amazon.awssdk.services.securityhub.model.AwsWafRateBasedRuleMatchPredicate#builder()}. * *

* When the {@link Consumer} completes, * {@link software.amazon.awssdk.services.securityhub.model.AwsWafRateBasedRuleMatchPredicate.Builder#build()} * is called immediately and its result is passed to {@link * #matchPredicates(List)}. * * @param matchPredicates * a consumer that will call methods on * {@link software.amazon.awssdk.services.securityhub.model.AwsWafRateBasedRuleMatchPredicate.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #matchPredicates(java.util.Collection) */ Builder matchPredicates(Consumer... matchPredicates); } static final class BuilderImpl implements Builder { private String metricName; private String name; private String rateKey; private Long rateLimit; private String ruleId; private List matchPredicates = DefaultSdkAutoConstructList.getInstance(); private BuilderImpl() { } private BuilderImpl(AwsWafRateBasedRuleDetails model) { metricName(model.metricName); name(model.name); rateKey(model.rateKey); rateLimit(model.rateLimit); ruleId(model.ruleId); matchPredicates(model.matchPredicates); } public final String getMetricName() { return metricName; } public final void setMetricName(String metricName) { this.metricName = metricName; } @Override public final Builder metricName(String metricName) { this.metricName = metricName; return this; } public final String getName() { return name; } public final void setName(String name) { this.name = name; } @Override public final Builder name(String name) { this.name = name; return this; } public final String getRateKey() { return rateKey; } public final void setRateKey(String rateKey) { this.rateKey = rateKey; } @Override public final Builder rateKey(String rateKey) { this.rateKey = rateKey; return this; } public final Long getRateLimit() { return rateLimit; } public final void setRateLimit(Long rateLimit) { this.rateLimit = rateLimit; } @Override public final Builder rateLimit(Long rateLimit) { this.rateLimit = rateLimit; return this; } public final String getRuleId() { return ruleId; } public final void setRuleId(String ruleId) { this.ruleId = ruleId; } @Override public final Builder ruleId(String ruleId) { this.ruleId = ruleId; return this; } public final List getMatchPredicates() { List result = AwsWafRateBasedRuleMatchPredicateListCopier .copyToBuilder(this.matchPredicates); if (result instanceof SdkAutoConstructList) { return null; } return result; } public final void setMatchPredicates(Collection matchPredicates) { this.matchPredicates = AwsWafRateBasedRuleMatchPredicateListCopier.copyFromBuilder(matchPredicates); } @Override public final Builder matchPredicates(Collection matchPredicates) { this.matchPredicates = AwsWafRateBasedRuleMatchPredicateListCopier.copy(matchPredicates); return this; } @Override @SafeVarargs public final Builder matchPredicates(AwsWafRateBasedRuleMatchPredicate... matchPredicates) { matchPredicates(Arrays.asList(matchPredicates)); return this; } @Override @SafeVarargs public final Builder matchPredicates(Consumer... matchPredicates) { matchPredicates(Stream.of(matchPredicates) .map(c -> AwsWafRateBasedRuleMatchPredicate.builder().applyMutation(c).build()).collect(Collectors.toList())); return this; } @Override public AwsWafRateBasedRuleDetails build() { return new AwsWafRateBasedRuleDetails(this); } @Override public List> sdkFields() { return SDK_FIELDS; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy