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

io.cloudshiftdev.awscdk.services.iam.GrantWithResourceOptions.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

/**
 * Options for a grant operation.
 *
 * Example:
 *
 * ```
 * // The code below shows an example of how to instantiate this type.
 * // The values are placeholders you should change.
 * import io.cloudshiftdev.awscdk.services.iam.*;
 * Object conditions;
 * IGrantable grantable;
 * IResourceWithPolicy resourceWithPolicy;
 * GrantWithResourceOptions grantWithResourceOptions = GrantWithResourceOptions.builder()
 * .actions(List.of("actions"))
 * .grantee(grantable)
 * .resource(resourceWithPolicy)
 * .resourceArns(List.of("resourceArns"))
 * // the properties below are optional
 * .conditions(Map.of(
 * "conditionsKey", Map.of(
 * "conditionsKey", conditions)))
 * .resourceSelfArns(List.of("resourceSelfArns"))
 * .build();
 * ```
 */
public interface GrantWithResourceOptions : CommonGrantOptions {
  /**
   * The resource with a resource policy.
   *
   * The statement will be added to the resource policy if it couldn't be
   * added to the principal policy.
   */
  public fun resource(): IResourceWithPolicy

  /**
   * When referring to the resource in a resource policy, use this as ARN.
   *
   * (Depending on the resource type, this needs to be '*' in a resource policy).
   *
   * Default: Same as regular resource ARNs
   */
  public fun resourceSelfArns(): List = unwrap(this).getResourceSelfArns() ?: emptyList()

  /**
   * A builder for [GrantWithResourceOptions]
   */
  @CdkDslMarker
  public interface Builder {
    /**
     * @param actions The actions to grant. 
     */
    public fun actions(actions: List)

    /**
     * @param actions The actions to grant. 
     */
    public fun actions(vararg actions: String)

    /**
     * @param conditions Any conditions to attach to the grant.
     */
    public fun conditions(conditions: Map>)

    /**
     * @param grantee The principal to grant to. 
     */
    public fun grantee(grantee: IGrantable)

    /**
     * @param resource The resource with a resource policy. 
     * The statement will be added to the resource policy if it couldn't be
     * added to the principal policy.
     */
    public fun resource(resource: IResourceWithPolicy)

    /**
     * @param resourceArns The resource ARNs to grant to. 
     */
    public fun resourceArns(resourceArns: List)

    /**
     * @param resourceArns The resource ARNs to grant to. 
     */
    public fun resourceArns(vararg resourceArns: String)

    /**
     * @param resourceSelfArns When referring to the resource in a resource policy, use this as ARN.
     * (Depending on the resource type, this needs to be '*' in a resource policy).
     */
    public fun resourceSelfArns(resourceSelfArns: List)

    /**
     * @param resourceSelfArns When referring to the resource in a resource policy, use this as ARN.
     * (Depending on the resource type, this needs to be '*' in a resource policy).
     */
    public fun resourceSelfArns(vararg resourceSelfArns: String)
  }

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

    /**
     * @param actions The actions to grant. 
     */
    override fun actions(actions: List) {
      cdkBuilder.actions(actions)
    }

    /**
     * @param actions The actions to grant. 
     */
    override fun actions(vararg actions: String): Unit = actions(actions.toList())

    /**
     * @param conditions Any conditions to attach to the grant.
     */
    override fun conditions(conditions: Map>) {
      cdkBuilder.conditions(conditions)
    }

    /**
     * @param grantee The principal to grant to. 
     */
    override fun grantee(grantee: IGrantable) {
      cdkBuilder.grantee(grantee.let(IGrantable.Companion::unwrap))
    }

    /**
     * @param resource The resource with a resource policy. 
     * The statement will be added to the resource policy if it couldn't be
     * added to the principal policy.
     */
    override fun resource(resource: IResourceWithPolicy) {
      cdkBuilder.resource(resource.let(IResourceWithPolicy.Companion::unwrap))
    }

    /**
     * @param resourceArns The resource ARNs to grant to. 
     */
    override fun resourceArns(resourceArns: List) {
      cdkBuilder.resourceArns(resourceArns)
    }

    /**
     * @param resourceArns The resource ARNs to grant to. 
     */
    override fun resourceArns(vararg resourceArns: String): Unit =
        resourceArns(resourceArns.toList())

    /**
     * @param resourceSelfArns When referring to the resource in a resource policy, use this as ARN.
     * (Depending on the resource type, this needs to be '*' in a resource policy).
     */
    override fun resourceSelfArns(resourceSelfArns: List) {
      cdkBuilder.resourceSelfArns(resourceSelfArns)
    }

    /**
     * @param resourceSelfArns When referring to the resource in a resource policy, use this as ARN.
     * (Depending on the resource type, this needs to be '*' in a resource policy).
     */
    override fun resourceSelfArns(vararg resourceSelfArns: String): Unit =
        resourceSelfArns(resourceSelfArns.toList())

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

  private class Wrapper(
    cdkObject: software.amazon.awscdk.services.iam.GrantWithResourceOptions,
  ) : CdkObject(cdkObject),
      GrantWithResourceOptions {
    /**
     * The actions to grant.
     */
    override fun actions(): List = unwrap(this).getActions()

    /**
     * Any conditions to attach to the grant.
     *
     * Default: - No conditions
     */
    override fun conditions(): Map> = unwrap(this).getConditions() ?:
        emptyMap()

    /**
     * The principal to grant to.
     *
     * Default: if principal is undefined, no work is done.
     */
    override fun grantee(): IGrantable = unwrap(this).getGrantee().let(IGrantable::wrap)

    /**
     * The resource with a resource policy.
     *
     * The statement will be added to the resource policy if it couldn't be
     * added to the principal policy.
     */
    override fun resource(): IResourceWithPolicy =
        unwrap(this).getResource().let(IResourceWithPolicy::wrap)

    /**
     * The resource ARNs to grant to.
     */
    override fun resourceArns(): List = unwrap(this).getResourceArns()

    /**
     * When referring to the resource in a resource policy, use this as ARN.
     *
     * (Depending on the resource type, this needs to be '*' in a resource policy).
     *
     * Default: Same as regular resource ARNs
     */
    override fun resourceSelfArns(): List = unwrap(this).getResourceSelfArns() ?:
        emptyList()
  }

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy