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

import qualified Amazonka.Core as Core
import Amazonka.GlobalAccelerator.Types.CustomRoutingDestinationTrafficState
import Amazonka.GlobalAccelerator.Types.CustomRoutingProtocol
import Amazonka.GlobalAccelerator.Types.SocketAddress
import qualified Amazonka.Lens as Lens
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 AWS 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 EC2 instance IP address and port number in the virtual private cloud
    -- (VPC) subnet.
    PortMapping -> Maybe SocketAddress
destinationSocketAddress :: Prelude.Maybe SocketAddress,
    -- | The protocols supported by the endpoint group.
    PortMapping -> Maybe (NonEmpty CustomRoutingProtocol)
protocols :: Prelude.Maybe (Prelude.NonEmpty CustomRoutingProtocol),
    -- | 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,
    -- | 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 accelerator port.
    PortMapping -> Maybe Natural
acceleratorPort :: Prelude.Maybe Prelude.Natural
  }
  deriving (PortMapping -> PortMapping -> Bool
(PortMapping -> PortMapping -> Bool)
-> (PortMapping -> PortMapping -> Bool) -> Eq PortMapping
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]
(Int -> ReadS PortMapping)
-> ReadS [PortMapping]
-> ReadPrec PortMapping
-> ReadPrec [PortMapping]
-> Read 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
(Int -> PortMapping -> ShowS)
-> (PortMapping -> String)
-> ([PortMapping] -> ShowS)
-> Show PortMapping
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. PortMapping -> Rep PortMapping x)
-> (forall x. Rep PortMapping x -> PortMapping)
-> Generic PortMapping
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:
--
-- 'destinationSocketAddress', 'portMapping_destinationSocketAddress' - The EC2 instance IP address and port number in the virtual private cloud
-- (VPC) subnet.
--
-- 'protocols', 'portMapping_protocols' - The protocols supported by the endpoint group.
--
-- '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).
--
-- '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.
--
-- 'acceleratorPort', 'portMapping_acceleratorPort' - The accelerator port.
newPortMapping ::
  PortMapping
newPortMapping :: PortMapping
newPortMapping =
  PortMapping' :: Maybe SocketAddress
-> Maybe (NonEmpty CustomRoutingProtocol)
-> Maybe Text
-> Maybe Text
-> Maybe CustomRoutingDestinationTrafficState
-> Maybe Natural
-> PortMapping
PortMapping'
    { $sel:destinationSocketAddress:PortMapping' :: Maybe SocketAddress
destinationSocketAddress =
        Maybe SocketAddress
forall a. Maybe a
Prelude.Nothing,
      $sel:protocols:PortMapping' :: Maybe (NonEmpty CustomRoutingProtocol)
protocols = Maybe (NonEmpty CustomRoutingProtocol)
forall a. Maybe a
Prelude.Nothing,
      $sel:endpointGroupArn:PortMapping' :: Maybe Text
endpointGroupArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:endpointId:PortMapping' :: Maybe Text
endpointId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:destinationTrafficState:PortMapping' :: Maybe CustomRoutingDestinationTrafficState
destinationTrafficState = Maybe CustomRoutingDestinationTrafficState
forall a. Maybe a
Prelude.Nothing,
      $sel:acceleratorPort:PortMapping' :: Maybe Natural
acceleratorPort = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe SocketAddress -> f (Maybe SocketAddress))
-> PortMapping -> f PortMapping
portMapping_destinationSocketAddress = (PortMapping -> Maybe SocketAddress)
-> (PortMapping -> Maybe SocketAddress -> PortMapping)
-> Lens
     PortMapping PortMapping (Maybe SocketAddress) (Maybe SocketAddress)
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)

-- | The protocols supported by the endpoint group.
portMapping_protocols :: Lens.Lens' PortMapping (Prelude.Maybe (Prelude.NonEmpty CustomRoutingProtocol))
portMapping_protocols :: (Maybe (NonEmpty CustomRoutingProtocol)
 -> f (Maybe (NonEmpty CustomRoutingProtocol)))
-> PortMapping -> f PortMapping
portMapping_protocols = (PortMapping -> Maybe (NonEmpty CustomRoutingProtocol))
-> (PortMapping
    -> Maybe (NonEmpty CustomRoutingProtocol) -> PortMapping)
-> Lens
     PortMapping
     PortMapping
     (Maybe (NonEmpty CustomRoutingProtocol))
     (Maybe (NonEmpty CustomRoutingProtocol))
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) ((Maybe (NonEmpty CustomRoutingProtocol)
  -> f (Maybe (NonEmpty CustomRoutingProtocol)))
 -> PortMapping -> f PortMapping)
-> ((Maybe (NonEmpty CustomRoutingProtocol)
     -> f (Maybe (NonEmpty CustomRoutingProtocol)))
    -> Maybe (NonEmpty CustomRoutingProtocol)
    -> f (Maybe (NonEmpty CustomRoutingProtocol)))
-> (Maybe (NonEmpty CustomRoutingProtocol)
    -> f (Maybe (NonEmpty CustomRoutingProtocol)))
-> PortMapping
-> f PortMapping
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty CustomRoutingProtocol)
  (NonEmpty CustomRoutingProtocol)
  (NonEmpty CustomRoutingProtocol)
  (NonEmpty CustomRoutingProtocol)
-> Iso
     (Maybe (NonEmpty CustomRoutingProtocol))
     (Maybe (NonEmpty CustomRoutingProtocol))
     (Maybe (NonEmpty CustomRoutingProtocol))
     (Maybe (NonEmpty CustomRoutingProtocol))
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 CustomRoutingProtocol)
  (NonEmpty CustomRoutingProtocol)
  (NonEmpty CustomRoutingProtocol)
  (NonEmpty CustomRoutingProtocol)
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 endpoint group.
portMapping_endpointGroupArn :: Lens.Lens' PortMapping (Prelude.Maybe Prelude.Text)
portMapping_endpointGroupArn :: (Maybe Text -> f (Maybe Text)) -> PortMapping -> f PortMapping
portMapping_endpointGroupArn = (PortMapping -> Maybe Text)
-> (PortMapping -> Maybe Text -> PortMapping)
-> Lens PortMapping PortMapping (Maybe Text) (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text)) -> PortMapping -> f PortMapping
portMapping_endpointId = (PortMapping -> Maybe Text)
-> (PortMapping -> Maybe Text -> PortMapping)
-> Lens PortMapping PortMapping (Maybe Text) (Maybe Text)
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)

-- | 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 :: (Maybe CustomRoutingDestinationTrafficState
 -> f (Maybe CustomRoutingDestinationTrafficState))
-> PortMapping -> f PortMapping
portMapping_destinationTrafficState = (PortMapping -> Maybe CustomRoutingDestinationTrafficState)
-> (PortMapping
    -> Maybe CustomRoutingDestinationTrafficState -> PortMapping)
-> Lens
     PortMapping
     PortMapping
     (Maybe CustomRoutingDestinationTrafficState)
     (Maybe CustomRoutingDestinationTrafficState)
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 accelerator port.
portMapping_acceleratorPort :: Lens.Lens' PortMapping (Prelude.Maybe Prelude.Natural)
portMapping_acceleratorPort :: (Maybe Natural -> f (Maybe Natural))
-> PortMapping -> f PortMapping
portMapping_acceleratorPort = (PortMapping -> Maybe Natural)
-> (PortMapping -> Maybe Natural -> PortMapping)
-> Lens PortMapping PortMapping (Maybe Natural) (Maybe Natural)
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)

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

instance Prelude.Hashable PortMapping

instance Prelude.NFData PortMapping