{-# 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.RolesAnywhere.Types.SourceData
-- 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.RolesAnywhere.Types.SourceData 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

-- | The data field of the trust anchor depending on its type.
--
-- /See:/ 'newSourceData' smart constructor.
data SourceData = SourceData'
  { -- | The root certificate of the Certificate Manager Private Certificate
    -- Authority specified by this ARN is used in trust validation for
    -- <https://docs.aws.amazon.com/rolesanywhere/latest/APIReference/API_CreateSession.html CreateSession>
    -- operations. Included for trust anchors of type @AWS_ACM_PCA@.
    SourceData -> Maybe Text
acmPcaArn :: Prelude.Maybe Prelude.Text,
    -- | The PEM-encoded data for the certificate anchor. Included for trust
    -- anchors of type @CERTIFICATE_BUNDLE@.
    SourceData -> Maybe Text
x509CertificateData :: Prelude.Maybe Prelude.Text
  }
  deriving (SourceData -> SourceData -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SourceData -> SourceData -> Bool
$c/= :: SourceData -> SourceData -> Bool
== :: SourceData -> SourceData -> Bool
$c== :: SourceData -> SourceData -> Bool
Prelude.Eq, ReadPrec [SourceData]
ReadPrec SourceData
Int -> ReadS SourceData
ReadS [SourceData]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SourceData]
$creadListPrec :: ReadPrec [SourceData]
readPrec :: ReadPrec SourceData
$creadPrec :: ReadPrec SourceData
readList :: ReadS [SourceData]
$creadList :: ReadS [SourceData]
readsPrec :: Int -> ReadS SourceData
$creadsPrec :: Int -> ReadS SourceData
Prelude.Read, Int -> SourceData -> ShowS
[SourceData] -> ShowS
SourceData -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SourceData] -> ShowS
$cshowList :: [SourceData] -> ShowS
show :: SourceData -> String
$cshow :: SourceData -> String
showsPrec :: Int -> SourceData -> ShowS
$cshowsPrec :: Int -> SourceData -> ShowS
Prelude.Show, forall x. Rep SourceData x -> SourceData
forall x. SourceData -> Rep SourceData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SourceData x -> SourceData
$cfrom :: forall x. SourceData -> Rep SourceData x
Prelude.Generic)

-- |
-- Create a value of 'SourceData' 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:
--
-- 'acmPcaArn', 'sourceData_acmPcaArn' - The root certificate of the Certificate Manager Private Certificate
-- Authority specified by this ARN is used in trust validation for
-- <https://docs.aws.amazon.com/rolesanywhere/latest/APIReference/API_CreateSession.html CreateSession>
-- operations. Included for trust anchors of type @AWS_ACM_PCA@.
--
-- 'x509CertificateData', 'sourceData_x509CertificateData' - The PEM-encoded data for the certificate anchor. Included for trust
-- anchors of type @CERTIFICATE_BUNDLE@.
newSourceData ::
  SourceData
newSourceData :: SourceData
newSourceData =
  SourceData'
    { $sel:acmPcaArn:SourceData' :: Maybe Text
acmPcaArn = forall a. Maybe a
Prelude.Nothing,
      $sel:x509CertificateData:SourceData' :: Maybe Text
x509CertificateData = forall a. Maybe a
Prelude.Nothing
    }

-- | The root certificate of the Certificate Manager Private Certificate
-- Authority specified by this ARN is used in trust validation for
-- <https://docs.aws.amazon.com/rolesanywhere/latest/APIReference/API_CreateSession.html CreateSession>
-- operations. Included for trust anchors of type @AWS_ACM_PCA@.
sourceData_acmPcaArn :: Lens.Lens' SourceData (Prelude.Maybe Prelude.Text)
sourceData_acmPcaArn :: Lens' SourceData (Maybe Text)
sourceData_acmPcaArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceData' {Maybe Text
acmPcaArn :: Maybe Text
$sel:acmPcaArn:SourceData' :: SourceData -> Maybe Text
acmPcaArn} -> Maybe Text
acmPcaArn) (\s :: SourceData
s@SourceData' {} Maybe Text
a -> SourceData
s {$sel:acmPcaArn:SourceData' :: Maybe Text
acmPcaArn = Maybe Text
a} :: SourceData)

-- | The PEM-encoded data for the certificate anchor. Included for trust
-- anchors of type @CERTIFICATE_BUNDLE@.
sourceData_x509CertificateData :: Lens.Lens' SourceData (Prelude.Maybe Prelude.Text)
sourceData_x509CertificateData :: Lens' SourceData (Maybe Text)
sourceData_x509CertificateData = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceData' {Maybe Text
x509CertificateData :: Maybe Text
$sel:x509CertificateData:SourceData' :: SourceData -> Maybe Text
x509CertificateData} -> Maybe Text
x509CertificateData) (\s :: SourceData
s@SourceData' {} Maybe Text
a -> SourceData
s {$sel:x509CertificateData:SourceData' :: Maybe Text
x509CertificateData = Maybe Text
a} :: SourceData)

instance Data.FromJSON SourceData where
  parseJSON :: Value -> Parser SourceData
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SourceData"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> SourceData
SourceData'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"acmPcaArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"x509CertificateData")
      )

instance Prelude.Hashable SourceData where
  hashWithSalt :: Int -> SourceData -> Int
hashWithSalt Int
_salt SourceData' {Maybe Text
x509CertificateData :: Maybe Text
acmPcaArn :: Maybe Text
$sel:x509CertificateData:SourceData' :: SourceData -> Maybe Text
$sel:acmPcaArn:SourceData' :: SourceData -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
acmPcaArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
x509CertificateData

instance Prelude.NFData SourceData where
  rnf :: SourceData -> ()
rnf SourceData' {Maybe Text
x509CertificateData :: Maybe Text
acmPcaArn :: Maybe Text
$sel:x509CertificateData:SourceData' :: SourceData -> Maybe Text
$sel:acmPcaArn:SourceData' :: SourceData -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
acmPcaArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
x509CertificateData

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