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

import qualified Amazonka.Core as Core
import Amazonka.GlobalAccelerator.Types.ClientAffinity
import Amazonka.GlobalAccelerator.Types.PortRange
import Amazonka.GlobalAccelerator.Types.Protocol
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A complex type for a listener.
--
-- /See:/ 'newListener' smart constructor.
data Listener = Listener'
  { -- | The list of port ranges for the connections from clients to the
    -- accelerator.
    Listener -> Maybe (NonEmpty PortRange)
portRanges :: Prelude.Maybe (Prelude.NonEmpty PortRange),
    -- | The Amazon Resource Name (ARN) of the listener.
    Listener -> Maybe Text
listenerArn :: Prelude.Maybe Prelude.Text,
    -- | The protocol for the connections from clients to the accelerator.
    Listener -> Maybe Protocol
protocol :: Prelude.Maybe Protocol,
    -- | Client affinity lets you direct all requests from a user to the same
    -- endpoint, if you have stateful applications, regardless of the port and
    -- protocol of the client request. Client affinity gives you control over
    -- whether to always route each client to the same specific endpoint.
    --
    -- AWS Global Accelerator uses a consistent-flow hashing algorithm to
    -- choose the optimal endpoint for a connection. If client affinity is
    -- @NONE@, Global Accelerator uses the \"five-tuple\" (5-tuple)
    -- properties—source IP address, source port, destination IP address,
    -- destination port, and protocol—to select the hash value, and then
    -- chooses the best endpoint. However, with this setting, if someone uses
    -- different ports to connect to Global Accelerator, their connections
    -- might not be always routed to the same endpoint because the hash value
    -- changes.
    --
    -- If you want a given client to always be routed to the same endpoint, set
    -- client affinity to @SOURCE_IP@ instead. When you use the @SOURCE_IP@
    -- setting, Global Accelerator uses the \"two-tuple\" (2-tuple) properties—
    -- source (client) IP address and destination IP address—to select the hash
    -- value.
    --
    -- The default value is @NONE@.
    Listener -> Maybe ClientAffinity
clientAffinity :: Prelude.Maybe ClientAffinity
  }
  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:
--
-- 'portRanges', 'listener_portRanges' - The list of port ranges for the connections from clients to the
-- accelerator.
--
-- 'listenerArn', 'listener_listenerArn' - The Amazon Resource Name (ARN) of the listener.
--
-- 'protocol', 'listener_protocol' - The protocol for the connections from clients to the accelerator.
--
-- 'clientAffinity', 'listener_clientAffinity' - Client affinity lets you direct all requests from a user to the same
-- endpoint, if you have stateful applications, regardless of the port and
-- protocol of the client request. Client affinity gives you control over
-- whether to always route each client to the same specific endpoint.
--
-- AWS Global Accelerator uses a consistent-flow hashing algorithm to
-- choose the optimal endpoint for a connection. If client affinity is
-- @NONE@, Global Accelerator uses the \"five-tuple\" (5-tuple)
-- properties—source IP address, source port, destination IP address,
-- destination port, and protocol—to select the hash value, and then
-- chooses the best endpoint. However, with this setting, if someone uses
-- different ports to connect to Global Accelerator, their connections
-- might not be always routed to the same endpoint because the hash value
-- changes.
--
-- If you want a given client to always be routed to the same endpoint, set
-- client affinity to @SOURCE_IP@ instead. When you use the @SOURCE_IP@
-- setting, Global Accelerator uses the \"two-tuple\" (2-tuple) properties—
-- source (client) IP address and destination IP address—to select the hash
-- value.
--
-- The default value is @NONE@.
newListener ::
  Listener
newListener :: Listener
newListener =
  Listener' :: Maybe (NonEmpty PortRange)
-> Maybe Text -> Maybe Protocol -> Maybe ClientAffinity -> Listener
Listener'
    { $sel:portRanges:Listener' :: Maybe (NonEmpty PortRange)
portRanges = Maybe (NonEmpty PortRange)
forall a. Maybe a
Prelude.Nothing,
      $sel:listenerArn:Listener' :: Maybe Text
listenerArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:protocol:Listener' :: Maybe Protocol
protocol = Maybe Protocol
forall a. Maybe a
Prelude.Nothing,
      $sel:clientAffinity:Listener' :: Maybe ClientAffinity
clientAffinity = Maybe ClientAffinity
forall a. Maybe a
Prelude.Nothing
    }

-- | The list of port ranges for the connections from clients to the
-- accelerator.
listener_portRanges :: Lens.Lens' Listener (Prelude.Maybe (Prelude.NonEmpty PortRange))
listener_portRanges :: (Maybe (NonEmpty PortRange) -> f (Maybe (NonEmpty PortRange)))
-> Listener -> f Listener
listener_portRanges = (Listener -> Maybe (NonEmpty PortRange))
-> (Listener -> Maybe (NonEmpty PortRange) -> Listener)
-> Lens
     Listener
     Listener
     (Maybe (NonEmpty PortRange))
     (Maybe (NonEmpty PortRange))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {Maybe (NonEmpty PortRange)
portRanges :: Maybe (NonEmpty PortRange)
$sel:portRanges:Listener' :: Listener -> Maybe (NonEmpty PortRange)
portRanges} -> Maybe (NonEmpty PortRange)
portRanges) (\s :: Listener
s@Listener' {} Maybe (NonEmpty PortRange)
a -> Listener
s {$sel:portRanges:Listener' :: Maybe (NonEmpty PortRange)
portRanges = Maybe (NonEmpty PortRange)
a} :: Listener) ((Maybe (NonEmpty PortRange) -> f (Maybe (NonEmpty PortRange)))
 -> Listener -> f Listener)
-> ((Maybe (NonEmpty PortRange) -> f (Maybe (NonEmpty PortRange)))
    -> Maybe (NonEmpty PortRange) -> f (Maybe (NonEmpty PortRange)))
-> (Maybe (NonEmpty PortRange) -> f (Maybe (NonEmpty PortRange)))
-> Listener
-> f Listener
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty PortRange)
  (NonEmpty PortRange)
  (NonEmpty PortRange)
  (NonEmpty PortRange)
-> Iso
     (Maybe (NonEmpty PortRange))
     (Maybe (NonEmpty PortRange))
     (Maybe (NonEmpty PortRange))
     (Maybe (NonEmpty PortRange))
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
  (NonEmpty PortRange)
  (NonEmpty PortRange)
  (NonEmpty PortRange)
  (NonEmpty PortRange)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The Amazon Resource Name (ARN) of the listener.
listener_listenerArn :: Lens.Lens' Listener (Prelude.Maybe Prelude.Text)
listener_listenerArn :: (Maybe Text -> f (Maybe Text)) -> Listener -> f Listener
listener_listenerArn = (Listener -> Maybe Text)
-> (Listener -> Maybe Text -> Listener)
-> Lens Listener Listener (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {Maybe Text
listenerArn :: Maybe Text
$sel:listenerArn:Listener' :: Listener -> Maybe Text
listenerArn} -> Maybe Text
listenerArn) (\s :: Listener
s@Listener' {} Maybe Text
a -> Listener
s {$sel:listenerArn:Listener' :: Maybe Text
listenerArn = Maybe Text
a} :: Listener)

-- | The protocol for the connections from clients to the accelerator.
listener_protocol :: Lens.Lens' Listener (Prelude.Maybe Protocol)
listener_protocol :: (Maybe Protocol -> f (Maybe Protocol)) -> Listener -> f Listener
listener_protocol = (Listener -> Maybe Protocol)
-> (Listener -> Maybe Protocol -> Listener)
-> Lens Listener Listener (Maybe Protocol) (Maybe Protocol)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {Maybe Protocol
protocol :: Maybe Protocol
$sel:protocol:Listener' :: Listener -> Maybe Protocol
protocol} -> Maybe Protocol
protocol) (\s :: Listener
s@Listener' {} Maybe Protocol
a -> Listener
s {$sel:protocol:Listener' :: Maybe Protocol
protocol = Maybe Protocol
a} :: Listener)

-- | Client affinity lets you direct all requests from a user to the same
-- endpoint, if you have stateful applications, regardless of the port and
-- protocol of the client request. Client affinity gives you control over
-- whether to always route each client to the same specific endpoint.
--
-- AWS Global Accelerator uses a consistent-flow hashing algorithm to
-- choose the optimal endpoint for a connection. If client affinity is
-- @NONE@, Global Accelerator uses the \"five-tuple\" (5-tuple)
-- properties—source IP address, source port, destination IP address,
-- destination port, and protocol—to select the hash value, and then
-- chooses the best endpoint. However, with this setting, if someone uses
-- different ports to connect to Global Accelerator, their connections
-- might not be always routed to the same endpoint because the hash value
-- changes.
--
-- If you want a given client to always be routed to the same endpoint, set
-- client affinity to @SOURCE_IP@ instead. When you use the @SOURCE_IP@
-- setting, Global Accelerator uses the \"two-tuple\" (2-tuple) properties—
-- source (client) IP address and destination IP address—to select the hash
-- value.
--
-- The default value is @NONE@.
listener_clientAffinity :: Lens.Lens' Listener (Prelude.Maybe ClientAffinity)
listener_clientAffinity :: (Maybe ClientAffinity -> f (Maybe ClientAffinity))
-> Listener -> f Listener
listener_clientAffinity = (Listener -> Maybe ClientAffinity)
-> (Listener -> Maybe ClientAffinity -> Listener)
-> Lens
     Listener Listener (Maybe ClientAffinity) (Maybe ClientAffinity)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {Maybe ClientAffinity
clientAffinity :: Maybe ClientAffinity
$sel:clientAffinity:Listener' :: Listener -> Maybe ClientAffinity
clientAffinity} -> Maybe ClientAffinity
clientAffinity) (\s :: Listener
s@Listener' {} Maybe ClientAffinity
a -> Listener
s {$sel:clientAffinity:Listener' :: Maybe ClientAffinity
clientAffinity = Maybe ClientAffinity
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 (NonEmpty PortRange)
-> Maybe Text -> Maybe Protocol -> Maybe ClientAffinity -> Listener
Listener'
            (Maybe (NonEmpty PortRange)
 -> Maybe Text
 -> Maybe Protocol
 -> Maybe ClientAffinity
 -> Listener)
-> Parser (Maybe (NonEmpty PortRange))
-> Parser
     (Maybe Text -> Maybe Protocol -> Maybe ClientAffinity -> Listener)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty PortRange))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PortRanges")
            Parser
  (Maybe Text -> Maybe Protocol -> Maybe ClientAffinity -> Listener)
-> Parser (Maybe Text)
-> Parser (Maybe Protocol -> Maybe ClientAffinity -> Listener)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ListenerArn")
            Parser (Maybe Protocol -> Maybe ClientAffinity -> Listener)
-> Parser (Maybe Protocol)
-> Parser (Maybe ClientAffinity -> Listener)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Protocol)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Protocol")
            Parser (Maybe ClientAffinity -> Listener)
-> Parser (Maybe ClientAffinity) -> Parser Listener
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ClientAffinity)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ClientAffinity")
      )

instance Prelude.Hashable Listener

instance Prelude.NFData Listener