{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.Configuration
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.AccessAnalyzer.Types.Configuration where

import Amazonka.AccessAnalyzer.Types.IamRoleConfiguration
import Amazonka.AccessAnalyzer.Types.KmsKeyConfiguration
import Amazonka.AccessAnalyzer.Types.S3BucketConfiguration
import Amazonka.AccessAnalyzer.Types.SecretsManagerSecretConfiguration
import Amazonka.AccessAnalyzer.Types.SqsQueueConfiguration
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Access control configuration structures for your resource. You specify
-- the configuration as a type-value pair. You can specify only one type of
-- access control configuration.
--
-- /See:/ 'newConfiguration' smart constructor.
data Configuration = Configuration'
  { -- | The access control configuration is for a KMS key.
    Configuration -> Maybe KmsKeyConfiguration
kmsKey :: Prelude.Maybe KmsKeyConfiguration,
    -- | The access control configuration is for a Secrets Manager secret.
    Configuration -> Maybe SecretsManagerSecretConfiguration
secretsManagerSecret :: Prelude.Maybe SecretsManagerSecretConfiguration,
    -- | The access control configuration is for an Amazon SQS queue.
    Configuration -> Maybe SqsQueueConfiguration
sqsQueue :: Prelude.Maybe SqsQueueConfiguration,
    -- | The access control configuration is for an Amazon S3 Bucket.
    Configuration -> Maybe S3BucketConfiguration
s3Bucket :: Prelude.Maybe S3BucketConfiguration,
    -- | The access control configuration is for an IAM role.
    Configuration -> Maybe IamRoleConfiguration
iamRole :: Prelude.Maybe IamRoleConfiguration
  }
  deriving (Configuration -> Configuration -> Bool
(Configuration -> Configuration -> Bool)
-> (Configuration -> Configuration -> Bool) -> Eq Configuration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Configuration -> Configuration -> Bool
$c/= :: Configuration -> Configuration -> Bool
== :: Configuration -> Configuration -> Bool
$c== :: Configuration -> Configuration -> Bool
Prelude.Eq, ReadPrec [Configuration]
ReadPrec Configuration
Int -> ReadS Configuration
ReadS [Configuration]
(Int -> ReadS Configuration)
-> ReadS [Configuration]
-> ReadPrec Configuration
-> ReadPrec [Configuration]
-> Read Configuration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Configuration]
$creadListPrec :: ReadPrec [Configuration]
readPrec :: ReadPrec Configuration
$creadPrec :: ReadPrec Configuration
readList :: ReadS [Configuration]
$creadList :: ReadS [Configuration]
readsPrec :: Int -> ReadS Configuration
$creadsPrec :: Int -> ReadS Configuration
Prelude.Read, Int -> Configuration -> ShowS
[Configuration] -> ShowS
Configuration -> String
(Int -> Configuration -> ShowS)
-> (Configuration -> String)
-> ([Configuration] -> ShowS)
-> Show Configuration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Configuration] -> ShowS
$cshowList :: [Configuration] -> ShowS
show :: Configuration -> String
$cshow :: Configuration -> String
showsPrec :: Int -> Configuration -> ShowS
$cshowsPrec :: Int -> Configuration -> ShowS
Prelude.Show, (forall x. Configuration -> Rep Configuration x)
-> (forall x. Rep Configuration x -> Configuration)
-> Generic Configuration
forall x. Rep Configuration x -> Configuration
forall x. Configuration -> Rep Configuration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Configuration x -> Configuration
$cfrom :: forall x. Configuration -> Rep Configuration x
Prelude.Generic)

-- |
-- Create a value of 'Configuration' 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:
--
-- 'kmsKey', 'configuration_kmsKey' - The access control configuration is for a KMS key.
--
-- 'secretsManagerSecret', 'configuration_secretsManagerSecret' - The access control configuration is for a Secrets Manager secret.
--
-- 'sqsQueue', 'configuration_sqsQueue' - The access control configuration is for an Amazon SQS queue.
--
-- 's3Bucket', 'configuration_s3Bucket' - The access control configuration is for an Amazon S3 Bucket.
--
-- 'iamRole', 'configuration_iamRole' - The access control configuration is for an IAM role.
newConfiguration ::
  Configuration
newConfiguration :: Configuration
newConfiguration =
  Configuration' :: Maybe KmsKeyConfiguration
-> Maybe SecretsManagerSecretConfiguration
-> Maybe SqsQueueConfiguration
-> Maybe S3BucketConfiguration
-> Maybe IamRoleConfiguration
-> Configuration
Configuration'
    { $sel:kmsKey:Configuration' :: Maybe KmsKeyConfiguration
kmsKey = Maybe KmsKeyConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:secretsManagerSecret:Configuration' :: Maybe SecretsManagerSecretConfiguration
secretsManagerSecret = Maybe SecretsManagerSecretConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:sqsQueue:Configuration' :: Maybe SqsQueueConfiguration
sqsQueue = Maybe SqsQueueConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:s3Bucket:Configuration' :: Maybe S3BucketConfiguration
s3Bucket = Maybe S3BucketConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:iamRole:Configuration' :: Maybe IamRoleConfiguration
iamRole = Maybe IamRoleConfiguration
forall a. Maybe a
Prelude.Nothing
    }

-- | The access control configuration is for a KMS key.
configuration_kmsKey :: Lens.Lens' Configuration (Prelude.Maybe KmsKeyConfiguration)
configuration_kmsKey :: (Maybe KmsKeyConfiguration -> f (Maybe KmsKeyConfiguration))
-> Configuration -> f Configuration
configuration_kmsKey = (Configuration -> Maybe KmsKeyConfiguration)
-> (Configuration -> Maybe KmsKeyConfiguration -> Configuration)
-> Lens
     Configuration
     Configuration
     (Maybe KmsKeyConfiguration)
     (Maybe KmsKeyConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Configuration' {Maybe KmsKeyConfiguration
kmsKey :: Maybe KmsKeyConfiguration
$sel:kmsKey:Configuration' :: Configuration -> Maybe KmsKeyConfiguration
kmsKey} -> Maybe KmsKeyConfiguration
kmsKey) (\s :: Configuration
s@Configuration' {} Maybe KmsKeyConfiguration
a -> Configuration
s {$sel:kmsKey:Configuration' :: Maybe KmsKeyConfiguration
kmsKey = Maybe KmsKeyConfiguration
a} :: Configuration)

-- | The access control configuration is for a Secrets Manager secret.
configuration_secretsManagerSecret :: Lens.Lens' Configuration (Prelude.Maybe SecretsManagerSecretConfiguration)
configuration_secretsManagerSecret :: (Maybe SecretsManagerSecretConfiguration
 -> f (Maybe SecretsManagerSecretConfiguration))
-> Configuration -> f Configuration
configuration_secretsManagerSecret = (Configuration -> Maybe SecretsManagerSecretConfiguration)
-> (Configuration
    -> Maybe SecretsManagerSecretConfiguration -> Configuration)
-> Lens
     Configuration
     Configuration
     (Maybe SecretsManagerSecretConfiguration)
     (Maybe SecretsManagerSecretConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Configuration' {Maybe SecretsManagerSecretConfiguration
secretsManagerSecret :: Maybe SecretsManagerSecretConfiguration
$sel:secretsManagerSecret:Configuration' :: Configuration -> Maybe SecretsManagerSecretConfiguration
secretsManagerSecret} -> Maybe SecretsManagerSecretConfiguration
secretsManagerSecret) (\s :: Configuration
s@Configuration' {} Maybe SecretsManagerSecretConfiguration
a -> Configuration
s {$sel:secretsManagerSecret:Configuration' :: Maybe SecretsManagerSecretConfiguration
secretsManagerSecret = Maybe SecretsManagerSecretConfiguration
a} :: Configuration)

-- | The access control configuration is for an Amazon SQS queue.
configuration_sqsQueue :: Lens.Lens' Configuration (Prelude.Maybe SqsQueueConfiguration)
configuration_sqsQueue :: (Maybe SqsQueueConfiguration -> f (Maybe SqsQueueConfiguration))
-> Configuration -> f Configuration
configuration_sqsQueue = (Configuration -> Maybe SqsQueueConfiguration)
-> (Configuration -> Maybe SqsQueueConfiguration -> Configuration)
-> Lens
     Configuration
     Configuration
     (Maybe SqsQueueConfiguration)
     (Maybe SqsQueueConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Configuration' {Maybe SqsQueueConfiguration
sqsQueue :: Maybe SqsQueueConfiguration
$sel:sqsQueue:Configuration' :: Configuration -> Maybe SqsQueueConfiguration
sqsQueue} -> Maybe SqsQueueConfiguration
sqsQueue) (\s :: Configuration
s@Configuration' {} Maybe SqsQueueConfiguration
a -> Configuration
s {$sel:sqsQueue:Configuration' :: Maybe SqsQueueConfiguration
sqsQueue = Maybe SqsQueueConfiguration
a} :: Configuration)

-- | The access control configuration is for an Amazon S3 Bucket.
configuration_s3Bucket :: Lens.Lens' Configuration (Prelude.Maybe S3BucketConfiguration)
configuration_s3Bucket :: (Maybe S3BucketConfiguration -> f (Maybe S3BucketConfiguration))
-> Configuration -> f Configuration
configuration_s3Bucket = (Configuration -> Maybe S3BucketConfiguration)
-> (Configuration -> Maybe S3BucketConfiguration -> Configuration)
-> Lens
     Configuration
     Configuration
     (Maybe S3BucketConfiguration)
     (Maybe S3BucketConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Configuration' {Maybe S3BucketConfiguration
s3Bucket :: Maybe S3BucketConfiguration
$sel:s3Bucket:Configuration' :: Configuration -> Maybe S3BucketConfiguration
s3Bucket} -> Maybe S3BucketConfiguration
s3Bucket) (\s :: Configuration
s@Configuration' {} Maybe S3BucketConfiguration
a -> Configuration
s {$sel:s3Bucket:Configuration' :: Maybe S3BucketConfiguration
s3Bucket = Maybe S3BucketConfiguration
a} :: Configuration)

-- | The access control configuration is for an IAM role.
configuration_iamRole :: Lens.Lens' Configuration (Prelude.Maybe IamRoleConfiguration)
configuration_iamRole :: (Maybe IamRoleConfiguration -> f (Maybe IamRoleConfiguration))
-> Configuration -> f Configuration
configuration_iamRole = (Configuration -> Maybe IamRoleConfiguration)
-> (Configuration -> Maybe IamRoleConfiguration -> Configuration)
-> Lens
     Configuration
     Configuration
     (Maybe IamRoleConfiguration)
     (Maybe IamRoleConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Configuration' {Maybe IamRoleConfiguration
iamRole :: Maybe IamRoleConfiguration
$sel:iamRole:Configuration' :: Configuration -> Maybe IamRoleConfiguration
iamRole} -> Maybe IamRoleConfiguration
iamRole) (\s :: Configuration
s@Configuration' {} Maybe IamRoleConfiguration
a -> Configuration
s {$sel:iamRole:Configuration' :: Maybe IamRoleConfiguration
iamRole = Maybe IamRoleConfiguration
a} :: Configuration)

instance Core.FromJSON Configuration where
  parseJSON :: Value -> Parser Configuration
parseJSON =
    String
-> (Object -> Parser Configuration)
-> Value
-> Parser Configuration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Configuration"
      ( \Object
x ->
          Maybe KmsKeyConfiguration
-> Maybe SecretsManagerSecretConfiguration
-> Maybe SqsQueueConfiguration
-> Maybe S3BucketConfiguration
-> Maybe IamRoleConfiguration
-> Configuration
Configuration'
            (Maybe KmsKeyConfiguration
 -> Maybe SecretsManagerSecretConfiguration
 -> Maybe SqsQueueConfiguration
 -> Maybe S3BucketConfiguration
 -> Maybe IamRoleConfiguration
 -> Configuration)
-> Parser (Maybe KmsKeyConfiguration)
-> Parser
     (Maybe SecretsManagerSecretConfiguration
      -> Maybe SqsQueueConfiguration
      -> Maybe S3BucketConfiguration
      -> Maybe IamRoleConfiguration
      -> Configuration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe KmsKeyConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"kmsKey")
            Parser
  (Maybe SecretsManagerSecretConfiguration
   -> Maybe SqsQueueConfiguration
   -> Maybe S3BucketConfiguration
   -> Maybe IamRoleConfiguration
   -> Configuration)
-> Parser (Maybe SecretsManagerSecretConfiguration)
-> Parser
     (Maybe SqsQueueConfiguration
      -> Maybe S3BucketConfiguration
      -> Maybe IamRoleConfiguration
      -> Configuration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe SecretsManagerSecretConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"secretsManagerSecret")
            Parser
  (Maybe SqsQueueConfiguration
   -> Maybe S3BucketConfiguration
   -> Maybe IamRoleConfiguration
   -> Configuration)
-> Parser (Maybe SqsQueueConfiguration)
-> Parser
     (Maybe S3BucketConfiguration
      -> Maybe IamRoleConfiguration -> Configuration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe SqsQueueConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"sqsQueue")
            Parser
  (Maybe S3BucketConfiguration
   -> Maybe IamRoleConfiguration -> Configuration)
-> Parser (Maybe S3BucketConfiguration)
-> Parser (Maybe IamRoleConfiguration -> Configuration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe S3BucketConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"s3Bucket")
            Parser (Maybe IamRoleConfiguration -> Configuration)
-> Parser (Maybe IamRoleConfiguration) -> Parser Configuration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe IamRoleConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"iamRole")
      )

instance Prelude.Hashable Configuration

instance Prelude.NFData Configuration

instance Core.ToJSON Configuration where
  toJSON :: Configuration -> Value
toJSON Configuration' {Maybe IamRoleConfiguration
Maybe KmsKeyConfiguration
Maybe SecretsManagerSecretConfiguration
Maybe SqsQueueConfiguration
Maybe S3BucketConfiguration
iamRole :: Maybe IamRoleConfiguration
s3Bucket :: Maybe S3BucketConfiguration
sqsQueue :: Maybe SqsQueueConfiguration
secretsManagerSecret :: Maybe SecretsManagerSecretConfiguration
kmsKey :: Maybe KmsKeyConfiguration
$sel:iamRole:Configuration' :: Configuration -> Maybe IamRoleConfiguration
$sel:s3Bucket:Configuration' :: Configuration -> Maybe S3BucketConfiguration
$sel:sqsQueue:Configuration' :: Configuration -> Maybe SqsQueueConfiguration
$sel:secretsManagerSecret:Configuration' :: Configuration -> Maybe SecretsManagerSecretConfiguration
$sel:kmsKey:Configuration' :: Configuration -> Maybe KmsKeyConfiguration
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"kmsKey" Text -> KmsKeyConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (KmsKeyConfiguration -> Pair)
-> Maybe KmsKeyConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe KmsKeyConfiguration
kmsKey,
            (Text
"secretsManagerSecret" Text -> SecretsManagerSecretConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (SecretsManagerSecretConfiguration -> Pair)
-> Maybe SecretsManagerSecretConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SecretsManagerSecretConfiguration
secretsManagerSecret,
            (Text
"sqsQueue" Text -> SqsQueueConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SqsQueueConfiguration -> Pair)
-> Maybe SqsQueueConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SqsQueueConfiguration
sqsQueue,
            (Text
"s3Bucket" Text -> S3BucketConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (S3BucketConfiguration -> Pair)
-> Maybe S3BucketConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe S3BucketConfiguration
s3Bucket,
            (Text
"iamRole" Text -> IamRoleConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (IamRoleConfiguration -> Pair)
-> Maybe IamRoleConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe IamRoleConfiguration
iamRole
          ]
      )