{-# 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.HttpAuthorization
-- 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.HttpAuthorization where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.SigV4Authorization
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The authorization method used to send messages.
--
-- /See:/ 'newHttpAuthorization' smart constructor.
data HttpAuthorization = HttpAuthorization'
  { -- | Use Sig V4 authorization. For more information, see
    -- <https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html Signature Version 4 Signing Process>.
    HttpAuthorization -> Maybe SigV4Authorization
sigv4 :: Prelude.Maybe SigV4Authorization
  }
  deriving (HttpAuthorization -> HttpAuthorization -> Bool
(HttpAuthorization -> HttpAuthorization -> Bool)
-> (HttpAuthorization -> HttpAuthorization -> Bool)
-> Eq HttpAuthorization
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HttpAuthorization -> HttpAuthorization -> Bool
$c/= :: HttpAuthorization -> HttpAuthorization -> Bool
== :: HttpAuthorization -> HttpAuthorization -> Bool
$c== :: HttpAuthorization -> HttpAuthorization -> Bool
Prelude.Eq, ReadPrec [HttpAuthorization]
ReadPrec HttpAuthorization
Int -> ReadS HttpAuthorization
ReadS [HttpAuthorization]
(Int -> ReadS HttpAuthorization)
-> ReadS [HttpAuthorization]
-> ReadPrec HttpAuthorization
-> ReadPrec [HttpAuthorization]
-> Read HttpAuthorization
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HttpAuthorization]
$creadListPrec :: ReadPrec [HttpAuthorization]
readPrec :: ReadPrec HttpAuthorization
$creadPrec :: ReadPrec HttpAuthorization
readList :: ReadS [HttpAuthorization]
$creadList :: ReadS [HttpAuthorization]
readsPrec :: Int -> ReadS HttpAuthorization
$creadsPrec :: Int -> ReadS HttpAuthorization
Prelude.Read, Int -> HttpAuthorization -> ShowS
[HttpAuthorization] -> ShowS
HttpAuthorization -> String
(Int -> HttpAuthorization -> ShowS)
-> (HttpAuthorization -> String)
-> ([HttpAuthorization] -> ShowS)
-> Show HttpAuthorization
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HttpAuthorization] -> ShowS
$cshowList :: [HttpAuthorization] -> ShowS
show :: HttpAuthorization -> String
$cshow :: HttpAuthorization -> String
showsPrec :: Int -> HttpAuthorization -> ShowS
$cshowsPrec :: Int -> HttpAuthorization -> ShowS
Prelude.Show, (forall x. HttpAuthorization -> Rep HttpAuthorization x)
-> (forall x. Rep HttpAuthorization x -> HttpAuthorization)
-> Generic HttpAuthorization
forall x. Rep HttpAuthorization x -> HttpAuthorization
forall x. HttpAuthorization -> Rep HttpAuthorization x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HttpAuthorization x -> HttpAuthorization
$cfrom :: forall x. HttpAuthorization -> Rep HttpAuthorization x
Prelude.Generic)

-- |
-- Create a value of 'HttpAuthorization' 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:
--
-- 'sigv4', 'httpAuthorization_sigv4' - Use Sig V4 authorization. For more information, see
-- <https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html Signature Version 4 Signing Process>.
newHttpAuthorization ::
  HttpAuthorization
newHttpAuthorization :: HttpAuthorization
newHttpAuthorization =
  HttpAuthorization' :: Maybe SigV4Authorization -> HttpAuthorization
HttpAuthorization' {$sel:sigv4:HttpAuthorization' :: Maybe SigV4Authorization
sigv4 = Maybe SigV4Authorization
forall a. Maybe a
Prelude.Nothing}

-- | Use Sig V4 authorization. For more information, see
-- <https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html Signature Version 4 Signing Process>.
httpAuthorization_sigv4 :: Lens.Lens' HttpAuthorization (Prelude.Maybe SigV4Authorization)
httpAuthorization_sigv4 :: (Maybe SigV4Authorization -> f (Maybe SigV4Authorization))
-> HttpAuthorization -> f HttpAuthorization
httpAuthorization_sigv4 = (HttpAuthorization -> Maybe SigV4Authorization)
-> (HttpAuthorization
    -> Maybe SigV4Authorization -> HttpAuthorization)
-> Lens
     HttpAuthorization
     HttpAuthorization
     (Maybe SigV4Authorization)
     (Maybe SigV4Authorization)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpAuthorization' {Maybe SigV4Authorization
sigv4 :: Maybe SigV4Authorization
$sel:sigv4:HttpAuthorization' :: HttpAuthorization -> Maybe SigV4Authorization
sigv4} -> Maybe SigV4Authorization
sigv4) (\s :: HttpAuthorization
s@HttpAuthorization' {} Maybe SigV4Authorization
a -> HttpAuthorization
s {$sel:sigv4:HttpAuthorization' :: Maybe SigV4Authorization
sigv4 = Maybe SigV4Authorization
a} :: HttpAuthorization)

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

instance Prelude.Hashable HttpAuthorization

instance Prelude.NFData HttpAuthorization

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