software.amazon.awssdk.services.iam.model.Policy Maven / Gradle / Ivy
Show all versions of iam 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.iam.model;
import java.io.Serializable;
import java.time.Instant;
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;
/**
*
* Contains information about a managed policy.
*
*
* This data type is used as a response element in the CreatePolicy, GetPolicy, and ListPolicies
* operations.
*
*
* For more information about managed policies, refer to Managed policies and inline
* policies in the IAM User Guide.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class Policy implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField POLICY_NAME_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("PolicyName").getter(getter(Policy::policyName)).setter(setter(Builder::policyName))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("PolicyName").build()).build();
private static final SdkField POLICY_ID_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("PolicyId").getter(getter(Policy::policyId)).setter(setter(Builder::policyId))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("PolicyId").build()).build();
private static final SdkField ARN_FIELD = SdkField. builder(MarshallingType.STRING).memberName("Arn")
.getter(getter(Policy::arn)).setter(setter(Builder::arn))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Arn").build()).build();
private static final SdkField PATH_FIELD = SdkField. builder(MarshallingType.STRING).memberName("Path")
.getter(getter(Policy::path)).setter(setter(Builder::path))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Path").build()).build();
private static final SdkField DEFAULT_VERSION_ID_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("DefaultVersionId").getter(getter(Policy::defaultVersionId)).setter(setter(Builder::defaultVersionId))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("DefaultVersionId").build()).build();
private static final SdkField ATTACHMENT_COUNT_FIELD = SdkField. builder(MarshallingType.INTEGER)
.memberName("AttachmentCount").getter(getter(Policy::attachmentCount)).setter(setter(Builder::attachmentCount))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("AttachmentCount").build()).build();
private static final SdkField PERMISSIONS_BOUNDARY_USAGE_COUNT_FIELD = SdkField
. builder(MarshallingType.INTEGER)
.memberName("PermissionsBoundaryUsageCount")
.getter(getter(Policy::permissionsBoundaryUsageCount))
.setter(setter(Builder::permissionsBoundaryUsageCount))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("PermissionsBoundaryUsageCount")
.build()).build();
private static final SdkField IS_ATTACHABLE_FIELD = SdkField. builder(MarshallingType.BOOLEAN)
.memberName("IsAttachable").getter(getter(Policy::isAttachable)).setter(setter(Builder::isAttachable))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("IsAttachable").build()).build();
private static final SdkField DESCRIPTION_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("Description").getter(getter(Policy::description)).setter(setter(Builder::description))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Description").build()).build();
private static final SdkField CREATE_DATE_FIELD = SdkField. builder(MarshallingType.INSTANT)
.memberName("CreateDate").getter(getter(Policy::createDate)).setter(setter(Builder::createDate))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("CreateDate").build()).build();
private static final SdkField UPDATE_DATE_FIELD = SdkField. builder(MarshallingType.INSTANT)
.memberName("UpdateDate").getter(getter(Policy::updateDate)).setter(setter(Builder::updateDate))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("UpdateDate").build()).build();
private static final SdkField> TAGS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Tags")
.getter(getter(Policy::tags))
.setter(setter(Builder::tags))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Tags").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(Tag::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(POLICY_NAME_FIELD,
POLICY_ID_FIELD, ARN_FIELD, PATH_FIELD, DEFAULT_VERSION_ID_FIELD, ATTACHMENT_COUNT_FIELD,
PERMISSIONS_BOUNDARY_USAGE_COUNT_FIELD, IS_ATTACHABLE_FIELD, DESCRIPTION_FIELD, CREATE_DATE_FIELD, UPDATE_DATE_FIELD,
TAGS_FIELD));
private static final long serialVersionUID = 1L;
private final String policyName;
private final String policyId;
private final String arn;
private final String path;
private final String defaultVersionId;
private final Integer attachmentCount;
private final Integer permissionsBoundaryUsageCount;
private final Boolean isAttachable;
private final String description;
private final Instant createDate;
private final Instant updateDate;
private final List tags;
private Policy(BuilderImpl builder) {
this.policyName = builder.policyName;
this.policyId = builder.policyId;
this.arn = builder.arn;
this.path = builder.path;
this.defaultVersionId = builder.defaultVersionId;
this.attachmentCount = builder.attachmentCount;
this.permissionsBoundaryUsageCount = builder.permissionsBoundaryUsageCount;
this.isAttachable = builder.isAttachable;
this.description = builder.description;
this.createDate = builder.createDate;
this.updateDate = builder.updateDate;
this.tags = builder.tags;
}
/**
*
* The friendly name (not ARN) identifying the policy.
*
*
* @return The friendly name (not ARN) identifying the policy.
*/
public final String policyName() {
return policyName;
}
/**
*
* The stable and unique string identifying the policy.
*
*
* For more information about IDs, see IAM identifiers in the IAM
* User Guide.
*
*
* @return The stable and unique string identifying the policy.
*
* For more information about IDs, see IAM identifiers in the
* IAM User Guide.
*/
public final String policyId() {
return policyId;
}
/**
* Returns the value of the Arn property for this object.
*
* @return The value of the Arn property for this object.
*/
public final String arn() {
return arn;
}
/**
*
* The path to the policy.
*
*
* For more information about paths, see IAM identifiers in the IAM
* User Guide.
*
*
* @return The path to the policy.
*
* For more information about paths, see IAM identifiers in the
* IAM User Guide.
*/
public final String path() {
return path;
}
/**
*
* The identifier for the version of the policy that is set as the default version.
*
*
* @return The identifier for the version of the policy that is set as the default version.
*/
public final String defaultVersionId() {
return defaultVersionId;
}
/**
*
* The number of entities (users, groups, and roles) that the policy is attached to.
*
*
* @return The number of entities (users, groups, and roles) that the policy is attached to.
*/
public final Integer attachmentCount() {
return attachmentCount;
}
/**
*
* The number of entities (users and roles) for which the policy is used to set the permissions boundary.
*
*
* For more information about permissions boundaries, see Permissions boundaries
* for IAM identities in the IAM User Guide.
*
*
* @return The number of entities (users and roles) for which the policy is used to set the permissions boundary.
*
*
* For more information about permissions boundaries, see Permissions
* boundaries for IAM identities in the IAM User Guide.
*/
public final Integer permissionsBoundaryUsageCount() {
return permissionsBoundaryUsageCount;
}
/**
*
* Specifies whether the policy can be attached to an IAM user, group, or role.
*
*
* @return Specifies whether the policy can be attached to an IAM user, group, or role.
*/
public final Boolean isAttachable() {
return isAttachable;
}
/**
*
* A friendly description of the policy.
*
*
* This element is included in the response to the GetPolicy operation. It is not included in the response to
* the ListPolicies operation.
*
*
* @return A friendly description of the policy.
*
* This element is included in the response to the GetPolicy operation. It is not included in the
* response to the ListPolicies operation.
*/
public final String description() {
return description;
}
/**
*
* The date and time, in ISO 8601 date-time format, when the policy was
* created.
*
*
* @return The date and time, in ISO 8601 date-time format, when the
* policy was created.
*/
public final Instant createDate() {
return createDate;
}
/**
*
* The date and time, in ISO 8601 date-time format, when the policy was
* last updated.
*
*
* When a policy has only one version, this field contains the date and time when the policy was created. When a
* policy has more than one version, this field contains the date and time when the most recent policy version was
* created.
*
*
* @return The date and time, in ISO 8601 date-time format, when the
* policy was last updated.
*
* When a policy has only one version, this field contains the date and time when the policy was created.
* When a policy has more than one version, this field contains the date and time when the most recent
* policy version was created.
*/
public final Instant updateDate() {
return updateDate;
}
/**
* For responses, this returns true if the service returned a value for the Tags 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 hasTags() {
return tags != null && !(tags instanceof SdkAutoConstructList);
}
/**
*
* A list of tags that are attached to the instance profile. For more information about tagging, see Tagging IAM resources in the IAM User
* Guide.
*
*
* 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 #hasTags} method.
*
*
* @return A list of tags that are attached to the instance profile. For more information about tagging, see Tagging IAM resources in the
* IAM User Guide.
*/
public final List tags() {
return tags;
}
@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(policyName());
hashCode = 31 * hashCode + Objects.hashCode(policyId());
hashCode = 31 * hashCode + Objects.hashCode(arn());
hashCode = 31 * hashCode + Objects.hashCode(path());
hashCode = 31 * hashCode + Objects.hashCode(defaultVersionId());
hashCode = 31 * hashCode + Objects.hashCode(attachmentCount());
hashCode = 31 * hashCode + Objects.hashCode(permissionsBoundaryUsageCount());
hashCode = 31 * hashCode + Objects.hashCode(isAttachable());
hashCode = 31 * hashCode + Objects.hashCode(description());
hashCode = 31 * hashCode + Objects.hashCode(createDate());
hashCode = 31 * hashCode + Objects.hashCode(updateDate());
hashCode = 31 * hashCode + Objects.hashCode(hasTags() ? tags() : 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 Policy)) {
return false;
}
Policy other = (Policy) obj;
return Objects.equals(policyName(), other.policyName()) && Objects.equals(policyId(), other.policyId())
&& Objects.equals(arn(), other.arn()) && Objects.equals(path(), other.path())
&& Objects.equals(defaultVersionId(), other.defaultVersionId())
&& Objects.equals(attachmentCount(), other.attachmentCount())
&& Objects.equals(permissionsBoundaryUsageCount(), other.permissionsBoundaryUsageCount())
&& Objects.equals(isAttachable(), other.isAttachable()) && Objects.equals(description(), other.description())
&& Objects.equals(createDate(), other.createDate()) && Objects.equals(updateDate(), other.updateDate())
&& hasTags() == other.hasTags() && Objects.equals(tags(), other.tags());
}
/**
* 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("Policy").add("PolicyName", policyName()).add("PolicyId", policyId()).add("Arn", arn())
.add("Path", path()).add("DefaultVersionId", defaultVersionId()).add("AttachmentCount", attachmentCount())
.add("PermissionsBoundaryUsageCount", permissionsBoundaryUsageCount()).add("IsAttachable", isAttachable())
.add("Description", description()).add("CreateDate", createDate()).add("UpdateDate", updateDate())
.add("Tags", hasTags() ? tags() : null).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "PolicyName":
return Optional.ofNullable(clazz.cast(policyName()));
case "PolicyId":
return Optional.ofNullable(clazz.cast(policyId()));
case "Arn":
return Optional.ofNullable(clazz.cast(arn()));
case "Path":
return Optional.ofNullable(clazz.cast(path()));
case "DefaultVersionId":
return Optional.ofNullable(clazz.cast(defaultVersionId()));
case "AttachmentCount":
return Optional.ofNullable(clazz.cast(attachmentCount()));
case "PermissionsBoundaryUsageCount":
return Optional.ofNullable(clazz.cast(permissionsBoundaryUsageCount()));
case "IsAttachable":
return Optional.ofNullable(clazz.cast(isAttachable()));
case "Description":
return Optional.ofNullable(clazz.cast(description()));
case "CreateDate":
return Optional.ofNullable(clazz.cast(createDate()));
case "UpdateDate":
return Optional.ofNullable(clazz.cast(updateDate()));
case "Tags":
return Optional.ofNullable(clazz.cast(tags()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function