
software.amazon.awssdk.services.accessanalyzer.model.KmsGrantConfiguration 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.accessanalyzer.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 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;
/**
*
* A proposed grant configuration for a KMS key. For more information, see CreateGrant.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class KmsGrantConfiguration implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField> OPERATIONS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("operations")
.getter(getter(KmsGrantConfiguration::operationsAsStrings))
.setter(setter(Builder::operationsWithStrings))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("operations").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.STRING)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField GRANTEE_PRINCIPAL_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("granteePrincipal").getter(getter(KmsGrantConfiguration::granteePrincipal))
.setter(setter(Builder::granteePrincipal))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("granteePrincipal").build()).build();
private static final SdkField RETIRING_PRINCIPAL_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("retiringPrincipal").getter(getter(KmsGrantConfiguration::retiringPrincipal))
.setter(setter(Builder::retiringPrincipal))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("retiringPrincipal").build()).build();
private static final SdkField CONSTRAINTS_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("constraints")
.getter(getter(KmsGrantConfiguration::constraints)).setter(setter(Builder::constraints))
.constructor(KmsGrantConstraints::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("constraints").build()).build();
private static final SdkField ISSUING_ACCOUNT_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("issuingAccount").getter(getter(KmsGrantConfiguration::issuingAccount))
.setter(setter(Builder::issuingAccount))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("issuingAccount").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(OPERATIONS_FIELD,
GRANTEE_PRINCIPAL_FIELD, RETIRING_PRINCIPAL_FIELD, CONSTRAINTS_FIELD, ISSUING_ACCOUNT_FIELD));
private static final long serialVersionUID = 1L;
private final List operations;
private final String granteePrincipal;
private final String retiringPrincipal;
private final KmsGrantConstraints constraints;
private final String issuingAccount;
private KmsGrantConfiguration(BuilderImpl builder) {
this.operations = builder.operations;
this.granteePrincipal = builder.granteePrincipal;
this.retiringPrincipal = builder.retiringPrincipal;
this.constraints = builder.constraints;
this.issuingAccount = builder.issuingAccount;
}
/**
*
* A list of operations that the grant permits.
*
*
* 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 #hasOperations} method.
*
*
* @return A list of operations that the grant permits.
*/
public final List operations() {
return KmsGrantOperationsListCopier.copyStringToEnum(operations);
}
/**
* For responses, this returns true if the service returned a value for the Operations 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 hasOperations() {
return operations != null && !(operations instanceof SdkAutoConstructList);
}
/**
*
* A list of operations that the grant permits.
*
*
* 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 #hasOperations} method.
*
*
* @return A list of operations that the grant permits.
*/
public final List operationsAsStrings() {
return operations;
}
/**
*
* The principal that is given permission to perform the operations that the grant permits.
*
*
* @return The principal that is given permission to perform the operations that the grant permits.
*/
public final String granteePrincipal() {
return granteePrincipal;
}
/**
*
* The principal that is given permission to retire the grant by using RetireGrant operation.
*
*
* @return The principal that is given permission to retire the grant by using RetireGrant
* operation.
*/
public final String retiringPrincipal() {
return retiringPrincipal;
}
/**
*
* Use this structure to propose allowing cryptographic
* operations in the grant only when the operation request includes the specified encryption
* context.
*
*
* @return Use this structure to propose allowing cryptographic operations in the grant only when the operation request includes the specified encryption
* context.
*/
public final KmsGrantConstraints constraints() {
return constraints;
}
/**
*
* The Amazon Web Services account under which the grant was issued. The account is used to propose KMS grants
* issued by accounts other than the owner of the key.
*
*
* @return The Amazon Web Services account under which the grant was issued. The account is used to propose KMS
* grants issued by accounts other than the owner of the key.
*/
public final String issuingAccount() {
return issuingAccount;
}
@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(hasOperations() ? operationsAsStrings() : null);
hashCode = 31 * hashCode + Objects.hashCode(granteePrincipal());
hashCode = 31 * hashCode + Objects.hashCode(retiringPrincipal());
hashCode = 31 * hashCode + Objects.hashCode(constraints());
hashCode = 31 * hashCode + Objects.hashCode(issuingAccount());
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 KmsGrantConfiguration)) {
return false;
}
KmsGrantConfiguration other = (KmsGrantConfiguration) obj;
return hasOperations() == other.hasOperations() && Objects.equals(operationsAsStrings(), other.operationsAsStrings())
&& Objects.equals(granteePrincipal(), other.granteePrincipal())
&& Objects.equals(retiringPrincipal(), other.retiringPrincipal())
&& Objects.equals(constraints(), other.constraints()) && Objects.equals(issuingAccount(), other.issuingAccount());
}
/**
* 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("KmsGrantConfiguration").add("Operations", hasOperations() ? operationsAsStrings() : null)
.add("GranteePrincipal", granteePrincipal()).add("RetiringPrincipal", retiringPrincipal())
.add("Constraints", constraints()).add("IssuingAccount", issuingAccount()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "operations":
return Optional.ofNullable(clazz.cast(operationsAsStrings()));
case "granteePrincipal":
return Optional.ofNullable(clazz.cast(granteePrincipal()));
case "retiringPrincipal":
return Optional.ofNullable(clazz.cast(retiringPrincipal()));
case "constraints":
return Optional.ofNullable(clazz.cast(constraints()));
case "issuingAccount":
return Optional.ofNullable(clazz.cast(issuingAccount()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function