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.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> 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()).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()).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(ALLOWED_HEADERS_FIELD,
ALLOWED_METHODS_FIELD, ALLOWED_ORIGINS_FIELD, EXPOSE_HEADERS_FIELD, MAX_AGE_SECONDS_FIELD));
private static final long serialVersionUID = 1L;
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.allowedHeaders = builder.allowedHeaders;
this.allowedMethods = builder.allowedMethods;
this.allowedOrigins = builder.allowedOrigins;
this.exposeHeaders = builder.exposeHeaders;
this.maxAgeSeconds = builder.maxAgeSeconds;
}
/**
* Returns true if the AllowedHeaders property was specified by the sender (it may be empty), or false if the sender
* did not specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
*/
public 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.
*
*
* You can use {@link #hasAllowedHeaders()} to see if a value was sent in this field.
*
*
* @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 List allowedHeaders() {
return allowedHeaders;
}
/**
* Returns true if the AllowedMethods property was specified by the sender (it may be empty), or false if the sender
* did not specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
*/
public 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.
*
*
* You can use {@link #hasAllowedMethods()} to see if a value was sent in this field.
*
*
* @return An HTTP method that you allow the origin to execute. Valid values are GET
, PUT
,
* HEAD
, POST
, and DELETE
.
*/
public List allowedMethods() {
return allowedMethods;
}
/**
* Returns true if the AllowedOrigins property was specified by the sender (it may be empty), or false if the sender
* did not specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
*/
public 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.
*
*
* You can use {@link #hasAllowedOrigins()} to see if a value was sent in this field.
*
*
* @return One or more origins you want customers to be able to access the bucket from.
*/
public List allowedOrigins() {
return allowedOrigins;
}
/**
* Returns true if the ExposeHeaders property was specified by the sender (it may be empty), or false if the sender
* did not specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
*/
public 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.
*
*
* You can use {@link #hasExposeHeaders()} to see if a value was sent in this field.
*
*
* @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 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 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 int hashCode() {
int hashCode = 1;
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 boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public 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 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 String toString() {
return ToString.builder("CORSRule").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 Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
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 List> sdkFields() {
return SDK_FIELDS;
}
private static Function