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

import qualified Amazonka.Core as Core
import Amazonka.ECS.Types.KeyValuePair
import Amazonka.ECS.Types.ProxyConfigurationType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The configuration details for the App Mesh proxy.
--
-- For tasks using the EC2 launch type, the container instances require at
-- least version 1.26.0 of the container agent and at least version
-- 1.26.0-1 of the @ecs-init@ package to enable a proxy configuration. If
-- your container instances are launched from the Amazon ECS-optimized AMI
-- version @20190301@ or later, then they contain the required versions of
-- the container agent and @ecs-init@. For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html Amazon ECS-optimized Linux AMI>
--
-- /See:/ 'newProxyConfiguration' smart constructor.
data ProxyConfiguration = ProxyConfiguration'
  { -- | The proxy type. The only supported value is @APPMESH@.
    ProxyConfiguration -> Maybe ProxyConfigurationType
type' :: Prelude.Maybe ProxyConfigurationType,
    -- | The set of network configuration parameters to provide the Container
    -- Network Interface (CNI) plugin, specified as key-value pairs.
    --
    -- -   @IgnoredUID@ - (Required) The user ID (UID) of the proxy container
    --     as defined by the @user@ parameter in a container definition. This
    --     is used to ensure the proxy ignores its own traffic. If @IgnoredGID@
    --     is specified, this field can be empty.
    --
    -- -   @IgnoredGID@ - (Required) The group ID (GID) of the proxy container
    --     as defined by the @user@ parameter in a container definition. This
    --     is used to ensure the proxy ignores its own traffic. If @IgnoredUID@
    --     is specified, this field can be empty.
    --
    -- -   @AppPorts@ - (Required) The list of ports that the application uses.
    --     Network traffic to these ports is forwarded to the
    --     @ProxyIngressPort@ and @ProxyEgressPort@.
    --
    -- -   @ProxyIngressPort@ - (Required) Specifies the port that incoming
    --     traffic to the @AppPorts@ is directed to.
    --
    -- -   @ProxyEgressPort@ - (Required) Specifies the port that outgoing
    --     traffic from the @AppPorts@ is directed to.
    --
    -- -   @EgressIgnoredPorts@ - (Required) The egress traffic going to the
    --     specified ports is ignored and not redirected to the
    --     @ProxyEgressPort@. It can be an empty list.
    --
    -- -   @EgressIgnoredIPs@ - (Required) The egress traffic going to the
    --     specified IP addresses is ignored and not redirected to the
    --     @ProxyEgressPort@. It can be an empty list.
    ProxyConfiguration -> Maybe [KeyValuePair]
properties :: Prelude.Maybe [KeyValuePair],
    -- | The name of the container that will serve as the App Mesh proxy.
    ProxyConfiguration -> Text
containerName :: Prelude.Text
  }
  deriving (ProxyConfiguration -> ProxyConfiguration -> Bool
(ProxyConfiguration -> ProxyConfiguration -> Bool)
-> (ProxyConfiguration -> ProxyConfiguration -> Bool)
-> Eq ProxyConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProxyConfiguration -> ProxyConfiguration -> Bool
$c/= :: ProxyConfiguration -> ProxyConfiguration -> Bool
== :: ProxyConfiguration -> ProxyConfiguration -> Bool
$c== :: ProxyConfiguration -> ProxyConfiguration -> Bool
Prelude.Eq, ReadPrec [ProxyConfiguration]
ReadPrec ProxyConfiguration
Int -> ReadS ProxyConfiguration
ReadS [ProxyConfiguration]
(Int -> ReadS ProxyConfiguration)
-> ReadS [ProxyConfiguration]
-> ReadPrec ProxyConfiguration
-> ReadPrec [ProxyConfiguration]
-> Read ProxyConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ProxyConfiguration]
$creadListPrec :: ReadPrec [ProxyConfiguration]
readPrec :: ReadPrec ProxyConfiguration
$creadPrec :: ReadPrec ProxyConfiguration
readList :: ReadS [ProxyConfiguration]
$creadList :: ReadS [ProxyConfiguration]
readsPrec :: Int -> ReadS ProxyConfiguration
$creadsPrec :: Int -> ReadS ProxyConfiguration
Prelude.Read, Int -> ProxyConfiguration -> ShowS
[ProxyConfiguration] -> ShowS
ProxyConfiguration -> String
(Int -> ProxyConfiguration -> ShowS)
-> (ProxyConfiguration -> String)
-> ([ProxyConfiguration] -> ShowS)
-> Show ProxyConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProxyConfiguration] -> ShowS
$cshowList :: [ProxyConfiguration] -> ShowS
show :: ProxyConfiguration -> String
$cshow :: ProxyConfiguration -> String
showsPrec :: Int -> ProxyConfiguration -> ShowS
$cshowsPrec :: Int -> ProxyConfiguration -> ShowS
Prelude.Show, (forall x. ProxyConfiguration -> Rep ProxyConfiguration x)
-> (forall x. Rep ProxyConfiguration x -> ProxyConfiguration)
-> Generic ProxyConfiguration
forall x. Rep ProxyConfiguration x -> ProxyConfiguration
forall x. ProxyConfiguration -> Rep ProxyConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProxyConfiguration x -> ProxyConfiguration
$cfrom :: forall x. ProxyConfiguration -> Rep ProxyConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ProxyConfiguration' 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:
--
-- 'type'', 'proxyConfiguration_type' - The proxy type. The only supported value is @APPMESH@.
--
-- 'properties', 'proxyConfiguration_properties' - The set of network configuration parameters to provide the Container
-- Network Interface (CNI) plugin, specified as key-value pairs.
--
-- -   @IgnoredUID@ - (Required) The user ID (UID) of the proxy container
--     as defined by the @user@ parameter in a container definition. This
--     is used to ensure the proxy ignores its own traffic. If @IgnoredGID@
--     is specified, this field can be empty.
--
-- -   @IgnoredGID@ - (Required) The group ID (GID) of the proxy container
--     as defined by the @user@ parameter in a container definition. This
--     is used to ensure the proxy ignores its own traffic. If @IgnoredUID@
--     is specified, this field can be empty.
--
-- -   @AppPorts@ - (Required) The list of ports that the application uses.
--     Network traffic to these ports is forwarded to the
--     @ProxyIngressPort@ and @ProxyEgressPort@.
--
-- -   @ProxyIngressPort@ - (Required) Specifies the port that incoming
--     traffic to the @AppPorts@ is directed to.
--
-- -   @ProxyEgressPort@ - (Required) Specifies the port that outgoing
--     traffic from the @AppPorts@ is directed to.
--
-- -   @EgressIgnoredPorts@ - (Required) The egress traffic going to the
--     specified ports is ignored and not redirected to the
--     @ProxyEgressPort@. It can be an empty list.
--
-- -   @EgressIgnoredIPs@ - (Required) The egress traffic going to the
--     specified IP addresses is ignored and not redirected to the
--     @ProxyEgressPort@. It can be an empty list.
--
-- 'containerName', 'proxyConfiguration_containerName' - The name of the container that will serve as the App Mesh proxy.
newProxyConfiguration ::
  -- | 'containerName'
  Prelude.Text ->
  ProxyConfiguration
newProxyConfiguration :: Text -> ProxyConfiguration
newProxyConfiguration Text
pContainerName_ =
  ProxyConfiguration' :: Maybe ProxyConfigurationType
-> Maybe [KeyValuePair] -> Text -> ProxyConfiguration
ProxyConfiguration'
    { $sel:type':ProxyConfiguration' :: Maybe ProxyConfigurationType
type' = Maybe ProxyConfigurationType
forall a. Maybe a
Prelude.Nothing,
      $sel:properties:ProxyConfiguration' :: Maybe [KeyValuePair]
properties = Maybe [KeyValuePair]
forall a. Maybe a
Prelude.Nothing,
      $sel:containerName:ProxyConfiguration' :: Text
containerName = Text
pContainerName_
    }

-- | The proxy type. The only supported value is @APPMESH@.
proxyConfiguration_type :: Lens.Lens' ProxyConfiguration (Prelude.Maybe ProxyConfigurationType)
proxyConfiguration_type :: (Maybe ProxyConfigurationType -> f (Maybe ProxyConfigurationType))
-> ProxyConfiguration -> f ProxyConfiguration
proxyConfiguration_type = (ProxyConfiguration -> Maybe ProxyConfigurationType)
-> (ProxyConfiguration
    -> Maybe ProxyConfigurationType -> ProxyConfiguration)
-> Lens
     ProxyConfiguration
     ProxyConfiguration
     (Maybe ProxyConfigurationType)
     (Maybe ProxyConfigurationType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProxyConfiguration' {Maybe ProxyConfigurationType
type' :: Maybe ProxyConfigurationType
$sel:type':ProxyConfiguration' :: ProxyConfiguration -> Maybe ProxyConfigurationType
type'} -> Maybe ProxyConfigurationType
type') (\s :: ProxyConfiguration
s@ProxyConfiguration' {} Maybe ProxyConfigurationType
a -> ProxyConfiguration
s {$sel:type':ProxyConfiguration' :: Maybe ProxyConfigurationType
type' = Maybe ProxyConfigurationType
a} :: ProxyConfiguration)

-- | The set of network configuration parameters to provide the Container
-- Network Interface (CNI) plugin, specified as key-value pairs.
--
-- -   @IgnoredUID@ - (Required) The user ID (UID) of the proxy container
--     as defined by the @user@ parameter in a container definition. This
--     is used to ensure the proxy ignores its own traffic. If @IgnoredGID@
--     is specified, this field can be empty.
--
-- -   @IgnoredGID@ - (Required) The group ID (GID) of the proxy container
--     as defined by the @user@ parameter in a container definition. This
--     is used to ensure the proxy ignores its own traffic. If @IgnoredUID@
--     is specified, this field can be empty.
--
-- -   @AppPorts@ - (Required) The list of ports that the application uses.
--     Network traffic to these ports is forwarded to the
--     @ProxyIngressPort@ and @ProxyEgressPort@.
--
-- -   @ProxyIngressPort@ - (Required) Specifies the port that incoming
--     traffic to the @AppPorts@ is directed to.
--
-- -   @ProxyEgressPort@ - (Required) Specifies the port that outgoing
--     traffic from the @AppPorts@ is directed to.
--
-- -   @EgressIgnoredPorts@ - (Required) The egress traffic going to the
--     specified ports is ignored and not redirected to the
--     @ProxyEgressPort@. It can be an empty list.
--
-- -   @EgressIgnoredIPs@ - (Required) The egress traffic going to the
--     specified IP addresses is ignored and not redirected to the
--     @ProxyEgressPort@. It can be an empty list.
proxyConfiguration_properties :: Lens.Lens' ProxyConfiguration (Prelude.Maybe [KeyValuePair])
proxyConfiguration_properties :: (Maybe [KeyValuePair] -> f (Maybe [KeyValuePair]))
-> ProxyConfiguration -> f ProxyConfiguration
proxyConfiguration_properties = (ProxyConfiguration -> Maybe [KeyValuePair])
-> (ProxyConfiguration
    -> Maybe [KeyValuePair] -> ProxyConfiguration)
-> Lens
     ProxyConfiguration
     ProxyConfiguration
     (Maybe [KeyValuePair])
     (Maybe [KeyValuePair])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProxyConfiguration' {Maybe [KeyValuePair]
properties :: Maybe [KeyValuePair]
$sel:properties:ProxyConfiguration' :: ProxyConfiguration -> Maybe [KeyValuePair]
properties} -> Maybe [KeyValuePair]
properties) (\s :: ProxyConfiguration
s@ProxyConfiguration' {} Maybe [KeyValuePair]
a -> ProxyConfiguration
s {$sel:properties:ProxyConfiguration' :: Maybe [KeyValuePair]
properties = Maybe [KeyValuePair]
a} :: ProxyConfiguration) ((Maybe [KeyValuePair] -> f (Maybe [KeyValuePair]))
 -> ProxyConfiguration -> f ProxyConfiguration)
-> ((Maybe [KeyValuePair] -> f (Maybe [KeyValuePair]))
    -> Maybe [KeyValuePair] -> f (Maybe [KeyValuePair]))
-> (Maybe [KeyValuePair] -> f (Maybe [KeyValuePair]))
-> ProxyConfiguration
-> f ProxyConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [KeyValuePair] [KeyValuePair] [KeyValuePair] [KeyValuePair]
-> Iso
     (Maybe [KeyValuePair])
     (Maybe [KeyValuePair])
     (Maybe [KeyValuePair])
     (Maybe [KeyValuePair])
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 [KeyValuePair] [KeyValuePair] [KeyValuePair] [KeyValuePair]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the container that will serve as the App Mesh proxy.
proxyConfiguration_containerName :: Lens.Lens' ProxyConfiguration Prelude.Text
proxyConfiguration_containerName :: (Text -> f Text) -> ProxyConfiguration -> f ProxyConfiguration
proxyConfiguration_containerName = (ProxyConfiguration -> Text)
-> (ProxyConfiguration -> Text -> ProxyConfiguration)
-> Lens ProxyConfiguration ProxyConfiguration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProxyConfiguration' {Text
containerName :: Text
$sel:containerName:ProxyConfiguration' :: ProxyConfiguration -> Text
containerName} -> Text
containerName) (\s :: ProxyConfiguration
s@ProxyConfiguration' {} Text
a -> ProxyConfiguration
s {$sel:containerName:ProxyConfiguration' :: Text
containerName = Text
a} :: ProxyConfiguration)

instance Core.FromJSON ProxyConfiguration where
  parseJSON :: Value -> Parser ProxyConfiguration
parseJSON =
    String
-> (Object -> Parser ProxyConfiguration)
-> Value
-> Parser ProxyConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ProxyConfiguration"
      ( \Object
x ->
          Maybe ProxyConfigurationType
-> Maybe [KeyValuePair] -> Text -> ProxyConfiguration
ProxyConfiguration'
            (Maybe ProxyConfigurationType
 -> Maybe [KeyValuePair] -> Text -> ProxyConfiguration)
-> Parser (Maybe ProxyConfigurationType)
-> Parser (Maybe [KeyValuePair] -> Text -> ProxyConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ProxyConfigurationType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"type")
            Parser (Maybe [KeyValuePair] -> Text -> ProxyConfiguration)
-> Parser (Maybe [KeyValuePair])
-> Parser (Text -> ProxyConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [KeyValuePair]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"properties" Parser (Maybe (Maybe [KeyValuePair]))
-> Maybe [KeyValuePair] -> Parser (Maybe [KeyValuePair])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [KeyValuePair]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> ProxyConfiguration)
-> Parser Text -> Parser ProxyConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"containerName")
      )

instance Prelude.Hashable ProxyConfiguration

instance Prelude.NFData ProxyConfiguration

instance Core.ToJSON ProxyConfiguration where
  toJSON :: ProxyConfiguration -> Value
toJSON ProxyConfiguration' {Maybe [KeyValuePair]
Maybe ProxyConfigurationType
Text
containerName :: Text
properties :: Maybe [KeyValuePair]
type' :: Maybe ProxyConfigurationType
$sel:containerName:ProxyConfiguration' :: ProxyConfiguration -> Text
$sel:properties:ProxyConfiguration' :: ProxyConfiguration -> Maybe [KeyValuePair]
$sel:type':ProxyConfiguration' :: ProxyConfiguration -> Maybe ProxyConfigurationType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"type" Text -> ProxyConfigurationType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ProxyConfigurationType -> Pair)
-> Maybe ProxyConfigurationType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ProxyConfigurationType
type',
            (Text
"properties" Text -> [KeyValuePair] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([KeyValuePair] -> Pair) -> Maybe [KeyValuePair] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [KeyValuePair]
properties,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"containerName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
containerName)
          ]
      )