{-# 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.CertificateManagerPCA.Types.CsrExtensions
-- 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.CertificateManagerPCA.Types.CsrExtensions where

import Amazonka.CertificateManagerPCA.Types.AccessDescription
import Amazonka.CertificateManagerPCA.Types.KeyUsage
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes the certificate extensions to be added to the certificate
-- signing request (CSR).
--
-- /See:/ 'newCsrExtensions' smart constructor.
data CsrExtensions = CsrExtensions'
  { -- | For CA certificates, provides a path to additional information
    -- pertaining to the CA, such as revocation and policy. For more
    -- information, see
    -- <https://tools.ietf.org/html/rfc5280#section-4.2.2.2 Subject Information Access>
    -- in RFC 5280.
    CsrExtensions -> Maybe [AccessDescription]
subjectInformationAccess :: Prelude.Maybe [AccessDescription],
    -- | Indicates the purpose of the certificate and of the key contained in the
    -- certificate.
    CsrExtensions -> Maybe KeyUsage
keyUsage :: Prelude.Maybe KeyUsage
  }
  deriving (CsrExtensions -> CsrExtensions -> Bool
(CsrExtensions -> CsrExtensions -> Bool)
-> (CsrExtensions -> CsrExtensions -> Bool) -> Eq CsrExtensions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CsrExtensions -> CsrExtensions -> Bool
$c/= :: CsrExtensions -> CsrExtensions -> Bool
== :: CsrExtensions -> CsrExtensions -> Bool
$c== :: CsrExtensions -> CsrExtensions -> Bool
Prelude.Eq, ReadPrec [CsrExtensions]
ReadPrec CsrExtensions
Int -> ReadS CsrExtensions
ReadS [CsrExtensions]
(Int -> ReadS CsrExtensions)
-> ReadS [CsrExtensions]
-> ReadPrec CsrExtensions
-> ReadPrec [CsrExtensions]
-> Read CsrExtensions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CsrExtensions]
$creadListPrec :: ReadPrec [CsrExtensions]
readPrec :: ReadPrec CsrExtensions
$creadPrec :: ReadPrec CsrExtensions
readList :: ReadS [CsrExtensions]
$creadList :: ReadS [CsrExtensions]
readsPrec :: Int -> ReadS CsrExtensions
$creadsPrec :: Int -> ReadS CsrExtensions
Prelude.Read, Int -> CsrExtensions -> ShowS
[CsrExtensions] -> ShowS
CsrExtensions -> String
(Int -> CsrExtensions -> ShowS)
-> (CsrExtensions -> String)
-> ([CsrExtensions] -> ShowS)
-> Show CsrExtensions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CsrExtensions] -> ShowS
$cshowList :: [CsrExtensions] -> ShowS
show :: CsrExtensions -> String
$cshow :: CsrExtensions -> String
showsPrec :: Int -> CsrExtensions -> ShowS
$cshowsPrec :: Int -> CsrExtensions -> ShowS
Prelude.Show, (forall x. CsrExtensions -> Rep CsrExtensions x)
-> (forall x. Rep CsrExtensions x -> CsrExtensions)
-> Generic CsrExtensions
forall x. Rep CsrExtensions x -> CsrExtensions
forall x. CsrExtensions -> Rep CsrExtensions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CsrExtensions x -> CsrExtensions
$cfrom :: forall x. CsrExtensions -> Rep CsrExtensions x
Prelude.Generic)

-- |
-- Create a value of 'CsrExtensions' 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:
--
-- 'subjectInformationAccess', 'csrExtensions_subjectInformationAccess' - For CA certificates, provides a path to additional information
-- pertaining to the CA, such as revocation and policy. For more
-- information, see
-- <https://tools.ietf.org/html/rfc5280#section-4.2.2.2 Subject Information Access>
-- in RFC 5280.
--
-- 'keyUsage', 'csrExtensions_keyUsage' - Indicates the purpose of the certificate and of the key contained in the
-- certificate.
newCsrExtensions ::
  CsrExtensions
newCsrExtensions :: CsrExtensions
newCsrExtensions =
  CsrExtensions' :: Maybe [AccessDescription] -> Maybe KeyUsage -> CsrExtensions
CsrExtensions'
    { $sel:subjectInformationAccess:CsrExtensions' :: Maybe [AccessDescription]
subjectInformationAccess =
        Maybe [AccessDescription]
forall a. Maybe a
Prelude.Nothing,
      $sel:keyUsage:CsrExtensions' :: Maybe KeyUsage
keyUsage = Maybe KeyUsage
forall a. Maybe a
Prelude.Nothing
    }

-- | For CA certificates, provides a path to additional information
-- pertaining to the CA, such as revocation and policy. For more
-- information, see
-- <https://tools.ietf.org/html/rfc5280#section-4.2.2.2 Subject Information Access>
-- in RFC 5280.
csrExtensions_subjectInformationAccess :: Lens.Lens' CsrExtensions (Prelude.Maybe [AccessDescription])
csrExtensions_subjectInformationAccess :: (Maybe [AccessDescription] -> f (Maybe [AccessDescription]))
-> CsrExtensions -> f CsrExtensions
csrExtensions_subjectInformationAccess = (CsrExtensions -> Maybe [AccessDescription])
-> (CsrExtensions -> Maybe [AccessDescription] -> CsrExtensions)
-> Lens
     CsrExtensions
     CsrExtensions
     (Maybe [AccessDescription])
     (Maybe [AccessDescription])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CsrExtensions' {Maybe [AccessDescription]
subjectInformationAccess :: Maybe [AccessDescription]
$sel:subjectInformationAccess:CsrExtensions' :: CsrExtensions -> Maybe [AccessDescription]
subjectInformationAccess} -> Maybe [AccessDescription]
subjectInformationAccess) (\s :: CsrExtensions
s@CsrExtensions' {} Maybe [AccessDescription]
a -> CsrExtensions
s {$sel:subjectInformationAccess:CsrExtensions' :: Maybe [AccessDescription]
subjectInformationAccess = Maybe [AccessDescription]
a} :: CsrExtensions) ((Maybe [AccessDescription] -> f (Maybe [AccessDescription]))
 -> CsrExtensions -> f CsrExtensions)
-> ((Maybe [AccessDescription] -> f (Maybe [AccessDescription]))
    -> Maybe [AccessDescription] -> f (Maybe [AccessDescription]))
-> (Maybe [AccessDescription] -> f (Maybe [AccessDescription]))
-> CsrExtensions
-> f CsrExtensions
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [AccessDescription]
  [AccessDescription]
  [AccessDescription]
  [AccessDescription]
-> Iso
     (Maybe [AccessDescription])
     (Maybe [AccessDescription])
     (Maybe [AccessDescription])
     (Maybe [AccessDescription])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [AccessDescription]
  [AccessDescription]
  [AccessDescription]
  [AccessDescription]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Indicates the purpose of the certificate and of the key contained in the
-- certificate.
csrExtensions_keyUsage :: Lens.Lens' CsrExtensions (Prelude.Maybe KeyUsage)
csrExtensions_keyUsage :: (Maybe KeyUsage -> f (Maybe KeyUsage))
-> CsrExtensions -> f CsrExtensions
csrExtensions_keyUsage = (CsrExtensions -> Maybe KeyUsage)
-> (CsrExtensions -> Maybe KeyUsage -> CsrExtensions)
-> Lens
     CsrExtensions CsrExtensions (Maybe KeyUsage) (Maybe KeyUsage)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CsrExtensions' {Maybe KeyUsage
keyUsage :: Maybe KeyUsage
$sel:keyUsage:CsrExtensions' :: CsrExtensions -> Maybe KeyUsage
keyUsage} -> Maybe KeyUsage
keyUsage) (\s :: CsrExtensions
s@CsrExtensions' {} Maybe KeyUsage
a -> CsrExtensions
s {$sel:keyUsage:CsrExtensions' :: Maybe KeyUsage
keyUsage = Maybe KeyUsage
a} :: CsrExtensions)

instance Core.FromJSON CsrExtensions where
  parseJSON :: Value -> Parser CsrExtensions
parseJSON =
    String
-> (Object -> Parser CsrExtensions)
-> Value
-> Parser CsrExtensions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CsrExtensions"
      ( \Object
x ->
          Maybe [AccessDescription] -> Maybe KeyUsage -> CsrExtensions
CsrExtensions'
            (Maybe [AccessDescription] -> Maybe KeyUsage -> CsrExtensions)
-> Parser (Maybe [AccessDescription])
-> Parser (Maybe KeyUsage -> CsrExtensions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [AccessDescription]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SubjectInformationAccess"
                            Parser (Maybe (Maybe [AccessDescription]))
-> Maybe [AccessDescription] -> Parser (Maybe [AccessDescription])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [AccessDescription]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe KeyUsage -> CsrExtensions)
-> Parser (Maybe KeyUsage) -> Parser CsrExtensions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe KeyUsage)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"KeyUsage")
      )

instance Prelude.Hashable CsrExtensions

instance Prelude.NFData CsrExtensions

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