{-# 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.ECS.Types.NetworkBinding
-- 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.ECS.Types.NetworkBinding where

import qualified Amazonka.Core as Core
import Amazonka.ECS.Types.TransportProtocol
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Details on the network bindings between a container and its host
-- container instance. After a task reaches the @RUNNING@ status, manual
-- and automatic host and container port assignments are visible in the
-- @networkBindings@ section of DescribeTasks API responses.
--
-- /See:/ 'newNetworkBinding' smart constructor.
data NetworkBinding = NetworkBinding'
  { -- | The IP address that the container is bound to on the container instance.
    NetworkBinding -> Maybe Text
bindIP :: Prelude.Maybe Prelude.Text,
    -- | The protocol used for the network binding.
    NetworkBinding -> Maybe TransportProtocol
protocol :: Prelude.Maybe TransportProtocol,
    -- | The port number on the host that is used with the network binding.
    NetworkBinding -> Maybe Int
hostPort :: Prelude.Maybe Prelude.Int,
    -- | The port number on the container that is used with the network binding.
    NetworkBinding -> Maybe Int
containerPort :: Prelude.Maybe Prelude.Int
  }
  deriving (NetworkBinding -> NetworkBinding -> Bool
(NetworkBinding -> NetworkBinding -> Bool)
-> (NetworkBinding -> NetworkBinding -> Bool) -> Eq NetworkBinding
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NetworkBinding -> NetworkBinding -> Bool
$c/= :: NetworkBinding -> NetworkBinding -> Bool
== :: NetworkBinding -> NetworkBinding -> Bool
$c== :: NetworkBinding -> NetworkBinding -> Bool
Prelude.Eq, ReadPrec [NetworkBinding]
ReadPrec NetworkBinding
Int -> ReadS NetworkBinding
ReadS [NetworkBinding]
(Int -> ReadS NetworkBinding)
-> ReadS [NetworkBinding]
-> ReadPrec NetworkBinding
-> ReadPrec [NetworkBinding]
-> Read NetworkBinding
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NetworkBinding]
$creadListPrec :: ReadPrec [NetworkBinding]
readPrec :: ReadPrec NetworkBinding
$creadPrec :: ReadPrec NetworkBinding
readList :: ReadS [NetworkBinding]
$creadList :: ReadS [NetworkBinding]
readsPrec :: Int -> ReadS NetworkBinding
$creadsPrec :: Int -> ReadS NetworkBinding
Prelude.Read, Int -> NetworkBinding -> ShowS
[NetworkBinding] -> ShowS
NetworkBinding -> String
(Int -> NetworkBinding -> ShowS)
-> (NetworkBinding -> String)
-> ([NetworkBinding] -> ShowS)
-> Show NetworkBinding
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NetworkBinding] -> ShowS
$cshowList :: [NetworkBinding] -> ShowS
show :: NetworkBinding -> String
$cshow :: NetworkBinding -> String
showsPrec :: Int -> NetworkBinding -> ShowS
$cshowsPrec :: Int -> NetworkBinding -> ShowS
Prelude.Show, (forall x. NetworkBinding -> Rep NetworkBinding x)
-> (forall x. Rep NetworkBinding x -> NetworkBinding)
-> Generic NetworkBinding
forall x. Rep NetworkBinding x -> NetworkBinding
forall x. NetworkBinding -> Rep NetworkBinding x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NetworkBinding x -> NetworkBinding
$cfrom :: forall x. NetworkBinding -> Rep NetworkBinding x
Prelude.Generic)

-- |
-- Create a value of 'NetworkBinding' 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:
--
-- 'bindIP', 'networkBinding_bindIP' - The IP address that the container is bound to on the container instance.
--
-- 'protocol', 'networkBinding_protocol' - The protocol used for the network binding.
--
-- 'hostPort', 'networkBinding_hostPort' - The port number on the host that is used with the network binding.
--
-- 'containerPort', 'networkBinding_containerPort' - The port number on the container that is used with the network binding.
newNetworkBinding ::
  NetworkBinding
newNetworkBinding :: NetworkBinding
newNetworkBinding =
  NetworkBinding' :: Maybe Text
-> Maybe TransportProtocol
-> Maybe Int
-> Maybe Int
-> NetworkBinding
NetworkBinding'
    { $sel:bindIP:NetworkBinding' :: Maybe Text
bindIP = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:protocol:NetworkBinding' :: Maybe TransportProtocol
protocol = Maybe TransportProtocol
forall a. Maybe a
Prelude.Nothing,
      $sel:hostPort:NetworkBinding' :: Maybe Int
hostPort = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:containerPort:NetworkBinding' :: Maybe Int
containerPort = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | The IP address that the container is bound to on the container instance.
networkBinding_bindIP :: Lens.Lens' NetworkBinding (Prelude.Maybe Prelude.Text)
networkBinding_bindIP :: (Maybe Text -> f (Maybe Text))
-> NetworkBinding -> f NetworkBinding
networkBinding_bindIP = (NetworkBinding -> Maybe Text)
-> (NetworkBinding -> Maybe Text -> NetworkBinding)
-> Lens NetworkBinding NetworkBinding (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NetworkBinding' {Maybe Text
bindIP :: Maybe Text
$sel:bindIP:NetworkBinding' :: NetworkBinding -> Maybe Text
bindIP} -> Maybe Text
bindIP) (\s :: NetworkBinding
s@NetworkBinding' {} Maybe Text
a -> NetworkBinding
s {$sel:bindIP:NetworkBinding' :: Maybe Text
bindIP = Maybe Text
a} :: NetworkBinding)

-- | The protocol used for the network binding.
networkBinding_protocol :: Lens.Lens' NetworkBinding (Prelude.Maybe TransportProtocol)
networkBinding_protocol :: (Maybe TransportProtocol -> f (Maybe TransportProtocol))
-> NetworkBinding -> f NetworkBinding
networkBinding_protocol = (NetworkBinding -> Maybe TransportProtocol)
-> (NetworkBinding -> Maybe TransportProtocol -> NetworkBinding)
-> Lens
     NetworkBinding
     NetworkBinding
     (Maybe TransportProtocol)
     (Maybe TransportProtocol)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NetworkBinding' {Maybe TransportProtocol
protocol :: Maybe TransportProtocol
$sel:protocol:NetworkBinding' :: NetworkBinding -> Maybe TransportProtocol
protocol} -> Maybe TransportProtocol
protocol) (\s :: NetworkBinding
s@NetworkBinding' {} Maybe TransportProtocol
a -> NetworkBinding
s {$sel:protocol:NetworkBinding' :: Maybe TransportProtocol
protocol = Maybe TransportProtocol
a} :: NetworkBinding)

-- | The port number on the host that is used with the network binding.
networkBinding_hostPort :: Lens.Lens' NetworkBinding (Prelude.Maybe Prelude.Int)
networkBinding_hostPort :: (Maybe Int -> f (Maybe Int)) -> NetworkBinding -> f NetworkBinding
networkBinding_hostPort = (NetworkBinding -> Maybe Int)
-> (NetworkBinding -> Maybe Int -> NetworkBinding)
-> Lens NetworkBinding NetworkBinding (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NetworkBinding' {Maybe Int
hostPort :: Maybe Int
$sel:hostPort:NetworkBinding' :: NetworkBinding -> Maybe Int
hostPort} -> Maybe Int
hostPort) (\s :: NetworkBinding
s@NetworkBinding' {} Maybe Int
a -> NetworkBinding
s {$sel:hostPort:NetworkBinding' :: Maybe Int
hostPort = Maybe Int
a} :: NetworkBinding)

-- | The port number on the container that is used with the network binding.
networkBinding_containerPort :: Lens.Lens' NetworkBinding (Prelude.Maybe Prelude.Int)
networkBinding_containerPort :: (Maybe Int -> f (Maybe Int)) -> NetworkBinding -> f NetworkBinding
networkBinding_containerPort = (NetworkBinding -> Maybe Int)
-> (NetworkBinding -> Maybe Int -> NetworkBinding)
-> Lens NetworkBinding NetworkBinding (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NetworkBinding' {Maybe Int
containerPort :: Maybe Int
$sel:containerPort:NetworkBinding' :: NetworkBinding -> Maybe Int
containerPort} -> Maybe Int
containerPort) (\s :: NetworkBinding
s@NetworkBinding' {} Maybe Int
a -> NetworkBinding
s {$sel:containerPort:NetworkBinding' :: Maybe Int
containerPort = Maybe Int
a} :: NetworkBinding)

instance Core.FromJSON NetworkBinding where
  parseJSON :: Value -> Parser NetworkBinding
parseJSON =
    String
-> (Object -> Parser NetworkBinding)
-> Value
-> Parser NetworkBinding
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"NetworkBinding"
      ( \Object
x ->
          Maybe Text
-> Maybe TransportProtocol
-> Maybe Int
-> Maybe Int
-> NetworkBinding
NetworkBinding'
            (Maybe Text
 -> Maybe TransportProtocol
 -> Maybe Int
 -> Maybe Int
 -> NetworkBinding)
-> Parser (Maybe Text)
-> Parser
     (Maybe TransportProtocol
      -> Maybe Int -> Maybe Int -> NetworkBinding)
forall (f :: * -> *) a b. Functor 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
"bindIP")
            Parser
  (Maybe TransportProtocol
   -> Maybe Int -> Maybe Int -> NetworkBinding)
-> Parser (Maybe TransportProtocol)
-> Parser (Maybe Int -> Maybe Int -> NetworkBinding)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe TransportProtocol)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"protocol")
            Parser (Maybe Int -> Maybe Int -> NetworkBinding)
-> Parser (Maybe Int) -> Parser (Maybe Int -> NetworkBinding)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"hostPort")
            Parser (Maybe Int -> NetworkBinding)
-> Parser (Maybe Int) -> Parser NetworkBinding
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"containerPort")
      )

instance Prelude.Hashable NetworkBinding

instance Prelude.NFData NetworkBinding

instance Core.ToJSON NetworkBinding where
  toJSON :: NetworkBinding -> Value
toJSON NetworkBinding' {Maybe Int
Maybe Text
Maybe TransportProtocol
containerPort :: Maybe Int
hostPort :: Maybe Int
protocol :: Maybe TransportProtocol
bindIP :: Maybe Text
$sel:containerPort:NetworkBinding' :: NetworkBinding -> Maybe Int
$sel:hostPort:NetworkBinding' :: NetworkBinding -> Maybe Int
$sel:protocol:NetworkBinding' :: NetworkBinding -> Maybe TransportProtocol
$sel:bindIP:NetworkBinding' :: NetworkBinding -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"bindIP" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
bindIP,
            (Text
"protocol" Text -> TransportProtocol -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (TransportProtocol -> Pair)
-> Maybe TransportProtocol -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TransportProtocol
protocol,
            (Text
"hostPort" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
hostPort,
            (Text
"containerPort" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
containerPort
          ]
      )