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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Each alias (\"endpoint\") is a fully-qualified name and port number that
-- other tasks (\"clients\") can use to connect to this service.
--
-- Each name and port mapping must be unique within the namespace.
--
-- Tasks that run in a namespace can use short names to connect to services
-- in the namespace. Tasks can connect to services across all of the
-- clusters in the namespace. Tasks connect through a managed proxy
-- container that collects logs and metrics for increased visibility. Only
-- the tasks that Amazon ECS services create are supported with Service
-- Connect. 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:/ 'newServiceConnectClientAlias' smart constructor.
data ServiceConnectClientAlias = ServiceConnectClientAlias'
  { -- | The @dnsName@ is the name that you use in the applications of client
    -- tasks to connect to this service. The name must be a valid DNS name but
    -- doesn\'t need to be fully-qualified. The name can include up to 127
    -- characters. The name can include lowercase letters, numbers, underscores
    -- (_), hyphens (-), and periods (.). 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@.
    --
    -- To avoid changing your applications in client Amazon ECS services, set
    -- this to the same name that the client application uses by default. For
    -- example, a few common names are @database@, @db@, or the lowercase name
    -- of a database, such as @mysql@ or @redis@. 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/.
    ServiceConnectClientAlias -> Maybe Text
dnsName :: Prelude.Maybe Prelude.Text,
    -- | The listening port number for the Service Connect proxy. This port is
    -- available inside of all of the tasks within the same namespace.
    --
    -- To avoid changing your applications in client Amazon ECS services, set
    -- this to the same port that the client application uses by default. 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/.
    ServiceConnectClientAlias -> Natural
port :: Prelude.Natural
  }
  deriving (ServiceConnectClientAlias -> ServiceConnectClientAlias -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ServiceConnectClientAlias -> ServiceConnectClientAlias -> Bool
$c/= :: ServiceConnectClientAlias -> ServiceConnectClientAlias -> Bool
== :: ServiceConnectClientAlias -> ServiceConnectClientAlias -> Bool
$c== :: ServiceConnectClientAlias -> ServiceConnectClientAlias -> Bool
Prelude.Eq, ReadPrec [ServiceConnectClientAlias]
ReadPrec ServiceConnectClientAlias
Int -> ReadS ServiceConnectClientAlias
ReadS [ServiceConnectClientAlias]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ServiceConnectClientAlias]
$creadListPrec :: ReadPrec [ServiceConnectClientAlias]
readPrec :: ReadPrec ServiceConnectClientAlias
$creadPrec :: ReadPrec ServiceConnectClientAlias
readList :: ReadS [ServiceConnectClientAlias]
$creadList :: ReadS [ServiceConnectClientAlias]
readsPrec :: Int -> ReadS ServiceConnectClientAlias
$creadsPrec :: Int -> ReadS ServiceConnectClientAlias
Prelude.Read, Int -> ServiceConnectClientAlias -> ShowS
[ServiceConnectClientAlias] -> ShowS
ServiceConnectClientAlias -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ServiceConnectClientAlias] -> ShowS
$cshowList :: [ServiceConnectClientAlias] -> ShowS
show :: ServiceConnectClientAlias -> String
$cshow :: ServiceConnectClientAlias -> String
showsPrec :: Int -> ServiceConnectClientAlias -> ShowS
$cshowsPrec :: Int -> ServiceConnectClientAlias -> ShowS
Prelude.Show, forall x.
Rep ServiceConnectClientAlias x -> ServiceConnectClientAlias
forall x.
ServiceConnectClientAlias -> Rep ServiceConnectClientAlias x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ServiceConnectClientAlias x -> ServiceConnectClientAlias
$cfrom :: forall x.
ServiceConnectClientAlias -> Rep ServiceConnectClientAlias x
Prelude.Generic)

-- |
-- Create a value of 'ServiceConnectClientAlias' 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:
--
-- 'dnsName', 'serviceConnectClientAlias_dnsName' - The @dnsName@ is the name that you use in the applications of client
-- tasks to connect to this service. The name must be a valid DNS name but
-- doesn\'t need to be fully-qualified. The name can include up to 127
-- characters. The name can include lowercase letters, numbers, underscores
-- (_), hyphens (-), and periods (.). 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@.
--
-- To avoid changing your applications in client Amazon ECS services, set
-- this to the same name that the client application uses by default. For
-- example, a few common names are @database@, @db@, or the lowercase name
-- of a database, such as @mysql@ or @redis@. 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/.
--
-- 'port', 'serviceConnectClientAlias_port' - The listening port number for the Service Connect proxy. This port is
-- available inside of all of the tasks within the same namespace.
--
-- To avoid changing your applications in client Amazon ECS services, set
-- this to the same port that the client application uses by default. 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/.
newServiceConnectClientAlias ::
  -- | 'port'
  Prelude.Natural ->
  ServiceConnectClientAlias
newServiceConnectClientAlias :: Natural -> ServiceConnectClientAlias
newServiceConnectClientAlias Natural
pPort_ =
  ServiceConnectClientAlias'
    { $sel:dnsName:ServiceConnectClientAlias' :: Maybe Text
dnsName =
        forall a. Maybe a
Prelude.Nothing,
      $sel:port:ServiceConnectClientAlias' :: Natural
port = Natural
pPort_
    }

-- | The @dnsName@ is the name that you use in the applications of client
-- tasks to connect to this service. The name must be a valid DNS name but
-- doesn\'t need to be fully-qualified. The name can include up to 127
-- characters. The name can include lowercase letters, numbers, underscores
-- (_), hyphens (-), and periods (.). 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@.
--
-- To avoid changing your applications in client Amazon ECS services, set
-- this to the same name that the client application uses by default. For
-- example, a few common names are @database@, @db@, or the lowercase name
-- of a database, such as @mysql@ or @redis@. 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/.
serviceConnectClientAlias_dnsName :: Lens.Lens' ServiceConnectClientAlias (Prelude.Maybe Prelude.Text)
serviceConnectClientAlias_dnsName :: Lens' ServiceConnectClientAlias (Maybe Text)
serviceConnectClientAlias_dnsName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceConnectClientAlias' {Maybe Text
dnsName :: Maybe Text
$sel:dnsName:ServiceConnectClientAlias' :: ServiceConnectClientAlias -> Maybe Text
dnsName} -> Maybe Text
dnsName) (\s :: ServiceConnectClientAlias
s@ServiceConnectClientAlias' {} Maybe Text
a -> ServiceConnectClientAlias
s {$sel:dnsName:ServiceConnectClientAlias' :: Maybe Text
dnsName = Maybe Text
a} :: ServiceConnectClientAlias)

-- | The listening port number for the Service Connect proxy. This port is
-- available inside of all of the tasks within the same namespace.
--
-- To avoid changing your applications in client Amazon ECS services, set
-- this to the same port that the client application uses by default. 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/.
serviceConnectClientAlias_port :: Lens.Lens' ServiceConnectClientAlias Prelude.Natural
serviceConnectClientAlias_port :: Lens' ServiceConnectClientAlias Natural
serviceConnectClientAlias_port = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceConnectClientAlias' {Natural
port :: Natural
$sel:port:ServiceConnectClientAlias' :: ServiceConnectClientAlias -> Natural
port} -> Natural
port) (\s :: ServiceConnectClientAlias
s@ServiceConnectClientAlias' {} Natural
a -> ServiceConnectClientAlias
s {$sel:port:ServiceConnectClientAlias' :: Natural
port = Natural
a} :: ServiceConnectClientAlias)

instance Data.FromJSON ServiceConnectClientAlias where
  parseJSON :: Value -> Parser ServiceConnectClientAlias
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ServiceConnectClientAlias"
      ( \Object
x ->
          Maybe Text -> Natural -> ServiceConnectClientAlias
ServiceConnectClientAlias'
            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
"dnsName")
            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
"port")
      )

instance Prelude.Hashable ServiceConnectClientAlias where
  hashWithSalt :: Int -> ServiceConnectClientAlias -> Int
hashWithSalt Int
_salt ServiceConnectClientAlias' {Natural
Maybe Text
port :: Natural
dnsName :: Maybe Text
$sel:port:ServiceConnectClientAlias' :: ServiceConnectClientAlias -> Natural
$sel:dnsName:ServiceConnectClientAlias' :: ServiceConnectClientAlias -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
dnsName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
port

instance Prelude.NFData ServiceConnectClientAlias where
  rnf :: ServiceConnectClientAlias -> ()
rnf ServiceConnectClientAlias' {Natural
Maybe Text
port :: Natural
dnsName :: Maybe Text
$sel:port:ServiceConnectClientAlias' :: ServiceConnectClientAlias -> Natural
$sel:dnsName:ServiceConnectClientAlias' :: ServiceConnectClientAlias -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
dnsName seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
port

instance Data.ToJSON ServiceConnectClientAlias where
  toJSON :: ServiceConnectClientAlias -> Value
toJSON ServiceConnectClientAlias' {Natural
Maybe Text
port :: Natural
dnsName :: Maybe Text
$sel:port:ServiceConnectClientAlias' :: ServiceConnectClientAlias -> Natural
$sel:dnsName:ServiceConnectClientAlias' :: ServiceConnectClientAlias -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"dnsName" 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
dnsName,
            forall a. a -> Maybe a
Prelude.Just (Key
"port" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
port)
          ]
      )