{-# 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.AppMesh.Types.TlsValidationContext
-- 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.AppMesh.Types.TlsValidationContext where

import Amazonka.AppMesh.Types.SubjectAlternativeNames
import Amazonka.AppMesh.Types.TlsValidationContextTrust
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that represents how the proxy will validate its peer during
-- Transport Layer Security (TLS) negotiation.
--
-- /See:/ 'newTlsValidationContext' smart constructor.
data TlsValidationContext = TlsValidationContext'
  { -- | A reference to an object that represents the SANs for a Transport Layer
    -- Security (TLS) validation context.
    TlsValidationContext -> Maybe SubjectAlternativeNames
subjectAlternativeNames :: Prelude.Maybe SubjectAlternativeNames,
    -- | A reference to where to retrieve the trust chain when validating a
    -- peer’s Transport Layer Security (TLS) certificate.
    TlsValidationContext -> TlsValidationContextTrust
trust :: TlsValidationContextTrust
  }
  deriving (TlsValidationContext -> TlsValidationContext -> Bool
(TlsValidationContext -> TlsValidationContext -> Bool)
-> (TlsValidationContext -> TlsValidationContext -> Bool)
-> Eq TlsValidationContext
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TlsValidationContext -> TlsValidationContext -> Bool
$c/= :: TlsValidationContext -> TlsValidationContext -> Bool
== :: TlsValidationContext -> TlsValidationContext -> Bool
$c== :: TlsValidationContext -> TlsValidationContext -> Bool
Prelude.Eq, ReadPrec [TlsValidationContext]
ReadPrec TlsValidationContext
Int -> ReadS TlsValidationContext
ReadS [TlsValidationContext]
(Int -> ReadS TlsValidationContext)
-> ReadS [TlsValidationContext]
-> ReadPrec TlsValidationContext
-> ReadPrec [TlsValidationContext]
-> Read TlsValidationContext
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TlsValidationContext]
$creadListPrec :: ReadPrec [TlsValidationContext]
readPrec :: ReadPrec TlsValidationContext
$creadPrec :: ReadPrec TlsValidationContext
readList :: ReadS [TlsValidationContext]
$creadList :: ReadS [TlsValidationContext]
readsPrec :: Int -> ReadS TlsValidationContext
$creadsPrec :: Int -> ReadS TlsValidationContext
Prelude.Read, Int -> TlsValidationContext -> ShowS
[TlsValidationContext] -> ShowS
TlsValidationContext -> String
(Int -> TlsValidationContext -> ShowS)
-> (TlsValidationContext -> String)
-> ([TlsValidationContext] -> ShowS)
-> Show TlsValidationContext
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TlsValidationContext] -> ShowS
$cshowList :: [TlsValidationContext] -> ShowS
show :: TlsValidationContext -> String
$cshow :: TlsValidationContext -> String
showsPrec :: Int -> TlsValidationContext -> ShowS
$cshowsPrec :: Int -> TlsValidationContext -> ShowS
Prelude.Show, (forall x. TlsValidationContext -> Rep TlsValidationContext x)
-> (forall x. Rep TlsValidationContext x -> TlsValidationContext)
-> Generic TlsValidationContext
forall x. Rep TlsValidationContext x -> TlsValidationContext
forall x. TlsValidationContext -> Rep TlsValidationContext x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TlsValidationContext x -> TlsValidationContext
$cfrom :: forall x. TlsValidationContext -> Rep TlsValidationContext x
Prelude.Generic)

-- |
-- Create a value of 'TlsValidationContext' 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:
--
-- 'subjectAlternativeNames', 'tlsValidationContext_subjectAlternativeNames' - A reference to an object that represents the SANs for a Transport Layer
-- Security (TLS) validation context.
--
-- 'trust', 'tlsValidationContext_trust' - A reference to where to retrieve the trust chain when validating a
-- peer’s Transport Layer Security (TLS) certificate.
newTlsValidationContext ::
  -- | 'trust'
  TlsValidationContextTrust ->
  TlsValidationContext
newTlsValidationContext :: TlsValidationContextTrust -> TlsValidationContext
newTlsValidationContext TlsValidationContextTrust
pTrust_ =
  TlsValidationContext' :: Maybe SubjectAlternativeNames
-> TlsValidationContextTrust -> TlsValidationContext
TlsValidationContext'
    { $sel:subjectAlternativeNames:TlsValidationContext' :: Maybe SubjectAlternativeNames
subjectAlternativeNames =
        Maybe SubjectAlternativeNames
forall a. Maybe a
Prelude.Nothing,
      $sel:trust:TlsValidationContext' :: TlsValidationContextTrust
trust = TlsValidationContextTrust
pTrust_
    }

-- | A reference to an object that represents the SANs for a Transport Layer
-- Security (TLS) validation context.
tlsValidationContext_subjectAlternativeNames :: Lens.Lens' TlsValidationContext (Prelude.Maybe SubjectAlternativeNames)
tlsValidationContext_subjectAlternativeNames :: (Maybe SubjectAlternativeNames
 -> f (Maybe SubjectAlternativeNames))
-> TlsValidationContext -> f TlsValidationContext
tlsValidationContext_subjectAlternativeNames = (TlsValidationContext -> Maybe SubjectAlternativeNames)
-> (TlsValidationContext
    -> Maybe SubjectAlternativeNames -> TlsValidationContext)
-> Lens
     TlsValidationContext
     TlsValidationContext
     (Maybe SubjectAlternativeNames)
     (Maybe SubjectAlternativeNames)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TlsValidationContext' {Maybe SubjectAlternativeNames
subjectAlternativeNames :: Maybe SubjectAlternativeNames
$sel:subjectAlternativeNames:TlsValidationContext' :: TlsValidationContext -> Maybe SubjectAlternativeNames
subjectAlternativeNames} -> Maybe SubjectAlternativeNames
subjectAlternativeNames) (\s :: TlsValidationContext
s@TlsValidationContext' {} Maybe SubjectAlternativeNames
a -> TlsValidationContext
s {$sel:subjectAlternativeNames:TlsValidationContext' :: Maybe SubjectAlternativeNames
subjectAlternativeNames = Maybe SubjectAlternativeNames
a} :: TlsValidationContext)

-- | A reference to where to retrieve the trust chain when validating a
-- peer’s Transport Layer Security (TLS) certificate.
tlsValidationContext_trust :: Lens.Lens' TlsValidationContext TlsValidationContextTrust
tlsValidationContext_trust :: (TlsValidationContextTrust -> f TlsValidationContextTrust)
-> TlsValidationContext -> f TlsValidationContext
tlsValidationContext_trust = (TlsValidationContext -> TlsValidationContextTrust)
-> (TlsValidationContext
    -> TlsValidationContextTrust -> TlsValidationContext)
-> Lens
     TlsValidationContext
     TlsValidationContext
     TlsValidationContextTrust
     TlsValidationContextTrust
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TlsValidationContext' {TlsValidationContextTrust
trust :: TlsValidationContextTrust
$sel:trust:TlsValidationContext' :: TlsValidationContext -> TlsValidationContextTrust
trust} -> TlsValidationContextTrust
trust) (\s :: TlsValidationContext
s@TlsValidationContext' {} TlsValidationContextTrust
a -> TlsValidationContext
s {$sel:trust:TlsValidationContext' :: TlsValidationContextTrust
trust = TlsValidationContextTrust
a} :: TlsValidationContext)

instance Core.FromJSON TlsValidationContext where
  parseJSON :: Value -> Parser TlsValidationContext
parseJSON =
    String
-> (Object -> Parser TlsValidationContext)
-> Value
-> Parser TlsValidationContext
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TlsValidationContext"
      ( \Object
x ->
          Maybe SubjectAlternativeNames
-> TlsValidationContextTrust -> TlsValidationContext
TlsValidationContext'
            (Maybe SubjectAlternativeNames
 -> TlsValidationContextTrust -> TlsValidationContext)
-> Parser (Maybe SubjectAlternativeNames)
-> Parser (TlsValidationContextTrust -> TlsValidationContext)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe SubjectAlternativeNames)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"subjectAlternativeNames")
            Parser (TlsValidationContextTrust -> TlsValidationContext)
-> Parser TlsValidationContextTrust -> Parser TlsValidationContext
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser TlsValidationContextTrust
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"trust")
      )

instance Prelude.Hashable TlsValidationContext

instance Prelude.NFData TlsValidationContext

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