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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ECS.Types.ServiceConnectClientAlias
import qualified Amazonka.Prelude as Prelude

-- | The Service Connect service object configuration. For more information,
-- see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-connect.html Service Connect>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- /See:/ 'newServiceConnectService' smart constructor.
data ServiceConnectService = ServiceConnectService'
  { -- | The list of client aliases for this Service Connect service. You use
    -- these to assign names that can be used by client applications. The
    -- maximum number of client aliases that you can have in this list is 1.
    --
    -- Each alias (\"endpoint\") is a fully-qualified name and port number that
    -- other Amazon ECS tasks (\"clients\") can use to connect to this service.
    --
    -- Each name and port mapping must be unique within the namespace.
    --
    -- For each @ServiceConnectService@, you must provide at least one
    -- @clientAlias@ with one @port@.
    ServiceConnectService -> Maybe [ServiceConnectClientAlias]
clientAliases :: Prelude.Maybe [ServiceConnectClientAlias],
    -- | The @discoveryName@ is the name of the new Cloud Map service that Amazon
    -- ECS creates for this Amazon ECS service. This must be unique within the
    -- Cloud Map namespace. The name can contain up to 64 characters. The name
    -- can include lowercase letters, numbers, underscores (_), and hyphens
    -- (-). The name can\'t start with a hyphen.
    --
    -- If this parameter isn\'t specified, the default value of
    -- @discoveryName.namespace@ is used. If the @discoveryName@ isn\'t
    -- specified, the port mapping name from the task definition is used in
    -- @portName.namespace@.
    ServiceConnectService -> Maybe Text
discoveryName :: Prelude.Maybe Prelude.Text,
    -- | The port number for the Service Connect proxy to listen on.
    --
    -- Use the value of this field to bypass the proxy for traffic on the port
    -- number specified in the named @portMapping@ in the task definition of
    -- this application, and then use it in your VPC security groups to allow
    -- traffic into the proxy for this Amazon ECS service.
    --
    -- In @awsvpc@ mode and Fargate, the default value is the container port
    -- number. The container port number is in the @portMapping@ in the task
    -- definition. In bridge mode, the default value is the ephemeral port of
    -- the Service Connect proxy.
    ServiceConnectService -> Maybe Natural
ingressPortOverride :: Prelude.Maybe Prelude.Natural,
    -- | The @portName@ must match the name of one of the @portMappings@ from all
    -- the containers in the task definition of this Amazon ECS service.
    ServiceConnectService -> Text
portName :: Prelude.Text
  }
  deriving (ServiceConnectService -> ServiceConnectService -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ServiceConnectService -> ServiceConnectService -> Bool
$c/= :: ServiceConnectService -> ServiceConnectService -> Bool
== :: ServiceConnectService -> ServiceConnectService -> Bool
$c== :: ServiceConnectService -> ServiceConnectService -> Bool
Prelude.Eq, ReadPrec [ServiceConnectService]
ReadPrec ServiceConnectService
Int -> ReadS ServiceConnectService
ReadS [ServiceConnectService]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ServiceConnectService]
$creadListPrec :: ReadPrec [ServiceConnectService]
readPrec :: ReadPrec ServiceConnectService
$creadPrec :: ReadPrec ServiceConnectService
readList :: ReadS [ServiceConnectService]
$creadList :: ReadS [ServiceConnectService]
readsPrec :: Int -> ReadS ServiceConnectService
$creadsPrec :: Int -> ReadS ServiceConnectService
Prelude.Read, Int -> ServiceConnectService -> ShowS
[ServiceConnectService] -> ShowS
ServiceConnectService -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ServiceConnectService] -> ShowS
$cshowList :: [ServiceConnectService] -> ShowS
show :: ServiceConnectService -> String
$cshow :: ServiceConnectService -> String
showsPrec :: Int -> ServiceConnectService -> ShowS
$cshowsPrec :: Int -> ServiceConnectService -> ShowS
Prelude.Show, forall x. Rep ServiceConnectService x -> ServiceConnectService
forall x. ServiceConnectService -> Rep ServiceConnectService x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ServiceConnectService x -> ServiceConnectService
$cfrom :: forall x. ServiceConnectService -> Rep ServiceConnectService x
Prelude.Generic)

-- |
-- Create a value of 'ServiceConnectService' 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:
--
-- 'clientAliases', 'serviceConnectService_clientAliases' - The list of client aliases for this Service Connect service. You use
-- these to assign names that can be used by client applications. The
-- maximum number of client aliases that you can have in this list is 1.
--
-- Each alias (\"endpoint\") is a fully-qualified name and port number that
-- other Amazon ECS tasks (\"clients\") can use to connect to this service.
--
-- Each name and port mapping must be unique within the namespace.
--
-- For each @ServiceConnectService@, you must provide at least one
-- @clientAlias@ with one @port@.
--
-- 'discoveryName', 'serviceConnectService_discoveryName' - The @discoveryName@ is the name of the new Cloud Map service that Amazon
-- ECS creates for this Amazon ECS service. This must be unique within the
-- Cloud Map namespace. The name can contain up to 64 characters. The name
-- can include lowercase letters, numbers, underscores (_), and hyphens
-- (-). The name can\'t start with a hyphen.
--
-- If this parameter isn\'t specified, the default value of
-- @discoveryName.namespace@ is used. If the @discoveryName@ isn\'t
-- specified, the port mapping name from the task definition is used in
-- @portName.namespace@.
--
-- 'ingressPortOverride', 'serviceConnectService_ingressPortOverride' - The port number for the Service Connect proxy to listen on.
--
-- Use the value of this field to bypass the proxy for traffic on the port
-- number specified in the named @portMapping@ in the task definition of
-- this application, and then use it in your VPC security groups to allow
-- traffic into the proxy for this Amazon ECS service.
--
-- In @awsvpc@ mode and Fargate, the default value is the container port
-- number. The container port number is in the @portMapping@ in the task
-- definition. In bridge mode, the default value is the ephemeral port of
-- the Service Connect proxy.
--
-- 'portName', 'serviceConnectService_portName' - The @portName@ must match the name of one of the @portMappings@ from all
-- the containers in the task definition of this Amazon ECS service.
newServiceConnectService ::
  -- | 'portName'
  Prelude.Text ->
  ServiceConnectService
newServiceConnectService :: Text -> ServiceConnectService
newServiceConnectService Text
pPortName_ =
  ServiceConnectService'
    { $sel:clientAliases:ServiceConnectService' :: Maybe [ServiceConnectClientAlias]
clientAliases =
        forall a. Maybe a
Prelude.Nothing,
      $sel:discoveryName:ServiceConnectService' :: Maybe Text
discoveryName = forall a. Maybe a
Prelude.Nothing,
      $sel:ingressPortOverride:ServiceConnectService' :: Maybe Natural
ingressPortOverride = forall a. Maybe a
Prelude.Nothing,
      $sel:portName:ServiceConnectService' :: Text
portName = Text
pPortName_
    }

-- | The list of client aliases for this Service Connect service. You use
-- these to assign names that can be used by client applications. The
-- maximum number of client aliases that you can have in this list is 1.
--
-- Each alias (\"endpoint\") is a fully-qualified name and port number that
-- other Amazon ECS tasks (\"clients\") can use to connect to this service.
--
-- Each name and port mapping must be unique within the namespace.
--
-- For each @ServiceConnectService@, you must provide at least one
-- @clientAlias@ with one @port@.
serviceConnectService_clientAliases :: Lens.Lens' ServiceConnectService (Prelude.Maybe [ServiceConnectClientAlias])
serviceConnectService_clientAliases :: Lens' ServiceConnectService (Maybe [ServiceConnectClientAlias])
serviceConnectService_clientAliases = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceConnectService' {Maybe [ServiceConnectClientAlias]
clientAliases :: Maybe [ServiceConnectClientAlias]
$sel:clientAliases:ServiceConnectService' :: ServiceConnectService -> Maybe [ServiceConnectClientAlias]
clientAliases} -> Maybe [ServiceConnectClientAlias]
clientAliases) (\s :: ServiceConnectService
s@ServiceConnectService' {} Maybe [ServiceConnectClientAlias]
a -> ServiceConnectService
s {$sel:clientAliases:ServiceConnectService' :: Maybe [ServiceConnectClientAlias]
clientAliases = Maybe [ServiceConnectClientAlias]
a} :: ServiceConnectService) 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

-- | The @discoveryName@ is the name of the new Cloud Map service that Amazon
-- ECS creates for this Amazon ECS service. This must be unique within the
-- Cloud Map namespace. The name can contain up to 64 characters. The name
-- can include lowercase letters, numbers, underscores (_), and hyphens
-- (-). The name can\'t start with a hyphen.
--
-- If this parameter isn\'t specified, the default value of
-- @discoveryName.namespace@ is used. If the @discoveryName@ isn\'t
-- specified, the port mapping name from the task definition is used in
-- @portName.namespace@.
serviceConnectService_discoveryName :: Lens.Lens' ServiceConnectService (Prelude.Maybe Prelude.Text)
serviceConnectService_discoveryName :: Lens' ServiceConnectService (Maybe Text)
serviceConnectService_discoveryName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceConnectService' {Maybe Text
discoveryName :: Maybe Text
$sel:discoveryName:ServiceConnectService' :: ServiceConnectService -> Maybe Text
discoveryName} -> Maybe Text
discoveryName) (\s :: ServiceConnectService
s@ServiceConnectService' {} Maybe Text
a -> ServiceConnectService
s {$sel:discoveryName:ServiceConnectService' :: Maybe Text
discoveryName = Maybe Text
a} :: ServiceConnectService)

-- | The port number for the Service Connect proxy to listen on.
--
-- Use the value of this field to bypass the proxy for traffic on the port
-- number specified in the named @portMapping@ in the task definition of
-- this application, and then use it in your VPC security groups to allow
-- traffic into the proxy for this Amazon ECS service.
--
-- In @awsvpc@ mode and Fargate, the default value is the container port
-- number. The container port number is in the @portMapping@ in the task
-- definition. In bridge mode, the default value is the ephemeral port of
-- the Service Connect proxy.
serviceConnectService_ingressPortOverride :: Lens.Lens' ServiceConnectService (Prelude.Maybe Prelude.Natural)
serviceConnectService_ingressPortOverride :: Lens' ServiceConnectService (Maybe Natural)
serviceConnectService_ingressPortOverride = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceConnectService' {Maybe Natural
ingressPortOverride :: Maybe Natural
$sel:ingressPortOverride:ServiceConnectService' :: ServiceConnectService -> Maybe Natural
ingressPortOverride} -> Maybe Natural
ingressPortOverride) (\s :: ServiceConnectService
s@ServiceConnectService' {} Maybe Natural
a -> ServiceConnectService
s {$sel:ingressPortOverride:ServiceConnectService' :: Maybe Natural
ingressPortOverride = Maybe Natural
a} :: ServiceConnectService)

-- | The @portName@ must match the name of one of the @portMappings@ from all
-- the containers in the task definition of this Amazon ECS service.
serviceConnectService_portName :: Lens.Lens' ServiceConnectService Prelude.Text
serviceConnectService_portName :: Lens' ServiceConnectService Text
serviceConnectService_portName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceConnectService' {Text
portName :: Text
$sel:portName:ServiceConnectService' :: ServiceConnectService -> Text
portName} -> Text
portName) (\s :: ServiceConnectService
s@ServiceConnectService' {} Text
a -> ServiceConnectService
s {$sel:portName:ServiceConnectService' :: Text
portName = Text
a} :: ServiceConnectService)

instance Data.FromJSON ServiceConnectService where
  parseJSON :: Value -> Parser ServiceConnectService
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ServiceConnectService"
      ( \Object
x ->
          Maybe [ServiceConnectClientAlias]
-> Maybe Text -> Maybe Natural -> Text -> ServiceConnectService
ServiceConnectService'
            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
"clientAliases" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"discoveryName")
            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
"ingressPortOverride")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"portName")
      )

instance Prelude.Hashable ServiceConnectService where
  hashWithSalt :: Int -> ServiceConnectService -> Int
hashWithSalt Int
_salt ServiceConnectService' {Maybe Natural
Maybe [ServiceConnectClientAlias]
Maybe Text
Text
portName :: Text
ingressPortOverride :: Maybe Natural
discoveryName :: Maybe Text
clientAliases :: Maybe [ServiceConnectClientAlias]
$sel:portName:ServiceConnectService' :: ServiceConnectService -> Text
$sel:ingressPortOverride:ServiceConnectService' :: ServiceConnectService -> Maybe Natural
$sel:discoveryName:ServiceConnectService' :: ServiceConnectService -> Maybe Text
$sel:clientAliases:ServiceConnectService' :: ServiceConnectService -> Maybe [ServiceConnectClientAlias]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [ServiceConnectClientAlias]
clientAliases
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
discoveryName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
ingressPortOverride
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
portName

instance Prelude.NFData ServiceConnectService where
  rnf :: ServiceConnectService -> ()
rnf ServiceConnectService' {Maybe Natural
Maybe [ServiceConnectClientAlias]
Maybe Text
Text
portName :: Text
ingressPortOverride :: Maybe Natural
discoveryName :: Maybe Text
clientAliases :: Maybe [ServiceConnectClientAlias]
$sel:portName:ServiceConnectService' :: ServiceConnectService -> Text
$sel:ingressPortOverride:ServiceConnectService' :: ServiceConnectService -> Maybe Natural
$sel:discoveryName:ServiceConnectService' :: ServiceConnectService -> Maybe Text
$sel:clientAliases:ServiceConnectService' :: ServiceConnectService -> Maybe [ServiceConnectClientAlias]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [ServiceConnectClientAlias]
clientAliases
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
discoveryName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
ingressPortOverride
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
portName

instance Data.ToJSON ServiceConnectService where
  toJSON :: ServiceConnectService -> Value
toJSON ServiceConnectService' {Maybe Natural
Maybe [ServiceConnectClientAlias]
Maybe Text
Text
portName :: Text
ingressPortOverride :: Maybe Natural
discoveryName :: Maybe Text
clientAliases :: Maybe [ServiceConnectClientAlias]
$sel:portName:ServiceConnectService' :: ServiceConnectService -> Text
$sel:ingressPortOverride:ServiceConnectService' :: ServiceConnectService -> Maybe Natural
$sel:discoveryName:ServiceConnectService' :: ServiceConnectService -> Maybe Text
$sel:clientAliases:ServiceConnectService' :: ServiceConnectService -> Maybe [ServiceConnectClientAlias]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"clientAliases" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [ServiceConnectClientAlias]
clientAliases,
            (Key
"discoveryName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
discoveryName,
            (Key
"ingressPortOverride" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
ingressPortOverride,
            forall a. a -> Maybe a
Prelude.Just (Key
"portName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
portName)
          ]
      )