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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ELB.Internal
import qualified Amazonka.Prelude as Prelude

-- | Information about a listener.
--
-- For information about the protocols and the ports supported by Elastic
-- Load Balancing, see
-- <https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-listener-config.html Listeners for Your Classic Load Balancer>
-- in the /Classic Load Balancers Guide/.
--
-- /See:/ 'newListener' smart constructor.
data Listener = Listener'
  { -- | The protocol to use for routing traffic to instances: HTTP, HTTPS, TCP,
    -- or SSL.
    --
    -- If the front-end protocol is TCP or SSL, the back-end protocol must be
    -- TCP or SSL. If the front-end protocol is HTTP or HTTPS, the back-end
    -- protocol must be HTTP or HTTPS.
    --
    -- If there is another listener with the same @InstancePort@ whose
    -- @InstanceProtocol@ is secure, (HTTPS or SSL), the listener\'s
    -- @InstanceProtocol@ must also be secure.
    --
    -- If there is another listener with the same @InstancePort@ whose
    -- @InstanceProtocol@ is HTTP or TCP, the listener\'s @InstanceProtocol@
    -- must be HTTP or TCP.
    Listener -> Maybe Text
instanceProtocol :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the server certificate.
    Listener -> Maybe Text
sSLCertificateId :: Prelude.Maybe Prelude.Text,
    -- | The load balancer transport protocol to use for routing: HTTP, HTTPS,
    -- TCP, or SSL.
    Listener -> Text
protocol :: Prelude.Text,
    -- | The port on which the load balancer is listening. On EC2-VPC, you can
    -- specify any port from the range 1-65535. On EC2-Classic, you can specify
    -- any port from the following list: 25, 80, 443, 465, 587, 1024-65535.
    Listener -> Int
loadBalancerPort :: Prelude.Int,
    -- | The port on which the instance is listening.
    Listener -> Natural
instancePort :: Prelude.Natural
  }
  deriving (Listener -> Listener -> Bool
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]
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
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. 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:
--
-- 'instanceProtocol', 'listener_instanceProtocol' - The protocol to use for routing traffic to instances: HTTP, HTTPS, TCP,
-- or SSL.
--
-- If the front-end protocol is TCP or SSL, the back-end protocol must be
-- TCP or SSL. If the front-end protocol is HTTP or HTTPS, the back-end
-- protocol must be HTTP or HTTPS.
--
-- If there is another listener with the same @InstancePort@ whose
-- @InstanceProtocol@ is secure, (HTTPS or SSL), the listener\'s
-- @InstanceProtocol@ must also be secure.
--
-- If there is another listener with the same @InstancePort@ whose
-- @InstanceProtocol@ is HTTP or TCP, the listener\'s @InstanceProtocol@
-- must be HTTP or TCP.
--
-- 'sSLCertificateId', 'listener_sSLCertificateId' - The Amazon Resource Name (ARN) of the server certificate.
--
-- 'protocol', 'listener_protocol' - The load balancer transport protocol to use for routing: HTTP, HTTPS,
-- TCP, or SSL.
--
-- 'loadBalancerPort', 'listener_loadBalancerPort' - The port on which the load balancer is listening. On EC2-VPC, you can
-- specify any port from the range 1-65535. On EC2-Classic, you can specify
-- any port from the following list: 25, 80, 443, 465, 587, 1024-65535.
--
-- 'instancePort', 'listener_instancePort' - The port on which the instance is listening.
newListener ::
  -- | 'protocol'
  Prelude.Text ->
  -- | 'loadBalancerPort'
  Prelude.Int ->
  -- | 'instancePort'
  Prelude.Natural ->
  Listener
newListener :: Text -> Int -> Natural -> Listener
newListener
  Text
pProtocol_
  Int
pLoadBalancerPort_
  Natural
pInstancePort_ =
    Listener'
      { $sel:instanceProtocol:Listener' :: Maybe Text
instanceProtocol = forall a. Maybe a
Prelude.Nothing,
        $sel:sSLCertificateId:Listener' :: Maybe Text
sSLCertificateId = forall a. Maybe a
Prelude.Nothing,
        $sel:protocol:Listener' :: Text
protocol = Text
pProtocol_,
        $sel:loadBalancerPort:Listener' :: Int
loadBalancerPort = Int
pLoadBalancerPort_,
        $sel:instancePort:Listener' :: Natural
instancePort = Natural
pInstancePort_
      }

-- | The protocol to use for routing traffic to instances: HTTP, HTTPS, TCP,
-- or SSL.
--
-- If the front-end protocol is TCP or SSL, the back-end protocol must be
-- TCP or SSL. If the front-end protocol is HTTP or HTTPS, the back-end
-- protocol must be HTTP or HTTPS.
--
-- If there is another listener with the same @InstancePort@ whose
-- @InstanceProtocol@ is secure, (HTTPS or SSL), the listener\'s
-- @InstanceProtocol@ must also be secure.
--
-- If there is another listener with the same @InstancePort@ whose
-- @InstanceProtocol@ is HTTP or TCP, the listener\'s @InstanceProtocol@
-- must be HTTP or TCP.
listener_instanceProtocol :: Lens.Lens' Listener (Prelude.Maybe Prelude.Text)
listener_instanceProtocol :: Lens' Listener (Maybe Text)
listener_instanceProtocol = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {Maybe Text
instanceProtocol :: Maybe Text
$sel:instanceProtocol:Listener' :: Listener -> Maybe Text
instanceProtocol} -> Maybe Text
instanceProtocol) (\s :: Listener
s@Listener' {} Maybe Text
a -> Listener
s {$sel:instanceProtocol:Listener' :: Maybe Text
instanceProtocol = Maybe Text
a} :: Listener)

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

-- | The load balancer transport protocol to use for routing: HTTP, HTTPS,
-- TCP, or SSL.
listener_protocol :: Lens.Lens' Listener Prelude.Text
listener_protocol :: Lens' Listener Text
listener_protocol = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {Text
protocol :: Text
$sel:protocol:Listener' :: Listener -> Text
protocol} -> Text
protocol) (\s :: Listener
s@Listener' {} Text
a -> Listener
s {$sel:protocol:Listener' :: Text
protocol = Text
a} :: Listener)

-- | The port on which the load balancer is listening. On EC2-VPC, you can
-- specify any port from the range 1-65535. On EC2-Classic, you can specify
-- any port from the following list: 25, 80, 443, 465, 587, 1024-65535.
listener_loadBalancerPort :: Lens.Lens' Listener Prelude.Int
listener_loadBalancerPort :: Lens' Listener Int
listener_loadBalancerPort = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {Int
loadBalancerPort :: Int
$sel:loadBalancerPort:Listener' :: Listener -> Int
loadBalancerPort} -> Int
loadBalancerPort) (\s :: Listener
s@Listener' {} Int
a -> Listener
s {$sel:loadBalancerPort:Listener' :: Int
loadBalancerPort = Int
a} :: Listener)

-- | The port on which the instance is listening.
listener_instancePort :: Lens.Lens' Listener Prelude.Natural
listener_instancePort :: Lens' Listener Natural
listener_instancePort = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Listener' {Natural
instancePort :: Natural
$sel:instancePort:Listener' :: Listener -> Natural
instancePort} -> Natural
instancePort) (\s :: Listener
s@Listener' {} Natural
a -> Listener
s {$sel:instancePort:Listener' :: Natural
instancePort = Natural
a} :: Listener)

instance Data.FromXML Listener where
  parseXML :: [Node] -> Either String Listener
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> Text -> Int -> Natural -> Listener
Listener'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"InstanceProtocol")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"SSLCertificateId")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Protocol")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"LoadBalancerPort")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"InstancePort")

instance Prelude.Hashable Listener where
  hashWithSalt :: Int -> Listener -> Int
hashWithSalt Int
_salt Listener' {Int
Natural
Maybe Text
Text
instancePort :: Natural
loadBalancerPort :: Int
protocol :: Text
sSLCertificateId :: Maybe Text
instanceProtocol :: Maybe Text
$sel:instancePort:Listener' :: Listener -> Natural
$sel:loadBalancerPort:Listener' :: Listener -> Int
$sel:protocol:Listener' :: Listener -> Text
$sel:sSLCertificateId:Listener' :: Listener -> Maybe Text
$sel:instanceProtocol:Listener' :: Listener -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
instanceProtocol
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sSLCertificateId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
protocol
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
loadBalancerPort
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
instancePort

instance Prelude.NFData Listener where
  rnf :: Listener -> ()
rnf Listener' {Int
Natural
Maybe Text
Text
instancePort :: Natural
loadBalancerPort :: Int
protocol :: Text
sSLCertificateId :: Maybe Text
instanceProtocol :: Maybe Text
$sel:instancePort:Listener' :: Listener -> Natural
$sel:loadBalancerPort:Listener' :: Listener -> Int
$sel:protocol:Listener' :: Listener -> Text
$sel:sSLCertificateId:Listener' :: Listener -> Maybe Text
$sel:instanceProtocol:Listener' :: Listener -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
instanceProtocol
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
sSLCertificateId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
protocol
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
loadBalancerPort
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
instancePort

instance Data.ToQuery Listener where
  toQuery :: Listener -> QueryString
toQuery Listener' {Int
Natural
Maybe Text
Text
instancePort :: Natural
loadBalancerPort :: Int
protocol :: Text
sSLCertificateId :: Maybe Text
instanceProtocol :: Maybe Text
$sel:instancePort:Listener' :: Listener -> Natural
$sel:loadBalancerPort:Listener' :: Listener -> Int
$sel:protocol:Listener' :: Listener -> Text
$sel:sSLCertificateId:Listener' :: Listener -> Maybe Text
$sel:instanceProtocol:Listener' :: Listener -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"InstanceProtocol" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
instanceProtocol,
        ByteString
"SSLCertificateId" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
sSLCertificateId,
        ByteString
"Protocol" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
protocol,
        ByteString
"LoadBalancerPort" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Int
loadBalancerPort,
        ByteString
"InstancePort" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Natural
instancePort
      ]