{-# 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-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.AppSync.Types.AuthorizationConfig where

import Amazonka.AppSync.Types.AuthorizationType
import Amazonka.AppSync.Types.AwsIamConfig
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The authorization config in case the HTTP endpoint requires
-- authorization.
--
-- /See:/ 'newAuthorizationConfig' smart constructor.
data AuthorizationConfig = AuthorizationConfig'
  { -- | The Identity and Access Management settings.
    AuthorizationConfig -> Maybe AwsIamConfig
awsIamConfig :: Prelude.Maybe AwsIamConfig,
    -- | The authorization type required by the HTTP endpoint.
    --
    -- -   __AWS_IAM__: The authorization type is Sigv4.
    AuthorizationConfig -> AuthorizationType
authorizationType :: AuthorizationType
  }
  deriving (AuthorizationConfig -> AuthorizationConfig -> Bool
(AuthorizationConfig -> AuthorizationConfig -> Bool)
-> (AuthorizationConfig -> AuthorizationConfig -> Bool)
-> Eq AuthorizationConfig
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]
(Int -> ReadS AuthorizationConfig)
-> ReadS [AuthorizationConfig]
-> ReadPrec AuthorizationConfig
-> ReadPrec [AuthorizationConfig]
-> Read 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
(Int -> AuthorizationConfig -> ShowS)
-> (AuthorizationConfig -> String)
-> ([AuthorizationConfig] -> ShowS)
-> Show AuthorizationConfig
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. AuthorizationConfig -> Rep AuthorizationConfig x)
-> (forall x. Rep AuthorizationConfig x -> AuthorizationConfig)
-> Generic AuthorizationConfig
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 settings.
--
-- 'authorizationType', 'authorizationConfig_authorizationType' - The authorization type required by the HTTP endpoint.
--
-- -   __AWS_IAM__: The authorization type is Sigv4.
newAuthorizationConfig ::
  -- | 'authorizationType'
  AuthorizationType ->
  AuthorizationConfig
newAuthorizationConfig :: AuthorizationType -> AuthorizationConfig
newAuthorizationConfig AuthorizationType
pAuthorizationType_ =
  AuthorizationConfig' :: Maybe AwsIamConfig -> AuthorizationType -> AuthorizationConfig
AuthorizationConfig'
    { $sel:awsIamConfig:AuthorizationConfig' :: Maybe AwsIamConfig
awsIamConfig =
        Maybe AwsIamConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:authorizationType:AuthorizationConfig' :: AuthorizationType
authorizationType = AuthorizationType
pAuthorizationType_
    }

-- | The Identity and Access Management settings.
authorizationConfig_awsIamConfig :: Lens.Lens' AuthorizationConfig (Prelude.Maybe AwsIamConfig)
authorizationConfig_awsIamConfig :: (Maybe AwsIamConfig -> f (Maybe AwsIamConfig))
-> AuthorizationConfig -> f AuthorizationConfig
authorizationConfig_awsIamConfig = (AuthorizationConfig -> Maybe AwsIamConfig)
-> (AuthorizationConfig
    -> Maybe AwsIamConfig -> AuthorizationConfig)
-> Lens
     AuthorizationConfig
     AuthorizationConfig
     (Maybe AwsIamConfig)
     (Maybe 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 required by the HTTP endpoint.
--
-- -   __AWS_IAM__: The authorization type is Sigv4.
authorizationConfig_authorizationType :: Lens.Lens' AuthorizationConfig AuthorizationType
authorizationConfig_authorizationType :: (AuthorizationType -> f AuthorizationType)
-> AuthorizationConfig -> f AuthorizationConfig
authorizationConfig_authorizationType = (AuthorizationConfig -> AuthorizationType)
-> (AuthorizationConfig
    -> AuthorizationType -> AuthorizationConfig)
-> Lens
     AuthorizationConfig
     AuthorizationConfig
     AuthorizationType
     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 Core.FromJSON AuthorizationConfig where
  parseJSON :: Value -> Parser AuthorizationConfig
parseJSON =
    String
-> (Object -> Parser AuthorizationConfig)
-> Value
-> Parser AuthorizationConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AuthorizationConfig"
      ( \Object
x ->
          Maybe AwsIamConfig -> AuthorizationType -> AuthorizationConfig
AuthorizationConfig'
            (Maybe AwsIamConfig -> AuthorizationType -> AuthorizationConfig)
-> Parser (Maybe AwsIamConfig)
-> Parser (AuthorizationType -> AuthorizationConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe AwsIamConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"awsIamConfig")
            Parser (AuthorizationType -> AuthorizationConfig)
-> Parser AuthorizationType -> Parser AuthorizationConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser AuthorizationType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"authorizationType")
      )

instance Prelude.Hashable AuthorizationConfig

instance Prelude.NFData AuthorizationConfig

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"awsIamConfig" Text -> AwsIamConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (AwsIamConfig -> Pair) -> Maybe AwsIamConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AwsIamConfig
awsIamConfig,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"authorizationType" Text -> AuthorizationType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AuthorizationType
authorizationType)
          ]
      )