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

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

-- | 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
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]
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
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. 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'
      { $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 :: Lens' SigV4Authorization Text
sigV4Authorization_signingRegion = 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 :: Lens' SigV4Authorization Text
sigV4Authorization_serviceName = 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 :: Lens' SigV4Authorization Text
sigV4Authorization_roleArn = 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 Data.FromJSON SigV4Authorization where
  parseJSON :: Value -> Parser SigV4Authorization
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SigV4Authorization"
      ( \Object
x ->
          Text -> Text -> Text -> SigV4Authorization
SigV4Authorization'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"signingRegion")
            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
"serviceName")
            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
"roleArn")
      )

instance Prelude.Hashable SigV4Authorization where
  hashWithSalt :: Int -> SigV4Authorization -> Int
hashWithSalt Int
_salt SigV4Authorization' {Text
roleArn :: Text
serviceName :: Text
signingRegion :: Text
$sel:roleArn:SigV4Authorization' :: SigV4Authorization -> Text
$sel:serviceName:SigV4Authorization' :: SigV4Authorization -> Text
$sel:signingRegion:SigV4Authorization' :: SigV4Authorization -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
signingRegion
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
serviceName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleArn

instance Prelude.NFData SigV4Authorization where
  rnf :: SigV4Authorization -> ()
rnf SigV4Authorization' {Text
roleArn :: Text
serviceName :: Text
signingRegion :: Text
$sel:roleArn:SigV4Authorization' :: SigV4Authorization -> Text
$sel:serviceName:SigV4Authorization' :: SigV4Authorization -> Text
$sel:signingRegion:SigV4Authorization' :: SigV4Authorization -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
signingRegion
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
serviceName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
roleArn

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"signingRegion" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
signingRegion),
            forall a. a -> Maybe a
Prelude.Just (Key
"serviceName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
serviceName),
            forall a. a -> Maybe a
Prelude.Just (Key
"roleArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
roleArn)
          ]
      )