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

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

-- | For more information, see
-- <https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html Signature Version 4 signing process>.
--
-- /See:/ 'newSigV4Authorization' smart constructor.
data SigV4Authorization = SigV4Authorization'
  { -- | The signing region.
    SigV4Authorization -> Text
signingRegion :: Prelude.Text,
    -- | The service name to use while signing with Sig V4.
    SigV4Authorization -> Text
serviceName :: Prelude.Text,
    -- | The ARN of the signing role.
    SigV4Authorization -> Text
roleArn :: Prelude.Text
  }
  deriving (SigV4Authorization -> SigV4Authorization -> Bool
(SigV4Authorization -> SigV4Authorization -> Bool)
-> (SigV4Authorization -> SigV4Authorization -> Bool)
-> Eq SigV4Authorization
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SigV4Authorization -> SigV4Authorization -> Bool
$c/= :: SigV4Authorization -> SigV4Authorization -> Bool
== :: SigV4Authorization -> SigV4Authorization -> Bool
$c== :: SigV4Authorization -> SigV4Authorization -> Bool
Prelude.Eq, ReadPrec [SigV4Authorization]
ReadPrec SigV4Authorization
Int -> ReadS SigV4Authorization
ReadS [SigV4Authorization]
(Int -> ReadS SigV4Authorization)
-> ReadS [SigV4Authorization]
-> ReadPrec SigV4Authorization
-> ReadPrec [SigV4Authorization]
-> Read SigV4Authorization
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SigV4Authorization]
$creadListPrec :: ReadPrec [SigV4Authorization]
readPrec :: ReadPrec SigV4Authorization
$creadPrec :: ReadPrec SigV4Authorization
readList :: ReadS [SigV4Authorization]
$creadList :: ReadS [SigV4Authorization]
readsPrec :: Int -> ReadS SigV4Authorization
$creadsPrec :: Int -> ReadS SigV4Authorization
Prelude.Read, Int -> SigV4Authorization -> ShowS
[SigV4Authorization] -> ShowS
SigV4Authorization -> String
(Int -> SigV4Authorization -> ShowS)
-> (SigV4Authorization -> String)
-> ([SigV4Authorization] -> ShowS)
-> Show SigV4Authorization
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SigV4Authorization] -> ShowS
$cshowList :: [SigV4Authorization] -> ShowS
show :: SigV4Authorization -> String
$cshow :: SigV4Authorization -> String
showsPrec :: Int -> SigV4Authorization -> ShowS
$cshowsPrec :: Int -> SigV4Authorization -> ShowS
Prelude.Show, (forall x. SigV4Authorization -> Rep SigV4Authorization x)
-> (forall x. Rep SigV4Authorization x -> SigV4Authorization)
-> Generic SigV4Authorization
forall x. Rep SigV4Authorization x -> SigV4Authorization
forall x. SigV4Authorization -> Rep SigV4Authorization x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SigV4Authorization x -> SigV4Authorization
$cfrom :: forall x. SigV4Authorization -> Rep SigV4Authorization x
Prelude.Generic)

-- |
-- Create a value of 'SigV4Authorization' 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:
--
-- 'signingRegion', 'sigV4Authorization_signingRegion' - The signing region.
--
-- 'serviceName', 'sigV4Authorization_serviceName' - The service name to use while signing with Sig V4.
--
-- 'roleArn', 'sigV4Authorization_roleArn' - The ARN of the signing role.
newSigV4Authorization ::
  -- | 'signingRegion'
  Prelude.Text ->
  -- | 'serviceName'
  Prelude.Text ->
  -- | 'roleArn'
  Prelude.Text ->
  SigV4Authorization
newSigV4Authorization :: Text -> Text -> Text -> SigV4Authorization
newSigV4Authorization
  Text
pSigningRegion_
  Text
pServiceName_
  Text
pRoleArn_ =
    SigV4Authorization' :: Text -> Text -> Text -> SigV4Authorization
SigV4Authorization'
      { $sel:signingRegion:SigV4Authorization' :: Text
signingRegion =
          Text
pSigningRegion_,
        $sel:serviceName:SigV4Authorization' :: Text
serviceName = Text
pServiceName_,
        $sel:roleArn:SigV4Authorization' :: Text
roleArn = Text
pRoleArn_
      }

-- | The signing region.
sigV4Authorization_signingRegion :: Lens.Lens' SigV4Authorization Prelude.Text
sigV4Authorization_signingRegion :: (Text -> f Text) -> SigV4Authorization -> f SigV4Authorization
sigV4Authorization_signingRegion = (SigV4Authorization -> Text)
-> (SigV4Authorization -> Text -> SigV4Authorization)
-> Lens SigV4Authorization SigV4Authorization Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SigV4Authorization' {Text
signingRegion :: Text
$sel:signingRegion:SigV4Authorization' :: SigV4Authorization -> Text
signingRegion} -> Text
signingRegion) (\s :: SigV4Authorization
s@SigV4Authorization' {} Text
a -> SigV4Authorization
s {$sel:signingRegion:SigV4Authorization' :: Text
signingRegion = Text
a} :: SigV4Authorization)

-- | The service name to use while signing with Sig V4.
sigV4Authorization_serviceName :: Lens.Lens' SigV4Authorization Prelude.Text
sigV4Authorization_serviceName :: (Text -> f Text) -> SigV4Authorization -> f SigV4Authorization
sigV4Authorization_serviceName = (SigV4Authorization -> Text)
-> (SigV4Authorization -> Text -> SigV4Authorization)
-> Lens SigV4Authorization SigV4Authorization Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SigV4Authorization' {Text
serviceName :: Text
$sel:serviceName:SigV4Authorization' :: SigV4Authorization -> Text
serviceName} -> Text
serviceName) (\s :: SigV4Authorization
s@SigV4Authorization' {} Text
a -> SigV4Authorization
s {$sel:serviceName:SigV4Authorization' :: Text
serviceName = Text
a} :: SigV4Authorization)

-- | The ARN of the signing role.
sigV4Authorization_roleArn :: Lens.Lens' SigV4Authorization Prelude.Text
sigV4Authorization_roleArn :: (Text -> f Text) -> SigV4Authorization -> f SigV4Authorization
sigV4Authorization_roleArn = (SigV4Authorization -> Text)
-> (SigV4Authorization -> Text -> SigV4Authorization)
-> Lens SigV4Authorization SigV4Authorization Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SigV4Authorization' {Text
roleArn :: Text
$sel:roleArn:SigV4Authorization' :: SigV4Authorization -> Text
roleArn} -> Text
roleArn) (\s :: SigV4Authorization
s@SigV4Authorization' {} Text
a -> SigV4Authorization
s {$sel:roleArn:SigV4Authorization' :: Text
roleArn = Text
a} :: SigV4Authorization)

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

instance Prelude.Hashable SigV4Authorization

instance Prelude.NFData SigV4Authorization

instance Core.ToJSON SigV4Authorization where
  toJSON :: SigV4Authorization -> Value
toJSON SigV4Authorization' {Text
roleArn :: Text
serviceName :: Text
signingRegion :: Text
$sel:roleArn:SigV4Authorization' :: SigV4Authorization -> Text
$sel:serviceName:SigV4Authorization' :: SigV4Authorization -> Text
$sel:signingRegion:SigV4Authorization' :: SigV4Authorization -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"signingRegion" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
signingRegion),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"serviceName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
serviceName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"roleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleArn)
          ]
      )