{-# 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.AppSync.Types.AuthorizationConfig
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.AppSync.Types.AuthorizationConfig where

import Amazonka.AppSync.Types.AuthorizationType
import Amazonka.AppSync.Types.AwsIamConfig
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

-- | The authorization configuration in case the HTTP endpoint requires
-- authorization.
--
-- /See:/ 'newAuthorizationConfig' smart constructor.
data AuthorizationConfig = AuthorizationConfig'
  { -- | The Identity and Access Management (IAM) settings.
    AuthorizationConfig -> Maybe AwsIamConfig
awsIamConfig :: Prelude.Maybe AwsIamConfig,
    -- | The authorization type that the HTTP endpoint requires.
    --
    -- -   __AWS_IAM__: The authorization type is Signature Version 4 (SigV4).
    AuthorizationConfig -> AuthorizationType
authorizationType :: AuthorizationType
  }
  deriving (AuthorizationConfig -> AuthorizationConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AuthorizationConfig -> AuthorizationConfig -> Bool
$c/= :: AuthorizationConfig -> AuthorizationConfig -> Bool
== :: AuthorizationConfig -> AuthorizationConfig -> Bool
$c== :: AuthorizationConfig -> AuthorizationConfig -> Bool
Prelude.Eq, ReadPrec [AuthorizationConfig]
ReadPrec AuthorizationConfig
Int -> ReadS AuthorizationConfig
ReadS [AuthorizationConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AuthorizationConfig]
$creadListPrec :: ReadPrec [AuthorizationConfig]
readPrec :: ReadPrec AuthorizationConfig
$creadPrec :: ReadPrec AuthorizationConfig
readList :: ReadS [AuthorizationConfig]
$creadList :: ReadS [AuthorizationConfig]
readsPrec :: Int -> ReadS AuthorizationConfig
$creadsPrec :: Int -> ReadS AuthorizationConfig
Prelude.Read, Int -> AuthorizationConfig -> ShowS
[AuthorizationConfig] -> ShowS
AuthorizationConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuthorizationConfig] -> ShowS
$cshowList :: [AuthorizationConfig] -> ShowS
show :: AuthorizationConfig -> String
$cshow :: AuthorizationConfig -> String
showsPrec :: Int -> AuthorizationConfig -> ShowS
$cshowsPrec :: Int -> AuthorizationConfig -> ShowS
Prelude.Show, forall x. Rep AuthorizationConfig x -> AuthorizationConfig
forall x. AuthorizationConfig -> Rep AuthorizationConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AuthorizationConfig x -> AuthorizationConfig
$cfrom :: forall x. AuthorizationConfig -> Rep AuthorizationConfig x
Prelude.Generic)

-- |
-- Create a value of 'AuthorizationConfig' 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:
--
-- 'awsIamConfig', 'authorizationConfig_awsIamConfig' - The Identity and Access Management (IAM) settings.
--
-- 'authorizationType', 'authorizationConfig_authorizationType' - The authorization type that the HTTP endpoint requires.
--
-- -   __AWS_IAM__: The authorization type is Signature Version 4 (SigV4).
newAuthorizationConfig ::
  -- | 'authorizationType'
  AuthorizationType ->
  AuthorizationConfig
newAuthorizationConfig :: AuthorizationType -> AuthorizationConfig
newAuthorizationConfig AuthorizationType
pAuthorizationType_ =
  AuthorizationConfig'
    { $sel:awsIamConfig:AuthorizationConfig' :: Maybe AwsIamConfig
awsIamConfig =
        forall a. Maybe a
Prelude.Nothing,
      $sel:authorizationType:AuthorizationConfig' :: AuthorizationType
authorizationType = AuthorizationType
pAuthorizationType_
    }

-- | The Identity and Access Management (IAM) settings.
authorizationConfig_awsIamConfig :: Lens.Lens' AuthorizationConfig (Prelude.Maybe AwsIamConfig)
authorizationConfig_awsIamConfig :: Lens' AuthorizationConfig (Maybe AwsIamConfig)
authorizationConfig_awsIamConfig = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthorizationConfig' {Maybe AwsIamConfig
awsIamConfig :: Maybe AwsIamConfig
$sel:awsIamConfig:AuthorizationConfig' :: AuthorizationConfig -> Maybe AwsIamConfig
awsIamConfig} -> Maybe AwsIamConfig
awsIamConfig) (\s :: AuthorizationConfig
s@AuthorizationConfig' {} Maybe AwsIamConfig
a -> AuthorizationConfig
s {$sel:awsIamConfig:AuthorizationConfig' :: Maybe AwsIamConfig
awsIamConfig = Maybe AwsIamConfig
a} :: AuthorizationConfig)

-- | The authorization type that the HTTP endpoint requires.
--
-- -   __AWS_IAM__: The authorization type is Signature Version 4 (SigV4).
authorizationConfig_authorizationType :: Lens.Lens' AuthorizationConfig AuthorizationType
authorizationConfig_authorizationType :: Lens' AuthorizationConfig AuthorizationType
authorizationConfig_authorizationType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthorizationConfig' {AuthorizationType
authorizationType :: AuthorizationType
$sel:authorizationType:AuthorizationConfig' :: AuthorizationConfig -> AuthorizationType
authorizationType} -> AuthorizationType
authorizationType) (\s :: AuthorizationConfig
s@AuthorizationConfig' {} AuthorizationType
a -> AuthorizationConfig
s {$sel:authorizationType:AuthorizationConfig' :: AuthorizationType
authorizationType = AuthorizationType
a} :: AuthorizationConfig)

instance Data.FromJSON AuthorizationConfig where
  parseJSON :: Value -> Parser AuthorizationConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AuthorizationConfig"
      ( \Object
x ->
          Maybe AwsIamConfig -> AuthorizationType -> AuthorizationConfig
AuthorizationConfig'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"awsIamConfig")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"authorizationType")
      )

instance Prelude.Hashable AuthorizationConfig where
  hashWithSalt :: Int -> AuthorizationConfig -> Int
hashWithSalt Int
_salt AuthorizationConfig' {Maybe AwsIamConfig
AuthorizationType
authorizationType :: AuthorizationType
awsIamConfig :: Maybe AwsIamConfig
$sel:authorizationType:AuthorizationConfig' :: AuthorizationConfig -> AuthorizationType
$sel:awsIamConfig:AuthorizationConfig' :: AuthorizationConfig -> Maybe AwsIamConfig
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AwsIamConfig
awsIamConfig
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` AuthorizationType
authorizationType

instance Prelude.NFData AuthorizationConfig where
  rnf :: AuthorizationConfig -> ()
rnf AuthorizationConfig' {Maybe AwsIamConfig
AuthorizationType
authorizationType :: AuthorizationType
awsIamConfig :: Maybe AwsIamConfig
$sel:authorizationType:AuthorizationConfig' :: AuthorizationConfig -> AuthorizationType
$sel:awsIamConfig:AuthorizationConfig' :: AuthorizationConfig -> Maybe AwsIamConfig
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe AwsIamConfig
awsIamConfig
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf AuthorizationType
authorizationType

instance Data.ToJSON AuthorizationConfig where
  toJSON :: AuthorizationConfig -> Value
toJSON AuthorizationConfig' {Maybe AwsIamConfig
AuthorizationType
authorizationType :: AuthorizationType
awsIamConfig :: Maybe AwsIamConfig
$sel:authorizationType:AuthorizationConfig' :: AuthorizationConfig -> AuthorizationType
$sel:awsIamConfig:AuthorizationConfig' :: AuthorizationConfig -> Maybe AwsIamConfig
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"awsIamConfig" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AwsIamConfig
awsIamConfig,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"authorizationType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= AuthorizationType
authorizationType)
          ]
      )