{-# 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.IoT.Types.AuthorizerConfig
-- 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.IoT.Types.AuthorizerConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that specifies the authorization service for a domain.
--
-- /See:/ 'newAuthorizerConfig' smart constructor.
data AuthorizerConfig = AuthorizerConfig'
  { -- | A Boolean that specifies whether the domain configuration\'s
    -- authorization service can be overridden.
    AuthorizerConfig -> Maybe Bool
allowAuthorizerOverride :: Prelude.Maybe Prelude.Bool,
    -- | The name of the authorization service for a domain configuration.
    AuthorizerConfig -> Maybe Text
defaultAuthorizerName :: Prelude.Maybe Prelude.Text
  }
  deriving (AuthorizerConfig -> AuthorizerConfig -> Bool
(AuthorizerConfig -> AuthorizerConfig -> Bool)
-> (AuthorizerConfig -> AuthorizerConfig -> Bool)
-> Eq AuthorizerConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AuthorizerConfig -> AuthorizerConfig -> Bool
$c/= :: AuthorizerConfig -> AuthorizerConfig -> Bool
== :: AuthorizerConfig -> AuthorizerConfig -> Bool
$c== :: AuthorizerConfig -> AuthorizerConfig -> Bool
Prelude.Eq, ReadPrec [AuthorizerConfig]
ReadPrec AuthorizerConfig
Int -> ReadS AuthorizerConfig
ReadS [AuthorizerConfig]
(Int -> ReadS AuthorizerConfig)
-> ReadS [AuthorizerConfig]
-> ReadPrec AuthorizerConfig
-> ReadPrec [AuthorizerConfig]
-> Read AuthorizerConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AuthorizerConfig]
$creadListPrec :: ReadPrec [AuthorizerConfig]
readPrec :: ReadPrec AuthorizerConfig
$creadPrec :: ReadPrec AuthorizerConfig
readList :: ReadS [AuthorizerConfig]
$creadList :: ReadS [AuthorizerConfig]
readsPrec :: Int -> ReadS AuthorizerConfig
$creadsPrec :: Int -> ReadS AuthorizerConfig
Prelude.Read, Int -> AuthorizerConfig -> ShowS
[AuthorizerConfig] -> ShowS
AuthorizerConfig -> String
(Int -> AuthorizerConfig -> ShowS)
-> (AuthorizerConfig -> String)
-> ([AuthorizerConfig] -> ShowS)
-> Show AuthorizerConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuthorizerConfig] -> ShowS
$cshowList :: [AuthorizerConfig] -> ShowS
show :: AuthorizerConfig -> String
$cshow :: AuthorizerConfig -> String
showsPrec :: Int -> AuthorizerConfig -> ShowS
$cshowsPrec :: Int -> AuthorizerConfig -> ShowS
Prelude.Show, (forall x. AuthorizerConfig -> Rep AuthorizerConfig x)
-> (forall x. Rep AuthorizerConfig x -> AuthorizerConfig)
-> Generic AuthorizerConfig
forall x. Rep AuthorizerConfig x -> AuthorizerConfig
forall x. AuthorizerConfig -> Rep AuthorizerConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AuthorizerConfig x -> AuthorizerConfig
$cfrom :: forall x. AuthorizerConfig -> Rep AuthorizerConfig x
Prelude.Generic)

-- |
-- Create a value of 'AuthorizerConfig' 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:
--
-- 'allowAuthorizerOverride', 'authorizerConfig_allowAuthorizerOverride' - A Boolean that specifies whether the domain configuration\'s
-- authorization service can be overridden.
--
-- 'defaultAuthorizerName', 'authorizerConfig_defaultAuthorizerName' - The name of the authorization service for a domain configuration.
newAuthorizerConfig ::
  AuthorizerConfig
newAuthorizerConfig :: AuthorizerConfig
newAuthorizerConfig =
  AuthorizerConfig' :: Maybe Bool -> Maybe Text -> AuthorizerConfig
AuthorizerConfig'
    { $sel:allowAuthorizerOverride:AuthorizerConfig' :: Maybe Bool
allowAuthorizerOverride =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:defaultAuthorizerName:AuthorizerConfig' :: Maybe Text
defaultAuthorizerName = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | A Boolean that specifies whether the domain configuration\'s
-- authorization service can be overridden.
authorizerConfig_allowAuthorizerOverride :: Lens.Lens' AuthorizerConfig (Prelude.Maybe Prelude.Bool)
authorizerConfig_allowAuthorizerOverride :: (Maybe Bool -> f (Maybe Bool))
-> AuthorizerConfig -> f AuthorizerConfig
authorizerConfig_allowAuthorizerOverride = (AuthorizerConfig -> Maybe Bool)
-> (AuthorizerConfig -> Maybe Bool -> AuthorizerConfig)
-> Lens AuthorizerConfig AuthorizerConfig (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthorizerConfig' {Maybe Bool
allowAuthorizerOverride :: Maybe Bool
$sel:allowAuthorizerOverride:AuthorizerConfig' :: AuthorizerConfig -> Maybe Bool
allowAuthorizerOverride} -> Maybe Bool
allowAuthorizerOverride) (\s :: AuthorizerConfig
s@AuthorizerConfig' {} Maybe Bool
a -> AuthorizerConfig
s {$sel:allowAuthorizerOverride:AuthorizerConfig' :: Maybe Bool
allowAuthorizerOverride = Maybe Bool
a} :: AuthorizerConfig)

-- | The name of the authorization service for a domain configuration.
authorizerConfig_defaultAuthorizerName :: Lens.Lens' AuthorizerConfig (Prelude.Maybe Prelude.Text)
authorizerConfig_defaultAuthorizerName :: (Maybe Text -> f (Maybe Text))
-> AuthorizerConfig -> f AuthorizerConfig
authorizerConfig_defaultAuthorizerName = (AuthorizerConfig -> Maybe Text)
-> (AuthorizerConfig -> Maybe Text -> AuthorizerConfig)
-> Lens AuthorizerConfig AuthorizerConfig (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthorizerConfig' {Maybe Text
defaultAuthorizerName :: Maybe Text
$sel:defaultAuthorizerName:AuthorizerConfig' :: AuthorizerConfig -> Maybe Text
defaultAuthorizerName} -> Maybe Text
defaultAuthorizerName) (\s :: AuthorizerConfig
s@AuthorizerConfig' {} Maybe Text
a -> AuthorizerConfig
s {$sel:defaultAuthorizerName:AuthorizerConfig' :: Maybe Text
defaultAuthorizerName = Maybe Text
a} :: AuthorizerConfig)

instance Core.FromJSON AuthorizerConfig where
  parseJSON :: Value -> Parser AuthorizerConfig
parseJSON =
    String
-> (Object -> Parser AuthorizerConfig)
-> Value
-> Parser AuthorizerConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AuthorizerConfig"
      ( \Object
x ->
          Maybe Bool -> Maybe Text -> AuthorizerConfig
AuthorizerConfig'
            (Maybe Bool -> Maybe Text -> AuthorizerConfig)
-> Parser (Maybe Bool) -> Parser (Maybe Text -> AuthorizerConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"allowAuthorizerOverride")
            Parser (Maybe Text -> AuthorizerConfig)
-> Parser (Maybe Text) -> Parser AuthorizerConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"defaultAuthorizerName")
      )

instance Prelude.Hashable AuthorizerConfig

instance Prelude.NFData AuthorizerConfig

instance Core.ToJSON AuthorizerConfig where
  toJSON :: AuthorizerConfig -> Value
toJSON AuthorizerConfig' {Maybe Bool
Maybe Text
defaultAuthorizerName :: Maybe Text
allowAuthorizerOverride :: Maybe Bool
$sel:defaultAuthorizerName:AuthorizerConfig' :: AuthorizerConfig -> Maybe Text
$sel:allowAuthorizerOverride:AuthorizerConfig' :: AuthorizerConfig -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"allowAuthorizerOverride" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
allowAuthorizerOverride,
            (Text
"defaultAuthorizerName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
defaultAuthorizerName
          ]
      )