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

import Amazonka.AppMesh.Types.HealthCheckPolicy
import Amazonka.AppMesh.Types.ListenerTimeout
import Amazonka.AppMesh.Types.ListenerTls
import Amazonka.AppMesh.Types.OutlierDetection
import Amazonka.AppMesh.Types.PortMapping
import Amazonka.AppMesh.Types.VirtualNodeConnectionPool
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that represents a listener for a virtual node.
--
-- /See:/ 'newListener' smart constructor.
data Listener = Listener'
  { -- | The health check information for the listener.
    Listener -> Maybe HealthCheckPolicy
healthCheck :: Prelude.Maybe HealthCheckPolicy,
    -- | The connection pool information for the listener.
    Listener -> Maybe VirtualNodeConnectionPool
connectionPool :: Prelude.Maybe VirtualNodeConnectionPool,
    -- | A reference to an object that represents the Transport Layer Security
    -- (TLS) properties for a listener.
    Listener -> Maybe ListenerTls
tls :: Prelude.Maybe ListenerTls,
    -- | The outlier detection information for the listener.
    Listener -> Maybe OutlierDetection
outlierDetection :: Prelude.Maybe OutlierDetection,
    -- | An object that represents timeouts for different protocols.
    Listener -> Maybe ListenerTimeout
timeout :: Prelude.Maybe ListenerTimeout,
    -- | The port mapping information for the listener.
    Listener -> PortMapping
portMapping :: PortMapping
  }
  deriving (Listener -> Listener -> Bool
(Listener -> Listener -> Bool)
-> (Listener -> Listener -> Bool) -> Eq Listener
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Listener -> Listener -> Bool
$c/= :: Listener -> Listener -> Bool
== :: Listener -> Listener -> Bool
$c== :: Listener -> Listener -> Bool
Prelude.Eq, ReadPrec [Listener]
ReadPrec Listener
Int -> ReadS Listener
ReadS [Listener]
(Int -> ReadS Listener)
-> ReadS [Listener]
-> ReadPrec Listener
-> ReadPrec [Listener]
-> Read Listener
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Listener]
$creadListPrec :: ReadPrec [Listener]
readPrec :: ReadPrec Listener
$creadPrec :: ReadPrec Listener
readList :: ReadS [Listener]
$creadList :: ReadS [Listener]
readsPrec :: Int -> ReadS Listener
$creadsPrec :: Int -> ReadS Listener
Prelude.Read, Int -> Listener -> ShowS
[Listener] -> ShowS
Listener -> String
(Int -> Listener -> ShowS)
-> (Listener -> String) -> ([Listener] -> ShowS) -> Show Listener
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Listener] -> ShowS
$cshowList :: [Listener] -> ShowS
show :: Listener -> String
$cshow :: Listener -> String
showsPrec :: Int -> Listener -> ShowS
$cshowsPrec :: Int -> Listener -> ShowS
Prelude.Show, (forall x. Listener -> Rep Listener x)
-> (forall x. Rep Listener x -> Listener) -> Generic Listener
forall x. Rep Listener x -> Listener
forall x. Listener -> Rep Listener x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Listener x -> Listener
$cfrom :: forall x. Listener -> Rep Listener x
Prelude.Generic)

-- |
-- Create a value of 'Listener' 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:
--
-- 'healthCheck', 'listener_healthCheck' - The health check information for the listener.
--
-- 'connectionPool', 'listener_connectionPool' - The connection pool information for the listener.
--
-- 'tls', 'listener_tls' - A reference to an object that represents the Transport Layer Security
-- (TLS) properties for a listener.
--
-- 'outlierDetection', 'listener_outlierDetection' - The outlier detection information for the listener.
--
-- 'timeout', 'listener_timeout' - An object that represents timeouts for different protocols.
--
-- 'portMapping', 'listener_portMapping' - The port mapping information for the listener.
newListener ::
  -- | 'portMapping'
  PortMapping ->
  Listener
newListener :: PortMapping -> Listener
newListener PortMapping
pPortMapping_ =
  Listener' :: Maybe HealthCheckPolicy
-> Maybe VirtualNodeConnectionPool
-> Maybe ListenerTls
-> Maybe OutlierDetection
-> Maybe ListenerTimeout
-> PortMapping
-> Listener
Listener'
    { $sel:healthCheck:Listener' :: Maybe HealthCheckPolicy
healthCheck = Maybe HealthCheckPolicy
forall a. Maybe a
Prelude.Nothing,
      $sel:connectionPool:Listener' :: Maybe VirtualNodeConnectionPool
connectionPool = Maybe VirtualNodeConnectionPool
forall a. Maybe a
Prelude.Nothing,
      $sel:tls:Listener' :: Maybe ListenerTls
tls = Maybe ListenerTls
forall a. Maybe a
Prelude.Nothing,
      $sel:outlierDetection:Listener' :: Maybe OutlierDetection
outlierDetection = Maybe OutlierDetection
forall a. Maybe a
Prelude.Nothing,
      $sel:timeout:Listener' :: Maybe ListenerTimeout
timeout = Maybe ListenerTimeout
forall a. Maybe a
Prelude.Nothing,
      $sel:portMapping:Listener' :: PortMapping
portMapping = PortMapping
pPortMapping_
    }

-- | The health check information for the listener.
listener_healthCheck :: Lens.Lens' Listener (Prelude.Maybe HealthCheckPolicy)
listener_healthCheck :: (Maybe HealthCheckPolicy -> f (Maybe HealthCheckPolicy))
-> Listener -> f Listener
listener_healthCheck = (Listener -> Maybe HealthCheckPolicy)
-> (Listener -> Maybe HealthCheckPolicy -> Listener)
-> Lens
     Listener
     Listener
     (Maybe HealthCheckPolicy)
     (Maybe HealthCheckPolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {Maybe HealthCheckPolicy
healthCheck :: Maybe HealthCheckPolicy
$sel:healthCheck:Listener' :: Listener -> Maybe HealthCheckPolicy
healthCheck} -> Maybe HealthCheckPolicy
healthCheck) (\s :: Listener
s@Listener' {} Maybe HealthCheckPolicy
a -> Listener
s {$sel:healthCheck:Listener' :: Maybe HealthCheckPolicy
healthCheck = Maybe HealthCheckPolicy
a} :: Listener)

-- | The connection pool information for the listener.
listener_connectionPool :: Lens.Lens' Listener (Prelude.Maybe VirtualNodeConnectionPool)
listener_connectionPool :: (Maybe VirtualNodeConnectionPool
 -> f (Maybe VirtualNodeConnectionPool))
-> Listener -> f Listener
listener_connectionPool = (Listener -> Maybe VirtualNodeConnectionPool)
-> (Listener -> Maybe VirtualNodeConnectionPool -> Listener)
-> Lens
     Listener
     Listener
     (Maybe VirtualNodeConnectionPool)
     (Maybe VirtualNodeConnectionPool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {Maybe VirtualNodeConnectionPool
connectionPool :: Maybe VirtualNodeConnectionPool
$sel:connectionPool:Listener' :: Listener -> Maybe VirtualNodeConnectionPool
connectionPool} -> Maybe VirtualNodeConnectionPool
connectionPool) (\s :: Listener
s@Listener' {} Maybe VirtualNodeConnectionPool
a -> Listener
s {$sel:connectionPool:Listener' :: Maybe VirtualNodeConnectionPool
connectionPool = Maybe VirtualNodeConnectionPool
a} :: Listener)

-- | A reference to an object that represents the Transport Layer Security
-- (TLS) properties for a listener.
listener_tls :: Lens.Lens' Listener (Prelude.Maybe ListenerTls)
listener_tls :: (Maybe ListenerTls -> f (Maybe ListenerTls))
-> Listener -> f Listener
listener_tls = (Listener -> Maybe ListenerTls)
-> (Listener -> Maybe ListenerTls -> Listener)
-> Lens Listener Listener (Maybe ListenerTls) (Maybe ListenerTls)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {Maybe ListenerTls
tls :: Maybe ListenerTls
$sel:tls:Listener' :: Listener -> Maybe ListenerTls
tls} -> Maybe ListenerTls
tls) (\s :: Listener
s@Listener' {} Maybe ListenerTls
a -> Listener
s {$sel:tls:Listener' :: Maybe ListenerTls
tls = Maybe ListenerTls
a} :: Listener)

-- | The outlier detection information for the listener.
listener_outlierDetection :: Lens.Lens' Listener (Prelude.Maybe OutlierDetection)
listener_outlierDetection :: (Maybe OutlierDetection -> f (Maybe OutlierDetection))
-> Listener -> f Listener
listener_outlierDetection = (Listener -> Maybe OutlierDetection)
-> (Listener -> Maybe OutlierDetection -> Listener)
-> Lens
     Listener Listener (Maybe OutlierDetection) (Maybe OutlierDetection)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {Maybe OutlierDetection
outlierDetection :: Maybe OutlierDetection
$sel:outlierDetection:Listener' :: Listener -> Maybe OutlierDetection
outlierDetection} -> Maybe OutlierDetection
outlierDetection) (\s :: Listener
s@Listener' {} Maybe OutlierDetection
a -> Listener
s {$sel:outlierDetection:Listener' :: Maybe OutlierDetection
outlierDetection = Maybe OutlierDetection
a} :: Listener)

-- | An object that represents timeouts for different protocols.
listener_timeout :: Lens.Lens' Listener (Prelude.Maybe ListenerTimeout)
listener_timeout :: (Maybe ListenerTimeout -> f (Maybe ListenerTimeout))
-> Listener -> f Listener
listener_timeout = (Listener -> Maybe ListenerTimeout)
-> (Listener -> Maybe ListenerTimeout -> Listener)
-> Lens
     Listener Listener (Maybe ListenerTimeout) (Maybe ListenerTimeout)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {Maybe ListenerTimeout
timeout :: Maybe ListenerTimeout
$sel:timeout:Listener' :: Listener -> Maybe ListenerTimeout
timeout} -> Maybe ListenerTimeout
timeout) (\s :: Listener
s@Listener' {} Maybe ListenerTimeout
a -> Listener
s {$sel:timeout:Listener' :: Maybe ListenerTimeout
timeout = Maybe ListenerTimeout
a} :: Listener)

-- | The port mapping information for the listener.
listener_portMapping :: Lens.Lens' Listener PortMapping
listener_portMapping :: (PortMapping -> f PortMapping) -> Listener -> f Listener
listener_portMapping = (Listener -> PortMapping)
-> (Listener -> PortMapping -> Listener)
-> Lens Listener Listener PortMapping PortMapping
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {PortMapping
portMapping :: PortMapping
$sel:portMapping:Listener' :: Listener -> PortMapping
portMapping} -> PortMapping
portMapping) (\s :: Listener
s@Listener' {} PortMapping
a -> Listener
s {$sel:portMapping:Listener' :: PortMapping
portMapping = PortMapping
a} :: Listener)

instance Core.FromJSON Listener where
  parseJSON :: Value -> Parser Listener
parseJSON =
    String -> (Object -> Parser Listener) -> Value -> Parser Listener
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Listener"
      ( \Object
x ->
          Maybe HealthCheckPolicy
-> Maybe VirtualNodeConnectionPool
-> Maybe ListenerTls
-> Maybe OutlierDetection
-> Maybe ListenerTimeout
-> PortMapping
-> Listener
Listener'
            (Maybe HealthCheckPolicy
 -> Maybe VirtualNodeConnectionPool
 -> Maybe ListenerTls
 -> Maybe OutlierDetection
 -> Maybe ListenerTimeout
 -> PortMapping
 -> Listener)
-> Parser (Maybe HealthCheckPolicy)
-> Parser
     (Maybe VirtualNodeConnectionPool
      -> Maybe ListenerTls
      -> Maybe OutlierDetection
      -> Maybe ListenerTimeout
      -> PortMapping
      -> Listener)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe HealthCheckPolicy)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"healthCheck")
            Parser
  (Maybe VirtualNodeConnectionPool
   -> Maybe ListenerTls
   -> Maybe OutlierDetection
   -> Maybe ListenerTimeout
   -> PortMapping
   -> Listener)
-> Parser (Maybe VirtualNodeConnectionPool)
-> Parser
     (Maybe ListenerTls
      -> Maybe OutlierDetection
      -> Maybe ListenerTimeout
      -> PortMapping
      -> Listener)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe VirtualNodeConnectionPool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"connectionPool")
            Parser
  (Maybe ListenerTls
   -> Maybe OutlierDetection
   -> Maybe ListenerTimeout
   -> PortMapping
   -> Listener)
-> Parser (Maybe ListenerTls)
-> Parser
     (Maybe OutlierDetection
      -> Maybe ListenerTimeout -> PortMapping -> Listener)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ListenerTls)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"tls")
            Parser
  (Maybe OutlierDetection
   -> Maybe ListenerTimeout -> PortMapping -> Listener)
-> Parser (Maybe OutlierDetection)
-> Parser (Maybe ListenerTimeout -> PortMapping -> Listener)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe OutlierDetection)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"outlierDetection")
            Parser (Maybe ListenerTimeout -> PortMapping -> Listener)
-> Parser (Maybe ListenerTimeout)
-> Parser (PortMapping -> Listener)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ListenerTimeout)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"timeout")
            Parser (PortMapping -> Listener)
-> Parser PortMapping -> Parser Listener
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser PortMapping
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"portMapping")
      )

instance Prelude.Hashable Listener

instance Prelude.NFData Listener

instance Core.ToJSON Listener where
  toJSON :: Listener -> Value
toJSON Listener' {Maybe OutlierDetection
Maybe HealthCheckPolicy
Maybe ListenerTimeout
Maybe ListenerTls
Maybe VirtualNodeConnectionPool
PortMapping
portMapping :: PortMapping
timeout :: Maybe ListenerTimeout
outlierDetection :: Maybe OutlierDetection
tls :: Maybe ListenerTls
connectionPool :: Maybe VirtualNodeConnectionPool
healthCheck :: Maybe HealthCheckPolicy
$sel:portMapping:Listener' :: Listener -> PortMapping
$sel:timeout:Listener' :: Listener -> Maybe ListenerTimeout
$sel:outlierDetection:Listener' :: Listener -> Maybe OutlierDetection
$sel:tls:Listener' :: Listener -> Maybe ListenerTls
$sel:connectionPool:Listener' :: Listener -> Maybe VirtualNodeConnectionPool
$sel:healthCheck:Listener' :: Listener -> Maybe HealthCheckPolicy
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"healthCheck" Text -> HealthCheckPolicy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HealthCheckPolicy -> Pair)
-> Maybe HealthCheckPolicy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe HealthCheckPolicy
healthCheck,
            (Text
"connectionPool" Text -> VirtualNodeConnectionPool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (VirtualNodeConnectionPool -> Pair)
-> Maybe VirtualNodeConnectionPool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe VirtualNodeConnectionPool
connectionPool,
            (Text
"tls" Text -> ListenerTls -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ListenerTls -> Pair) -> Maybe ListenerTls -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ListenerTls
tls,
            (Text
"outlierDetection" Text -> OutlierDetection -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (OutlierDetection -> Pair) -> Maybe OutlierDetection -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe OutlierDetection
outlierDetection,
            (Text
"timeout" Text -> ListenerTimeout -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ListenerTimeout -> Pair) -> Maybe ListenerTimeout -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ListenerTimeout
timeout,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"portMapping" Text -> PortMapping -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PortMapping
portMapping)
          ]
      )