software.amazon.awssdk.services.s3.model.CORSRule Maven / Gradle / Ivy
Show all versions of s3 Show documentation
/*
* 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.s3.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.Function;
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.traits.RequiredTrait;
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;
/**
*
* Specifies a cross-origin access rule for an Amazon S3 bucket.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class CORSRule implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField ID_FIELD = SdkField
. builder(MarshallingType.STRING)
.memberName("ID")
.getter(getter(CORSRule::id))
.setter(setter(Builder::id))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ID").unmarshallLocationName("ID")
.build()).build();
private static final SdkField> ALLOWED_HEADERS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("AllowedHeaders")
.getter(getter(CORSRule::allowedHeaders))
.setter(setter(Builder::allowedHeaders))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("AllowedHeader")
.unmarshallLocationName("AllowedHeader").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.STRING)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").unmarshallLocationName("member").build()).build())
.isFlattened(true).build()).build();
private static final SdkField> ALLOWED_METHODS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("AllowedMethods")
.getter(getter(CORSRule::allowedMethods))
.setter(setter(Builder::allowedMethods))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("AllowedMethod")
.unmarshallLocationName("AllowedMethod").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.STRING)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").unmarshallLocationName("member").build()).build())
.isFlattened(true).build(), RequiredTrait.create()).build();
private static final SdkField> ALLOWED_ORIGINS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("AllowedOrigins")
.getter(getter(CORSRule::allowedOrigins))
.setter(setter(Builder::allowedOrigins))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("AllowedOrigin")
.unmarshallLocationName("AllowedOrigin").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.STRING)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").unmarshallLocationName("member").build()).build())
.isFlattened(true).build(), RequiredTrait.create()).build();
private static final SdkField> EXPOSE_HEADERS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("ExposeHeaders")
.getter(getter(CORSRule::exposeHeaders))
.setter(setter(Builder::exposeHeaders))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ExposeHeader")
.unmarshallLocationName("ExposeHeader").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.STRING)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").unmarshallLocationName("member").build()).build())
.isFlattened(true).build()).build();
private static final SdkField MAX_AGE_SECONDS_FIELD = SdkField
. builder(MarshallingType.INTEGER)
.memberName("MaxAgeSeconds")
.getter(getter(CORSRule::maxAgeSeconds))
.setter(setter(Builder::maxAgeSeconds))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("MaxAgeSeconds")
.unmarshallLocationName("MaxAgeSeconds").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(ID_FIELD,
ALLOWED_HEADERS_FIELD, ALLOWED_METHODS_FIELD, ALLOWED_ORIGINS_FIELD, EXPOSE_HEADERS_FIELD, MAX_AGE_SECONDS_FIELD));
private static final long serialVersionUID = 1L;
private final String id;
private final List allowedHeaders;
private final List allowedMethods;
private final List allowedOrigins;
private final List exposeHeaders;
private final Integer maxAgeSeconds;
private CORSRule(BuilderImpl builder) {
this.id = builder.id;
this.allowedHeaders = builder.allowedHeaders;
this.allowedMethods = builder.allowedMethods;
this.allowedOrigins = builder.allowedOrigins;
this.exposeHeaders = builder.exposeHeaders;
this.maxAgeSeconds = builder.maxAgeSeconds;
}
/**
*
* Unique identifier for the rule. The value cannot be longer than 255 characters.
*
*
* @return Unique identifier for the rule. The value cannot be longer than 255 characters.
*/
public final String id() {
return id;
}
/**
* For responses, this returns true if the service returned a value for the AllowedHeaders 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 hasAllowedHeaders() {
return allowedHeaders != null && !(allowedHeaders instanceof SdkAutoConstructList);
}
/**
*
* Headers that are specified in the Access-Control-Request-Headers
header. These headers are allowed
* in a preflight OPTIONS request. In response to any preflight OPTIONS request, Amazon S3 returns any requested
* headers that are allowed.
*
*
* 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 #hasAllowedHeaders} method.
*
*
* @return Headers that are specified in the Access-Control-Request-Headers
header. These headers are
* allowed in a preflight OPTIONS request. In response to any preflight OPTIONS request, Amazon S3 returns
* any requested headers that are allowed.
*/
public final List allowedHeaders() {
return allowedHeaders;
}
/**
* For responses, this returns true if the service returned a value for the AllowedMethods 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 hasAllowedMethods() {
return allowedMethods != null && !(allowedMethods instanceof SdkAutoConstructList);
}
/**
*
* An HTTP method that you allow the origin to execute. Valid values are GET
, PUT
,
* HEAD
, POST
, and DELETE
.
*
*
* 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 #hasAllowedMethods} method.
*
*
* @return An HTTP method that you allow the origin to execute. Valid values are GET
, PUT
,
* HEAD
, POST
, and DELETE
.
*/
public final List allowedMethods() {
return allowedMethods;
}
/**
* For responses, this returns true if the service returned a value for the AllowedOrigins 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 hasAllowedOrigins() {
return allowedOrigins != null && !(allowedOrigins instanceof SdkAutoConstructList);
}
/**
*
* One or more origins you want customers to be able to access the bucket from.
*
*
* 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 #hasAllowedOrigins} method.
*
*
* @return One or more origins you want customers to be able to access the bucket from.
*/
public final List allowedOrigins() {
return allowedOrigins;
}
/**
* For responses, this returns true if the service returned a value for the ExposeHeaders 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 hasExposeHeaders() {
return exposeHeaders != null && !(exposeHeaders instanceof SdkAutoConstructList);
}
/**
*
* One or more headers in the response that you want customers to be able to access from their applications (for
* example, from a JavaScript XMLHttpRequest
object).
*
*
* 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 #hasExposeHeaders} method.
*
*
* @return One or more headers in the response that you want customers to be able to access from their applications
* (for example, from a JavaScript XMLHttpRequest
object).
*/
public final List exposeHeaders() {
return exposeHeaders;
}
/**
*
* The time in seconds that your browser is to cache the preflight response for the specified resource.
*
*
* @return The time in seconds that your browser is to cache the preflight response for the specified resource.
*/
public final Integer maxAgeSeconds() {
return maxAgeSeconds;
}
@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(id());
hashCode = 31 * hashCode + Objects.hashCode(hasAllowedHeaders() ? allowedHeaders() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasAllowedMethods() ? allowedMethods() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasAllowedOrigins() ? allowedOrigins() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasExposeHeaders() ? exposeHeaders() : null);
hashCode = 31 * hashCode + Objects.hashCode(maxAgeSeconds());
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 CORSRule)) {
return false;
}
CORSRule other = (CORSRule) obj;
return Objects.equals(id(), other.id()) && hasAllowedHeaders() == other.hasAllowedHeaders()
&& Objects.equals(allowedHeaders(), other.allowedHeaders()) && hasAllowedMethods() == other.hasAllowedMethods()
&& Objects.equals(allowedMethods(), other.allowedMethods()) && hasAllowedOrigins() == other.hasAllowedOrigins()
&& Objects.equals(allowedOrigins(), other.allowedOrigins()) && hasExposeHeaders() == other.hasExposeHeaders()
&& Objects.equals(exposeHeaders(), other.exposeHeaders())
&& Objects.equals(maxAgeSeconds(), other.maxAgeSeconds());
}
/**
* 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("CORSRule").add("ID", id()).add("AllowedHeaders", hasAllowedHeaders() ? allowedHeaders() : null)
.add("AllowedMethods", hasAllowedMethods() ? allowedMethods() : null)
.add("AllowedOrigins", hasAllowedOrigins() ? allowedOrigins() : null)
.add("ExposeHeaders", hasExposeHeaders() ? exposeHeaders() : null).add("MaxAgeSeconds", maxAgeSeconds()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "ID":
return Optional.ofNullable(clazz.cast(id()));
case "AllowedHeaders":
return Optional.ofNullable(clazz.cast(allowedHeaders()));
case "AllowedMethods":
return Optional.ofNullable(clazz.cast(allowedMethods()));
case "AllowedOrigins":
return Optional.ofNullable(clazz.cast(allowedOrigins()));
case "ExposeHeaders":
return Optional.ofNullable(clazz.cast(exposeHeaders()));
case "MaxAgeSeconds":
return Optional.ofNullable(clazz.cast(maxAgeSeconds()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function