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

software.amazon.awssdk.services.s3.model.CORSRule Maven / Gradle / Ivy

Go to download

The AWS Java SDK for Amazon S3 module holds the client classes that are used for communicating with Amazon Simple Storage Service

There is a newer version: 2.29.39
Show newest version
/*
 * 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 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 getter(Function g) { return obj -> g.apply((CORSRule) obj); } private static BiConsumer setter(BiConsumer s) { return (obj, val) -> s.accept((Builder) obj, val); } public interface Builder extends SdkPojo, CopyableBuilder { /** *

* 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. *

* * @param allowedHeaders * 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. * @return Returns a reference to this object so that method calls can be chained together. */ Builder allowedHeaders(Collection allowedHeaders); /** *

* 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. *

* * @param allowedHeaders * 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. * @return Returns a reference to this object so that method calls can be chained together. */ Builder allowedHeaders(String... allowedHeaders); /** *

* An HTTP method that you allow the origin to execute. Valid values are GET, PUT, * HEAD, POST, and DELETE. *

* * @param allowedMethods * An HTTP method that you allow the origin to execute. Valid values are GET, * PUT, HEAD, POST, and DELETE. * @return Returns a reference to this object so that method calls can be chained together. */ Builder allowedMethods(Collection allowedMethods); /** *

* An HTTP method that you allow the origin to execute. Valid values are GET, PUT, * HEAD, POST, and DELETE. *

* * @param allowedMethods * An HTTP method that you allow the origin to execute. Valid values are GET, * PUT, HEAD, POST, and DELETE. * @return Returns a reference to this object so that method calls can be chained together. */ Builder allowedMethods(String... allowedMethods); /** *

* One or more origins you want customers to be able to access the bucket from. *

* * @param allowedOrigins * One or more origins you want customers to be able to access the bucket from. * @return Returns a reference to this object so that method calls can be chained together. */ Builder allowedOrigins(Collection allowedOrigins); /** *

* One or more origins you want customers to be able to access the bucket from. *

* * @param allowedOrigins * One or more origins you want customers to be able to access the bucket from. * @return Returns a reference to this object so that method calls can be chained together. */ Builder allowedOrigins(String... allowedOrigins); /** *

* 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). *

* * @param exposeHeaders * 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). * @return Returns a reference to this object so that method calls can be chained together. */ Builder exposeHeaders(Collection exposeHeaders); /** *

* 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). *

* * @param exposeHeaders * 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). * @return Returns a reference to this object so that method calls can be chained together. */ Builder exposeHeaders(String... exposeHeaders); /** *

* The time in seconds that your browser is to cache the preflight response for the specified resource. *

* * @param maxAgeSeconds * The time in seconds that your browser is to cache the preflight response for the specified resource. * @return Returns a reference to this object so that method calls can be chained together. */ Builder maxAgeSeconds(Integer maxAgeSeconds); } static final class BuilderImpl implements Builder { private List allowedHeaders = DefaultSdkAutoConstructList.getInstance(); private List allowedMethods = DefaultSdkAutoConstructList.getInstance(); private List allowedOrigins = DefaultSdkAutoConstructList.getInstance(); private List exposeHeaders = DefaultSdkAutoConstructList.getInstance(); private Integer maxAgeSeconds; private BuilderImpl() { } private BuilderImpl(CORSRule model) { allowedHeaders(model.allowedHeaders); allowedMethods(model.allowedMethods); allowedOrigins(model.allowedOrigins); exposeHeaders(model.exposeHeaders); maxAgeSeconds(model.maxAgeSeconds); } public final Collection getAllowedHeaders() { if (allowedHeaders instanceof SdkAutoConstructList) { return null; } return allowedHeaders; } @Override public final Builder allowedHeaders(Collection allowedHeaders) { this.allowedHeaders = AllowedHeadersCopier.copy(allowedHeaders); return this; } @Override @SafeVarargs public final Builder allowedHeaders(String... allowedHeaders) { allowedHeaders(Arrays.asList(allowedHeaders)); return this; } public final void setAllowedHeaders(Collection allowedHeaders) { this.allowedHeaders = AllowedHeadersCopier.copy(allowedHeaders); } public final Collection getAllowedMethods() { if (allowedMethods instanceof SdkAutoConstructList) { return null; } return allowedMethods; } @Override public final Builder allowedMethods(Collection allowedMethods) { this.allowedMethods = AllowedMethodsCopier.copy(allowedMethods); return this; } @Override @SafeVarargs public final Builder allowedMethods(String... allowedMethods) { allowedMethods(Arrays.asList(allowedMethods)); return this; } public final void setAllowedMethods(Collection allowedMethods) { this.allowedMethods = AllowedMethodsCopier.copy(allowedMethods); } public final Collection getAllowedOrigins() { if (allowedOrigins instanceof SdkAutoConstructList) { return null; } return allowedOrigins; } @Override public final Builder allowedOrigins(Collection allowedOrigins) { this.allowedOrigins = AllowedOriginsCopier.copy(allowedOrigins); return this; } @Override @SafeVarargs public final Builder allowedOrigins(String... allowedOrigins) { allowedOrigins(Arrays.asList(allowedOrigins)); return this; } public final void setAllowedOrigins(Collection allowedOrigins) { this.allowedOrigins = AllowedOriginsCopier.copy(allowedOrigins); } public final Collection getExposeHeaders() { if (exposeHeaders instanceof SdkAutoConstructList) { return null; } return exposeHeaders; } @Override public final Builder exposeHeaders(Collection exposeHeaders) { this.exposeHeaders = ExposeHeadersCopier.copy(exposeHeaders); return this; } @Override @SafeVarargs public final Builder exposeHeaders(String... exposeHeaders) { exposeHeaders(Arrays.asList(exposeHeaders)); return this; } public final void setExposeHeaders(Collection exposeHeaders) { this.exposeHeaders = ExposeHeadersCopier.copy(exposeHeaders); } public final Integer getMaxAgeSeconds() { return maxAgeSeconds; } @Override public final Builder maxAgeSeconds(Integer maxAgeSeconds) { this.maxAgeSeconds = maxAgeSeconds; return this; } public final void setMaxAgeSeconds(Integer maxAgeSeconds) { this.maxAgeSeconds = maxAgeSeconds; } @Override public CORSRule build() { return new CORSRule(this); } @Override public List> sdkFields() { return SDK_FIELDS; } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy