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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.GlobalAccelerator.Types.CustomRoutingDestinationTrafficState
import Amazonka.GlobalAccelerator.Types.CustomRoutingProtocol
import Amazonka.GlobalAccelerator.Types.SocketAddress
import qualified Amazonka.Prelude as Prelude

-- | Returns the ports and associated IP addresses and ports of Amazon EC2
-- instances in your virtual private cloud (VPC) subnets. Custom routing is
-- a port mapping protocol in Global Accelerator that statically associates
-- port ranges with VPC subnets, which allows Global Accelerator to route
-- to specific instances and ports within one or more subnets.
--
-- /See:/ 'newPortMapping' smart constructor.
data PortMapping = PortMapping'
  { -- | The accelerator port.
    PortMapping -> Maybe Natural
acceleratorPort :: Prelude.Maybe Prelude.Natural,
    -- | The EC2 instance IP address and port number in the virtual private cloud
    -- (VPC) subnet.
    PortMapping -> Maybe SocketAddress
destinationSocketAddress :: Prelude.Maybe SocketAddress,
    -- | Indicates whether or not a port mapping destination can receive traffic.
    -- The value is either ALLOW, if traffic is allowed to the destination, or
    -- DENY, if traffic is not allowed to the destination.
    PortMapping -> Maybe CustomRoutingDestinationTrafficState
destinationTrafficState :: Prelude.Maybe CustomRoutingDestinationTrafficState,
    -- | The Amazon Resource Name (ARN) of the endpoint group.
    PortMapping -> Maybe Text
endpointGroupArn :: Prelude.Maybe Prelude.Text,
    -- | The IP address of the VPC subnet (the subnet ID).
    PortMapping -> Maybe Text
endpointId :: Prelude.Maybe Prelude.Text,
    -- | The protocols supported by the endpoint group.
    PortMapping -> Maybe (NonEmpty CustomRoutingProtocol)
protocols :: Prelude.Maybe (Prelude.NonEmpty CustomRoutingProtocol)
  }
  deriving (PortMapping -> PortMapping -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortMapping -> PortMapping -> Bool
$c/= :: PortMapping -> PortMapping -> Bool
== :: PortMapping -> PortMapping -> Bool
$c== :: PortMapping -> PortMapping -> Bool
Prelude.Eq, ReadPrec [PortMapping]
ReadPrec PortMapping
Int -> ReadS PortMapping
ReadS [PortMapping]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PortMapping]
$creadListPrec :: ReadPrec [PortMapping]
readPrec :: ReadPrec PortMapping
$creadPrec :: ReadPrec PortMapping
readList :: ReadS [PortMapping]
$creadList :: ReadS [PortMapping]
readsPrec :: Int -> ReadS PortMapping
$creadsPrec :: Int -> ReadS PortMapping
Prelude.Read, Int -> PortMapping -> ShowS
[PortMapping] -> ShowS
PortMapping -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PortMapping] -> ShowS
$cshowList :: [PortMapping] -> ShowS
show :: PortMapping -> String
$cshow :: PortMapping -> String
showsPrec :: Int -> PortMapping -> ShowS
$cshowsPrec :: Int -> PortMapping -> ShowS
Prelude.Show, forall x. Rep PortMapping x -> PortMapping
forall x. PortMapping -> Rep PortMapping x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PortMapping x -> PortMapping
$cfrom :: forall x. PortMapping -> Rep PortMapping x
Prelude.Generic)

-- |
-- Create a value of 'PortMapping' 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:
--
-- 'acceleratorPort', 'portMapping_acceleratorPort' - The accelerator port.
--
-- 'destinationSocketAddress', 'portMapping_destinationSocketAddress' - The EC2 instance IP address and port number in the virtual private cloud
-- (VPC) subnet.
--
-- 'destinationTrafficState', 'portMapping_destinationTrafficState' - Indicates whether or not a port mapping destination can receive traffic.
-- The value is either ALLOW, if traffic is allowed to the destination, or
-- DENY, if traffic is not allowed to the destination.
--
-- 'endpointGroupArn', 'portMapping_endpointGroupArn' - The Amazon Resource Name (ARN) of the endpoint group.
--
-- 'endpointId', 'portMapping_endpointId' - The IP address of the VPC subnet (the subnet ID).
--
-- 'protocols', 'portMapping_protocols' - The protocols supported by the endpoint group.
newPortMapping ::
  PortMapping
newPortMapping :: PortMapping
newPortMapping =
  PortMapping'
    { $sel:acceleratorPort:PortMapping' :: Maybe Natural
acceleratorPort = forall a. Maybe a
Prelude.Nothing,
      $sel:destinationSocketAddress:PortMapping' :: Maybe SocketAddress
destinationSocketAddress = forall a. Maybe a
Prelude.Nothing,
      $sel:destinationTrafficState:PortMapping' :: Maybe CustomRoutingDestinationTrafficState
destinationTrafficState = forall a. Maybe a
Prelude.Nothing,
      $sel:endpointGroupArn:PortMapping' :: Maybe Text
endpointGroupArn = forall a. Maybe a
Prelude.Nothing,
      $sel:endpointId:PortMapping' :: Maybe Text
endpointId = forall a. Maybe a
Prelude.Nothing,
      $sel:protocols:PortMapping' :: Maybe (NonEmpty CustomRoutingProtocol)
protocols = forall a. Maybe a
Prelude.Nothing
    }

-- | The accelerator port.
portMapping_acceleratorPort :: Lens.Lens' PortMapping (Prelude.Maybe Prelude.Natural)
portMapping_acceleratorPort :: Lens' PortMapping (Maybe Natural)
portMapping_acceleratorPort = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Maybe Natural
acceleratorPort :: Maybe Natural
$sel:acceleratorPort:PortMapping' :: PortMapping -> Maybe Natural
acceleratorPort} -> Maybe Natural
acceleratorPort) (\s :: PortMapping
s@PortMapping' {} Maybe Natural
a -> PortMapping
s {$sel:acceleratorPort:PortMapping' :: Maybe Natural
acceleratorPort = Maybe Natural
a} :: PortMapping)

-- | The EC2 instance IP address and port number in the virtual private cloud
-- (VPC) subnet.
portMapping_destinationSocketAddress :: Lens.Lens' PortMapping (Prelude.Maybe SocketAddress)
portMapping_destinationSocketAddress :: Lens' PortMapping (Maybe SocketAddress)
portMapping_destinationSocketAddress = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Maybe SocketAddress
destinationSocketAddress :: Maybe SocketAddress
$sel:destinationSocketAddress:PortMapping' :: PortMapping -> Maybe SocketAddress
destinationSocketAddress} -> Maybe SocketAddress
destinationSocketAddress) (\s :: PortMapping
s@PortMapping' {} Maybe SocketAddress
a -> PortMapping
s {$sel:destinationSocketAddress:PortMapping' :: Maybe SocketAddress
destinationSocketAddress = Maybe SocketAddress
a} :: PortMapping)

-- | Indicates whether or not a port mapping destination can receive traffic.
-- The value is either ALLOW, if traffic is allowed to the destination, or
-- DENY, if traffic is not allowed to the destination.
portMapping_destinationTrafficState :: Lens.Lens' PortMapping (Prelude.Maybe CustomRoutingDestinationTrafficState)
portMapping_destinationTrafficState :: Lens' PortMapping (Maybe CustomRoutingDestinationTrafficState)
portMapping_destinationTrafficState = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Maybe CustomRoutingDestinationTrafficState
destinationTrafficState :: Maybe CustomRoutingDestinationTrafficState
$sel:destinationTrafficState:PortMapping' :: PortMapping -> Maybe CustomRoutingDestinationTrafficState
destinationTrafficState} -> Maybe CustomRoutingDestinationTrafficState
destinationTrafficState) (\s :: PortMapping
s@PortMapping' {} Maybe CustomRoutingDestinationTrafficState
a -> PortMapping
s {$sel:destinationTrafficState:PortMapping' :: Maybe CustomRoutingDestinationTrafficState
destinationTrafficState = Maybe CustomRoutingDestinationTrafficState
a} :: PortMapping)

-- | The Amazon Resource Name (ARN) of the endpoint group.
portMapping_endpointGroupArn :: Lens.Lens' PortMapping (Prelude.Maybe Prelude.Text)
portMapping_endpointGroupArn :: Lens' PortMapping (Maybe Text)
portMapping_endpointGroupArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Maybe Text
endpointGroupArn :: Maybe Text
$sel:endpointGroupArn:PortMapping' :: PortMapping -> Maybe Text
endpointGroupArn} -> Maybe Text
endpointGroupArn) (\s :: PortMapping
s@PortMapping' {} Maybe Text
a -> PortMapping
s {$sel:endpointGroupArn:PortMapping' :: Maybe Text
endpointGroupArn = Maybe Text
a} :: PortMapping)

-- | The IP address of the VPC subnet (the subnet ID).
portMapping_endpointId :: Lens.Lens' PortMapping (Prelude.Maybe Prelude.Text)
portMapping_endpointId :: Lens' PortMapping (Maybe Text)
portMapping_endpointId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Maybe Text
endpointId :: Maybe Text
$sel:endpointId:PortMapping' :: PortMapping -> Maybe Text
endpointId} -> Maybe Text
endpointId) (\s :: PortMapping
s@PortMapping' {} Maybe Text
a -> PortMapping
s {$sel:endpointId:PortMapping' :: Maybe Text
endpointId = Maybe Text
a} :: PortMapping)

-- | The protocols supported by the endpoint group.
portMapping_protocols :: Lens.Lens' PortMapping (Prelude.Maybe (Prelude.NonEmpty CustomRoutingProtocol))
portMapping_protocols :: Lens' PortMapping (Maybe (NonEmpty CustomRoutingProtocol))
portMapping_protocols = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Maybe (NonEmpty CustomRoutingProtocol)
protocols :: Maybe (NonEmpty CustomRoutingProtocol)
$sel:protocols:PortMapping' :: PortMapping -> Maybe (NonEmpty CustomRoutingProtocol)
protocols} -> Maybe (NonEmpty CustomRoutingProtocol)
protocols) (\s :: PortMapping
s@PortMapping' {} Maybe (NonEmpty CustomRoutingProtocol)
a -> PortMapping
s {$sel:protocols:PortMapping' :: Maybe (NonEmpty CustomRoutingProtocol)
protocols = Maybe (NonEmpty CustomRoutingProtocol)
a} :: PortMapping) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON PortMapping where
  parseJSON :: Value -> Parser PortMapping
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PortMapping"
      ( \Object
x ->
          Maybe Natural
-> Maybe SocketAddress
-> Maybe CustomRoutingDestinationTrafficState
-> Maybe Text
-> Maybe Text
-> Maybe (NonEmpty CustomRoutingProtocol)
-> PortMapping
PortMapping'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"AcceleratorPort")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"DestinationSocketAddress")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"DestinationTrafficState")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"EndpointGroupArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"EndpointId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Protocols")
      )

instance Prelude.Hashable PortMapping where
  hashWithSalt :: Int -> PortMapping -> Int
hashWithSalt Int
_salt PortMapping' {Maybe Natural
Maybe (NonEmpty CustomRoutingProtocol)
Maybe Text
Maybe CustomRoutingDestinationTrafficState
Maybe SocketAddress
protocols :: Maybe (NonEmpty CustomRoutingProtocol)
endpointId :: Maybe Text
endpointGroupArn :: Maybe Text
destinationTrafficState :: Maybe CustomRoutingDestinationTrafficState
destinationSocketAddress :: Maybe SocketAddress
acceleratorPort :: Maybe Natural
$sel:protocols:PortMapping' :: PortMapping -> Maybe (NonEmpty CustomRoutingProtocol)
$sel:endpointId:PortMapping' :: PortMapping -> Maybe Text
$sel:endpointGroupArn:PortMapping' :: PortMapping -> Maybe Text
$sel:destinationTrafficState:PortMapping' :: PortMapping -> Maybe CustomRoutingDestinationTrafficState
$sel:destinationSocketAddress:PortMapping' :: PortMapping -> Maybe SocketAddress
$sel:acceleratorPort:PortMapping' :: PortMapping -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
acceleratorPort
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SocketAddress
destinationSocketAddress
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CustomRoutingDestinationTrafficState
destinationTrafficState
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
endpointGroupArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
endpointId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty CustomRoutingProtocol)
protocols

instance Prelude.NFData PortMapping where
  rnf :: PortMapping -> ()
rnf PortMapping' {Maybe Natural
Maybe (NonEmpty CustomRoutingProtocol)
Maybe Text
Maybe CustomRoutingDestinationTrafficState
Maybe SocketAddress
protocols :: Maybe (NonEmpty CustomRoutingProtocol)
endpointId :: Maybe Text
endpointGroupArn :: Maybe Text
destinationTrafficState :: Maybe CustomRoutingDestinationTrafficState
destinationSocketAddress :: Maybe SocketAddress
acceleratorPort :: Maybe Natural
$sel:protocols:PortMapping' :: PortMapping -> Maybe (NonEmpty CustomRoutingProtocol)
$sel:endpointId:PortMapping' :: PortMapping -> Maybe Text
$sel:endpointGroupArn:PortMapping' :: PortMapping -> Maybe Text
$sel:destinationTrafficState:PortMapping' :: PortMapping -> Maybe CustomRoutingDestinationTrafficState
$sel:destinationSocketAddress:PortMapping' :: PortMapping -> Maybe SocketAddress
$sel:acceleratorPort:PortMapping' :: PortMapping -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
acceleratorPort
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe SocketAddress
destinationSocketAddress
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe CustomRoutingDestinationTrafficState
destinationTrafficState
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
endpointGroupArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
endpointId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty CustomRoutingProtocol)
protocols