
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 extends Builder> 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