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

io.cloudshiftdev.awscdk.services.iam.PolicyStatementProps.kt Maven / Gradle / Ivy

The newest version!
@file:Suppress("RedundantVisibilityModifier","RedundantUnitReturnType","RemoveRedundantQualifierName","unused","UnusedImport","ClassName","REDUNDANT_PROJECTION","DEPRECATION")

package io.cloudshiftdev.awscdk.services.iam

import io.cloudshiftdev.awscdk.common.CdkDslMarker
import io.cloudshiftdev.awscdk.common.CdkObject
import io.cloudshiftdev.awscdk.common.CdkObjectWrappers
import kotlin.Any
import kotlin.String
import kotlin.Unit
import kotlin.collections.List
import kotlin.collections.Map

/**
 * Interface for creating a policy statement.
 *
 * Example:
 *
 * ```
 * Bucket accessLogsBucket = Bucket.Builder.create(this, "AccessLogsBucket")
 * .objectOwnership(ObjectOwnership.BUCKET_OWNER_ENFORCED)
 * .build();
 * accessLogsBucket.addToResourcePolicy(
 * PolicyStatement.Builder.create()
 * .actions(List.of("s3:*"))
 * .resources(List.of(accessLogsBucket.getBucketArn(), accessLogsBucket.arnForObjects("*")))
 * .principals(List.of(new AnyPrincipal()))
 * .build());
 * Bucket bucket = Bucket.Builder.create(this, "MyBucket")
 * .serverAccessLogsBucket(accessLogsBucket)
 * .serverAccessLogsPrefix("logs")
 * .build();
 * ```
 */
public interface PolicyStatementProps {
  /**
   * List of actions to add to the statement.
   *
   * Default: - no actions
   */
  public fun actions(): List = unwrap(this).getActions() ?: emptyList()

  /**
   * Conditions to add to the statement.
   *
   * Default: - no condition
   */
  public fun conditions(): Map = unwrap(this).getConditions() ?: emptyMap()

  /**
   * Whether to allow or deny the actions in this statement.
   *
   * Default: Effect.ALLOW
   */
  public fun effect(): Effect? = unwrap(this).getEffect()?.let(Effect::wrap)

  /**
   * List of not actions to add to the statement.
   *
   * Default: - no not-actions
   */
  public fun notActions(): List = unwrap(this).getNotActions() ?: emptyList()

  /**
   * List of not principals to add to the statement.
   *
   * Default: - no not principals
   */
  public fun notPrincipals(): List =
      unwrap(this).getNotPrincipals()?.map(IPrincipal::wrap) ?: emptyList()

  /**
   * NotResource ARNs to add to the statement.
   *
   * Default: - no not-resources
   */
  public fun notResources(): List = unwrap(this).getNotResources() ?: emptyList()

  /**
   * List of principals to add to the statement.
   *
   * Default: - no principals
   */
  public fun principals(): List = unwrap(this).getPrincipals()?.map(IPrincipal::wrap) ?:
      emptyList()

  /**
   * Resource ARNs to add to the statement.
   *
   * Default: - no resources
   */
  public fun resources(): List = unwrap(this).getResources() ?: emptyList()

  /**
   * The Sid (statement ID) is an optional identifier that you provide for the policy statement.
   *
   * You can assign a Sid value to each statement in a
   * statement array. In services that let you specify an ID element, such as
   * SQS and SNS, the Sid value is just a sub-ID of the policy document's ID. In
   * IAM, the Sid value must be unique within a JSON policy.
   *
   * Default: - no sid
   */
  public fun sid(): String? = unwrap(this).getSid()

  /**
   * A builder for [PolicyStatementProps]
   */
  @CdkDslMarker
  public interface Builder {
    /**
     * @param actions List of actions to add to the statement.
     */
    public fun actions(actions: List)

    /**
     * @param actions List of actions to add to the statement.
     */
    public fun actions(vararg actions: String)

    /**
     * @param conditions Conditions to add to the statement.
     */
    public fun conditions(conditions: Map)

    /**
     * @param effect Whether to allow or deny the actions in this statement.
     */
    public fun effect(effect: Effect)

    /**
     * @param notActions List of not actions to add to the statement.
     */
    public fun notActions(notActions: List)

    /**
     * @param notActions List of not actions to add to the statement.
     */
    public fun notActions(vararg notActions: String)

    /**
     * @param notPrincipals List of not principals to add to the statement.
     */
    public fun notPrincipals(notPrincipals: List)

    /**
     * @param notPrincipals List of not principals to add to the statement.
     */
    public fun notPrincipals(vararg notPrincipals: IPrincipal)

    /**
     * @param notResources NotResource ARNs to add to the statement.
     */
    public fun notResources(notResources: List)

    /**
     * @param notResources NotResource ARNs to add to the statement.
     */
    public fun notResources(vararg notResources: String)

    /**
     * @param principals List of principals to add to the statement.
     */
    public fun principals(principals: List)

    /**
     * @param principals List of principals to add to the statement.
     */
    public fun principals(vararg principals: IPrincipal)

    /**
     * @param resources Resource ARNs to add to the statement.
     */
    public fun resources(resources: List)

    /**
     * @param resources Resource ARNs to add to the statement.
     */
    public fun resources(vararg resources: String)

    /**
     * @param sid The Sid (statement ID) is an optional identifier that you provide for the policy
     * statement.
     * You can assign a Sid value to each statement in a
     * statement array. In services that let you specify an ID element, such as
     * SQS and SNS, the Sid value is just a sub-ID of the policy document's ID. In
     * IAM, the Sid value must be unique within a JSON policy.
     */
    public fun sid(sid: String)
  }

  private class BuilderImpl : Builder {
    private val cdkBuilder: software.amazon.awscdk.services.iam.PolicyStatementProps.Builder =
        software.amazon.awscdk.services.iam.PolicyStatementProps.builder()

    /**
     * @param actions List of actions to add to the statement.
     */
    override fun actions(actions: List) {
      cdkBuilder.actions(actions)
    }

    /**
     * @param actions List of actions to add to the statement.
     */
    override fun actions(vararg actions: String): Unit = actions(actions.toList())

    /**
     * @param conditions Conditions to add to the statement.
     */
    override fun conditions(conditions: Map) {
      cdkBuilder.conditions(conditions.mapValues{CdkObjectWrappers.unwrap(it.value)})
    }

    /**
     * @param effect Whether to allow or deny the actions in this statement.
     */
    override fun effect(effect: Effect) {
      cdkBuilder.effect(effect.let(Effect.Companion::unwrap))
    }

    /**
     * @param notActions List of not actions to add to the statement.
     */
    override fun notActions(notActions: List) {
      cdkBuilder.notActions(notActions)
    }

    /**
     * @param notActions List of not actions to add to the statement.
     */
    override fun notActions(vararg notActions: String): Unit = notActions(notActions.toList())

    /**
     * @param notPrincipals List of not principals to add to the statement.
     */
    override fun notPrincipals(notPrincipals: List) {
      cdkBuilder.notPrincipals(notPrincipals.map(IPrincipal.Companion::unwrap))
    }

    /**
     * @param notPrincipals List of not principals to add to the statement.
     */
    override fun notPrincipals(vararg notPrincipals: IPrincipal): Unit =
        notPrincipals(notPrincipals.toList())

    /**
     * @param notResources NotResource ARNs to add to the statement.
     */
    override fun notResources(notResources: List) {
      cdkBuilder.notResources(notResources)
    }

    /**
     * @param notResources NotResource ARNs to add to the statement.
     */
    override fun notResources(vararg notResources: String): Unit =
        notResources(notResources.toList())

    /**
     * @param principals List of principals to add to the statement.
     */
    override fun principals(principals: List) {
      cdkBuilder.principals(principals.map(IPrincipal.Companion::unwrap))
    }

    /**
     * @param principals List of principals to add to the statement.
     */
    override fun principals(vararg principals: IPrincipal): Unit = principals(principals.toList())

    /**
     * @param resources Resource ARNs to add to the statement.
     */
    override fun resources(resources: List) {
      cdkBuilder.resources(resources)
    }

    /**
     * @param resources Resource ARNs to add to the statement.
     */
    override fun resources(vararg resources: String): Unit = resources(resources.toList())

    /**
     * @param sid The Sid (statement ID) is an optional identifier that you provide for the policy
     * statement.
     * You can assign a Sid value to each statement in a
     * statement array. In services that let you specify an ID element, such as
     * SQS and SNS, the Sid value is just a sub-ID of the policy document's ID. In
     * IAM, the Sid value must be unique within a JSON policy.
     */
    override fun sid(sid: String) {
      cdkBuilder.sid(sid)
    }

    public fun build(): software.amazon.awscdk.services.iam.PolicyStatementProps =
        cdkBuilder.build()
  }

  private class Wrapper(
    cdkObject: software.amazon.awscdk.services.iam.PolicyStatementProps,
  ) : CdkObject(cdkObject),
      PolicyStatementProps {
    /**
     * List of actions to add to the statement.
     *
     * Default: - no actions
     */
    override fun actions(): List = unwrap(this).getActions() ?: emptyList()

    /**
     * Conditions to add to the statement.
     *
     * Default: - no condition
     */
    override fun conditions(): Map = unwrap(this).getConditions() ?: emptyMap()

    /**
     * Whether to allow or deny the actions in this statement.
     *
     * Default: Effect.ALLOW
     */
    override fun effect(): Effect? = unwrap(this).getEffect()?.let(Effect::wrap)

    /**
     * List of not actions to add to the statement.
     *
     * Default: - no not-actions
     */
    override fun notActions(): List = unwrap(this).getNotActions() ?: emptyList()

    /**
     * List of not principals to add to the statement.
     *
     * Default: - no not principals
     */
    override fun notPrincipals(): List =
        unwrap(this).getNotPrincipals()?.map(IPrincipal::wrap) ?: emptyList()

    /**
     * NotResource ARNs to add to the statement.
     *
     * Default: - no not-resources
     */
    override fun notResources(): List = unwrap(this).getNotResources() ?: emptyList()

    /**
     * List of principals to add to the statement.
     *
     * Default: - no principals
     */
    override fun principals(): List =
        unwrap(this).getPrincipals()?.map(IPrincipal::wrap) ?: emptyList()

    /**
     * Resource ARNs to add to the statement.
     *
     * Default: - no resources
     */
    override fun resources(): List = unwrap(this).getResources() ?: emptyList()

    /**
     * The Sid (statement ID) is an optional identifier that you provide for the policy statement.
     *
     * You can assign a Sid value to each statement in a
     * statement array. In services that let you specify an ID element, such as
     * SQS and SNS, the Sid value is just a sub-ID of the policy document's ID. In
     * IAM, the Sid value must be unique within a JSON policy.
     *
     * Default: - no sid
     */
    override fun sid(): String? = unwrap(this).getSid()
  }

  public companion object {
    public operator fun invoke(block: Builder.() -> Unit = {}): PolicyStatementProps {
      val builderImpl = BuilderImpl()
      return Wrapper(builderImpl.apply(block).build())
    }

    internal fun wrap(cdkObject: software.amazon.awscdk.services.iam.PolicyStatementProps):
        PolicyStatementProps = CdkObjectWrappers.wrap(cdkObject) as? PolicyStatementProps ?:
        Wrapper(cdkObject)

    internal fun unwrap(wrapped: PolicyStatementProps):
        software.amazon.awscdk.services.iam.PolicyStatementProps = (wrapped as CdkObject).cdkObject
        as software.amazon.awscdk.services.iam.PolicyStatementProps
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy