packages feed

amazonka-accessanalyzer-2.0: gen/Amazonka/AccessAnalyzer/StartPolicyGeneration.hs

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.AccessAnalyzer.StartPolicyGeneration
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Starts the policy generation request.
module Amazonka.AccessAnalyzer.StartPolicyGeneration
  ( -- * Creating a Request
    StartPolicyGeneration (..),
    newStartPolicyGeneration,

    -- * Request Lenses
    startPolicyGeneration_clientToken,
    startPolicyGeneration_cloudTrailDetails,
    startPolicyGeneration_policyGenerationDetails,

    -- * Destructuring the Response
    StartPolicyGenerationResponse (..),
    newStartPolicyGenerationResponse,

    -- * Response Lenses
    startPolicyGenerationResponse_httpStatus,
    startPolicyGenerationResponse_jobId,
  )
where

import Amazonka.AccessAnalyzer.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newStartPolicyGeneration' smart constructor.
data StartPolicyGeneration = StartPolicyGeneration'
  { -- | A unique, case-sensitive identifier that you provide to ensure the
    -- idempotency of the request. Idempotency ensures that an API request
    -- completes only once. With an idempotent request, if the original request
    -- completes successfully, the subsequent retries with the same client
    -- token return the result from the original successful request and they
    -- have no additional effect.
    --
    -- If you do not specify a client token, one is automatically generated by
    -- the Amazon Web Services SDK.
    clientToken :: Prelude.Maybe Prelude.Text,
    -- | A @CloudTrailDetails@ object that contains details about a @Trail@ that
    -- you want to analyze to generate policies.
    cloudTrailDetails :: Prelude.Maybe CloudTrailDetails,
    -- | Contains the ARN of the IAM entity (user or role) for which you are
    -- generating a policy.
    policyGenerationDetails :: PolicyGenerationDetails
  }
  deriving (Prelude.Eq, Prelude.Read, Prelude.Show, Prelude.Generic)

-- |
-- Create a value of 'StartPolicyGeneration' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'clientToken', 'startPolicyGeneration_clientToken' - A unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the request. Idempotency ensures that an API request
-- completes only once. With an idempotent request, if the original request
-- completes successfully, the subsequent retries with the same client
-- token return the result from the original successful request and they
-- have no additional effect.
--
-- If you do not specify a client token, one is automatically generated by
-- the Amazon Web Services SDK.
--
-- 'cloudTrailDetails', 'startPolicyGeneration_cloudTrailDetails' - A @CloudTrailDetails@ object that contains details about a @Trail@ that
-- you want to analyze to generate policies.
--
-- 'policyGenerationDetails', 'startPolicyGeneration_policyGenerationDetails' - Contains the ARN of the IAM entity (user or role) for which you are
-- generating a policy.
newStartPolicyGeneration ::
  -- | 'policyGenerationDetails'
  PolicyGenerationDetails ->
  StartPolicyGeneration
newStartPolicyGeneration pPolicyGenerationDetails_ =
  StartPolicyGeneration'
    { clientToken =
        Prelude.Nothing,
      cloudTrailDetails = Prelude.Nothing,
      policyGenerationDetails = pPolicyGenerationDetails_
    }

-- | A unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the request. Idempotency ensures that an API request
-- completes only once. With an idempotent request, if the original request
-- completes successfully, the subsequent retries with the same client
-- token return the result from the original successful request and they
-- have no additional effect.
--
-- If you do not specify a client token, one is automatically generated by
-- the Amazon Web Services SDK.
startPolicyGeneration_clientToken :: Lens.Lens' StartPolicyGeneration (Prelude.Maybe Prelude.Text)
startPolicyGeneration_clientToken = Lens.lens (\StartPolicyGeneration' {clientToken} -> clientToken) (\s@StartPolicyGeneration' {} a -> s {clientToken = a} :: StartPolicyGeneration)

-- | A @CloudTrailDetails@ object that contains details about a @Trail@ that
-- you want to analyze to generate policies.
startPolicyGeneration_cloudTrailDetails :: Lens.Lens' StartPolicyGeneration (Prelude.Maybe CloudTrailDetails)
startPolicyGeneration_cloudTrailDetails = Lens.lens (\StartPolicyGeneration' {cloudTrailDetails} -> cloudTrailDetails) (\s@StartPolicyGeneration' {} a -> s {cloudTrailDetails = a} :: StartPolicyGeneration)

-- | Contains the ARN of the IAM entity (user or role) for which you are
-- generating a policy.
startPolicyGeneration_policyGenerationDetails :: Lens.Lens' StartPolicyGeneration PolicyGenerationDetails
startPolicyGeneration_policyGenerationDetails = Lens.lens (\StartPolicyGeneration' {policyGenerationDetails} -> policyGenerationDetails) (\s@StartPolicyGeneration' {} a -> s {policyGenerationDetails = a} :: StartPolicyGeneration)

instance Core.AWSRequest StartPolicyGeneration where
  type
    AWSResponse StartPolicyGeneration =
      StartPolicyGenerationResponse
  request overrides =
    Request.putJSON (overrides defaultService)
  response =
    Response.receiveJSON
      ( \s h x ->
          StartPolicyGenerationResponse'
            Prelude.<$> (Prelude.pure (Prelude.fromEnum s))
            Prelude.<*> (x Data..:> "jobId")
      )

instance Prelude.Hashable StartPolicyGeneration where
  hashWithSalt _salt StartPolicyGeneration' {..} =
    _salt
      `Prelude.hashWithSalt` clientToken
      `Prelude.hashWithSalt` cloudTrailDetails
      `Prelude.hashWithSalt` policyGenerationDetails

instance Prelude.NFData StartPolicyGeneration where
  rnf StartPolicyGeneration' {..} =
    Prelude.rnf clientToken
      `Prelude.seq` Prelude.rnf cloudTrailDetails
      `Prelude.seq` Prelude.rnf policyGenerationDetails

instance Data.ToHeaders StartPolicyGeneration where
  toHeaders =
    Prelude.const
      ( Prelude.mconcat
          [ "Content-Type"
              Data.=# ( "application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON StartPolicyGeneration where
  toJSON StartPolicyGeneration' {..} =
    Data.object
      ( Prelude.catMaybes
          [ ("clientToken" Data..=) Prelude.<$> clientToken,
            ("cloudTrailDetails" Data..=)
              Prelude.<$> cloudTrailDetails,
            Prelude.Just
              ( "policyGenerationDetails"
                  Data..= policyGenerationDetails
              )
          ]
      )

instance Data.ToPath StartPolicyGeneration where
  toPath = Prelude.const "/policy/generation"

instance Data.ToQuery StartPolicyGeneration where
  toQuery = Prelude.const Prelude.mempty

-- | /See:/ 'newStartPolicyGenerationResponse' smart constructor.
data StartPolicyGenerationResponse = StartPolicyGenerationResponse'
  { -- | The response's http status code.
    httpStatus :: Prelude.Int,
    -- | The @JobId@ that is returned by the @StartPolicyGeneration@ operation.
    -- The @JobId@ can be used with @GetGeneratedPolicy@ to retrieve the
    -- generated policies or used with @CancelPolicyGeneration@ to cancel the
    -- policy generation request.
    jobId :: Prelude.Text
  }
  deriving (Prelude.Eq, Prelude.Read, Prelude.Show, Prelude.Generic)

-- |
-- Create a value of 'StartPolicyGenerationResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'httpStatus', 'startPolicyGenerationResponse_httpStatus' - The response's http status code.
--
-- 'jobId', 'startPolicyGenerationResponse_jobId' - The @JobId@ that is returned by the @StartPolicyGeneration@ operation.
-- The @JobId@ can be used with @GetGeneratedPolicy@ to retrieve the
-- generated policies or used with @CancelPolicyGeneration@ to cancel the
-- policy generation request.
newStartPolicyGenerationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'jobId'
  Prelude.Text ->
  StartPolicyGenerationResponse
newStartPolicyGenerationResponse pHttpStatus_ pJobId_ =
  StartPolicyGenerationResponse'
    { httpStatus =
        pHttpStatus_,
      jobId = pJobId_
    }

-- | The response's http status code.
startPolicyGenerationResponse_httpStatus :: Lens.Lens' StartPolicyGenerationResponse Prelude.Int
startPolicyGenerationResponse_httpStatus = Lens.lens (\StartPolicyGenerationResponse' {httpStatus} -> httpStatus) (\s@StartPolicyGenerationResponse' {} a -> s {httpStatus = a} :: StartPolicyGenerationResponse)

-- | The @JobId@ that is returned by the @StartPolicyGeneration@ operation.
-- The @JobId@ can be used with @GetGeneratedPolicy@ to retrieve the
-- generated policies or used with @CancelPolicyGeneration@ to cancel the
-- policy generation request.
startPolicyGenerationResponse_jobId :: Lens.Lens' StartPolicyGenerationResponse Prelude.Text
startPolicyGenerationResponse_jobId = Lens.lens (\StartPolicyGenerationResponse' {jobId} -> jobId) (\s@StartPolicyGenerationResponse' {} a -> s {jobId = a} :: StartPolicyGenerationResponse)

instance Prelude.NFData StartPolicyGenerationResponse where
  rnf StartPolicyGenerationResponse' {..} =
    Prelude.rnf httpStatus
      `Prelude.seq` Prelude.rnf jobId