{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.GetTaskProtection
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves the protection status of tasks in an Amazon ECS service.
module Amazonka.ECS.GetTaskProtection
  ( -- * Creating a Request
    GetTaskProtection (..),
    newGetTaskProtection,

    -- * Request Lenses
    getTaskProtection_tasks,
    getTaskProtection_cluster,

    -- * Destructuring the Response
    GetTaskProtectionResponse (..),
    newGetTaskProtectionResponse,

    -- * Response Lenses
    getTaskProtectionResponse_failures,
    getTaskProtectionResponse_protectedTasks,
    getTaskProtectionResponse_httpStatus,
  )
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
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetTaskProtection' smart constructor.
data GetTaskProtection = GetTaskProtection'
  { -- | A list of up to 100 task IDs or full ARN entries.
    GetTaskProtection -> Maybe [Text]
tasks :: Prelude.Maybe [Prelude.Text],
    -- | The short name or full Amazon Resource Name (ARN) of the cluster that
    -- hosts the service that the task sets exist in.
    GetTaskProtection -> Text
cluster :: Prelude.Text
  }
  deriving (GetTaskProtection -> GetTaskProtection -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetTaskProtection -> GetTaskProtection -> Bool
$c/= :: GetTaskProtection -> GetTaskProtection -> Bool
== :: GetTaskProtection -> GetTaskProtection -> Bool
$c== :: GetTaskProtection -> GetTaskProtection -> Bool
Prelude.Eq, ReadPrec [GetTaskProtection]
ReadPrec GetTaskProtection
Int -> ReadS GetTaskProtection
ReadS [GetTaskProtection]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetTaskProtection]
$creadListPrec :: ReadPrec [GetTaskProtection]
readPrec :: ReadPrec GetTaskProtection
$creadPrec :: ReadPrec GetTaskProtection
readList :: ReadS [GetTaskProtection]
$creadList :: ReadS [GetTaskProtection]
readsPrec :: Int -> ReadS GetTaskProtection
$creadsPrec :: Int -> ReadS GetTaskProtection
Prelude.Read, Int -> GetTaskProtection -> ShowS
[GetTaskProtection] -> ShowS
GetTaskProtection -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetTaskProtection] -> ShowS
$cshowList :: [GetTaskProtection] -> ShowS
show :: GetTaskProtection -> String
$cshow :: GetTaskProtection -> String
showsPrec :: Int -> GetTaskProtection -> ShowS
$cshowsPrec :: Int -> GetTaskProtection -> ShowS
Prelude.Show, forall x. Rep GetTaskProtection x -> GetTaskProtection
forall x. GetTaskProtection -> Rep GetTaskProtection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetTaskProtection x -> GetTaskProtection
$cfrom :: forall x. GetTaskProtection -> Rep GetTaskProtection x
Prelude.Generic)

-- |
-- Create a value of 'GetTaskProtection' 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:
--
-- 'tasks', 'getTaskProtection_tasks' - A list of up to 100 task IDs or full ARN entries.
--
-- 'cluster', 'getTaskProtection_cluster' - The short name or full Amazon Resource Name (ARN) of the cluster that
-- hosts the service that the task sets exist in.
newGetTaskProtection ::
  -- | 'cluster'
  Prelude.Text ->
  GetTaskProtection
newGetTaskProtection :: Text -> GetTaskProtection
newGetTaskProtection Text
pCluster_ =
  GetTaskProtection'
    { $sel:tasks:GetTaskProtection' :: Maybe [Text]
tasks = forall a. Maybe a
Prelude.Nothing,
      $sel:cluster:GetTaskProtection' :: Text
cluster = Text
pCluster_
    }

-- | A list of up to 100 task IDs or full ARN entries.
getTaskProtection_tasks :: Lens.Lens' GetTaskProtection (Prelude.Maybe [Prelude.Text])
getTaskProtection_tasks :: Lens' GetTaskProtection (Maybe [Text])
getTaskProtection_tasks = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTaskProtection' {Maybe [Text]
tasks :: Maybe [Text]
$sel:tasks:GetTaskProtection' :: GetTaskProtection -> Maybe [Text]
tasks} -> Maybe [Text]
tasks) (\s :: GetTaskProtection
s@GetTaskProtection' {} Maybe [Text]
a -> GetTaskProtection
s {$sel:tasks:GetTaskProtection' :: Maybe [Text]
tasks = Maybe [Text]
a} :: GetTaskProtection) 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 short name or full Amazon Resource Name (ARN) of the cluster that
-- hosts the service that the task sets exist in.
getTaskProtection_cluster :: Lens.Lens' GetTaskProtection Prelude.Text
getTaskProtection_cluster :: Lens' GetTaskProtection Text
getTaskProtection_cluster = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTaskProtection' {Text
cluster :: Text
$sel:cluster:GetTaskProtection' :: GetTaskProtection -> Text
cluster} -> Text
cluster) (\s :: GetTaskProtection
s@GetTaskProtection' {} Text
a -> GetTaskProtection
s {$sel:cluster:GetTaskProtection' :: Text
cluster = Text
a} :: GetTaskProtection)

instance Core.AWSRequest GetTaskProtection where
  type
    AWSResponse GetTaskProtection =
      GetTaskProtectionResponse
  request :: (Service -> Service)
-> GetTaskProtection -> Request GetTaskProtection
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetTaskProtection
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetTaskProtection)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [Failure]
-> Maybe [ProtectedTask] -> Int -> GetTaskProtectionResponse
GetTaskProtectionResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"failures" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ 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 -> Either String (Maybe a)
Data..?> Key
"protectedTasks" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetTaskProtection where
  hashWithSalt :: Int -> GetTaskProtection -> Int
hashWithSalt Int
_salt GetTaskProtection' {Maybe [Text]
Text
cluster :: Text
tasks :: Maybe [Text]
$sel:cluster:GetTaskProtection' :: GetTaskProtection -> Text
$sel:tasks:GetTaskProtection' :: GetTaskProtection -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
tasks
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
cluster

instance Prelude.NFData GetTaskProtection where
  rnf :: GetTaskProtection -> ()
rnf GetTaskProtection' {Maybe [Text]
Text
cluster :: Text
tasks :: Maybe [Text]
$sel:cluster:GetTaskProtection' :: GetTaskProtection -> Text
$sel:tasks:GetTaskProtection' :: GetTaskProtection -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
tasks seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
cluster

instance Data.ToHeaders GetTaskProtection where
  toHeaders :: GetTaskProtection -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"AmazonEC2ContainerServiceV20141113.GetTaskProtection" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

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

instance Data.ToPath GetTaskProtection where
  toPath :: GetTaskProtection -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery GetTaskProtection where
  toQuery :: GetTaskProtection -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newGetTaskProtectionResponse' smart constructor.
data GetTaskProtectionResponse = GetTaskProtectionResponse'
  { -- | Any failures associated with the call.
    GetTaskProtectionResponse -> Maybe [Failure]
failures :: Prelude.Maybe [Failure],
    -- | A list of tasks with the following information.
    --
    -- -   @taskArn@: The task ARN.
    --
    -- -   @protectionEnabled@: The protection status of the task. If scale-in
    --     protection is enabled for a task, the value is @true@. Otherwise, it
    --     is @false@.
    --
    -- -   @expirationDate@: The epoch time when protection for the task will
    --     expire.
    GetTaskProtectionResponse -> Maybe [ProtectedTask]
protectedTasks :: Prelude.Maybe [ProtectedTask],
    -- | The response's http status code.
    GetTaskProtectionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetTaskProtectionResponse -> GetTaskProtectionResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetTaskProtectionResponse -> GetTaskProtectionResponse -> Bool
$c/= :: GetTaskProtectionResponse -> GetTaskProtectionResponse -> Bool
== :: GetTaskProtectionResponse -> GetTaskProtectionResponse -> Bool
$c== :: GetTaskProtectionResponse -> GetTaskProtectionResponse -> Bool
Prelude.Eq, ReadPrec [GetTaskProtectionResponse]
ReadPrec GetTaskProtectionResponse
Int -> ReadS GetTaskProtectionResponse
ReadS [GetTaskProtectionResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetTaskProtectionResponse]
$creadListPrec :: ReadPrec [GetTaskProtectionResponse]
readPrec :: ReadPrec GetTaskProtectionResponse
$creadPrec :: ReadPrec GetTaskProtectionResponse
readList :: ReadS [GetTaskProtectionResponse]
$creadList :: ReadS [GetTaskProtectionResponse]
readsPrec :: Int -> ReadS GetTaskProtectionResponse
$creadsPrec :: Int -> ReadS GetTaskProtectionResponse
Prelude.Read, Int -> GetTaskProtectionResponse -> ShowS
[GetTaskProtectionResponse] -> ShowS
GetTaskProtectionResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetTaskProtectionResponse] -> ShowS
$cshowList :: [GetTaskProtectionResponse] -> ShowS
show :: GetTaskProtectionResponse -> String
$cshow :: GetTaskProtectionResponse -> String
showsPrec :: Int -> GetTaskProtectionResponse -> ShowS
$cshowsPrec :: Int -> GetTaskProtectionResponse -> ShowS
Prelude.Show, forall x.
Rep GetTaskProtectionResponse x -> GetTaskProtectionResponse
forall x.
GetTaskProtectionResponse -> Rep GetTaskProtectionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetTaskProtectionResponse x -> GetTaskProtectionResponse
$cfrom :: forall x.
GetTaskProtectionResponse -> Rep GetTaskProtectionResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetTaskProtectionResponse' 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:
--
-- 'failures', 'getTaskProtectionResponse_failures' - Any failures associated with the call.
--
-- 'protectedTasks', 'getTaskProtectionResponse_protectedTasks' - A list of tasks with the following information.
--
-- -   @taskArn@: The task ARN.
--
-- -   @protectionEnabled@: The protection status of the task. If scale-in
--     protection is enabled for a task, the value is @true@. Otherwise, it
--     is @false@.
--
-- -   @expirationDate@: The epoch time when protection for the task will
--     expire.
--
-- 'httpStatus', 'getTaskProtectionResponse_httpStatus' - The response's http status code.
newGetTaskProtectionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetTaskProtectionResponse
newGetTaskProtectionResponse :: Int -> GetTaskProtectionResponse
newGetTaskProtectionResponse Int
pHttpStatus_ =
  GetTaskProtectionResponse'
    { $sel:failures:GetTaskProtectionResponse' :: Maybe [Failure]
failures =
        forall a. Maybe a
Prelude.Nothing,
      $sel:protectedTasks:GetTaskProtectionResponse' :: Maybe [ProtectedTask]
protectedTasks = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetTaskProtectionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Any failures associated with the call.
getTaskProtectionResponse_failures :: Lens.Lens' GetTaskProtectionResponse (Prelude.Maybe [Failure])
getTaskProtectionResponse_failures :: Lens' GetTaskProtectionResponse (Maybe [Failure])
getTaskProtectionResponse_failures = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTaskProtectionResponse' {Maybe [Failure]
failures :: Maybe [Failure]
$sel:failures:GetTaskProtectionResponse' :: GetTaskProtectionResponse -> Maybe [Failure]
failures} -> Maybe [Failure]
failures) (\s :: GetTaskProtectionResponse
s@GetTaskProtectionResponse' {} Maybe [Failure]
a -> GetTaskProtectionResponse
s {$sel:failures:GetTaskProtectionResponse' :: Maybe [Failure]
failures = Maybe [Failure]
a} :: GetTaskProtectionResponse) 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

-- | A list of tasks with the following information.
--
-- -   @taskArn@: The task ARN.
--
-- -   @protectionEnabled@: The protection status of the task. If scale-in
--     protection is enabled for a task, the value is @true@. Otherwise, it
--     is @false@.
--
-- -   @expirationDate@: The epoch time when protection for the task will
--     expire.
getTaskProtectionResponse_protectedTasks :: Lens.Lens' GetTaskProtectionResponse (Prelude.Maybe [ProtectedTask])
getTaskProtectionResponse_protectedTasks :: Lens' GetTaskProtectionResponse (Maybe [ProtectedTask])
getTaskProtectionResponse_protectedTasks = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTaskProtectionResponse' {Maybe [ProtectedTask]
protectedTasks :: Maybe [ProtectedTask]
$sel:protectedTasks:GetTaskProtectionResponse' :: GetTaskProtectionResponse -> Maybe [ProtectedTask]
protectedTasks} -> Maybe [ProtectedTask]
protectedTasks) (\s :: GetTaskProtectionResponse
s@GetTaskProtectionResponse' {} Maybe [ProtectedTask]
a -> GetTaskProtectionResponse
s {$sel:protectedTasks:GetTaskProtectionResponse' :: Maybe [ProtectedTask]
protectedTasks = Maybe [ProtectedTask]
a} :: GetTaskProtectionResponse) 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 response's http status code.
getTaskProtectionResponse_httpStatus :: Lens.Lens' GetTaskProtectionResponse Prelude.Int
getTaskProtectionResponse_httpStatus :: Lens' GetTaskProtectionResponse Int
getTaskProtectionResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTaskProtectionResponse' {Int
httpStatus :: Int
$sel:httpStatus:GetTaskProtectionResponse' :: GetTaskProtectionResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: GetTaskProtectionResponse
s@GetTaskProtectionResponse' {} Int
a -> GetTaskProtectionResponse
s {$sel:httpStatus:GetTaskProtectionResponse' :: Int
httpStatus = Int
a} :: GetTaskProtectionResponse)

instance Prelude.NFData GetTaskProtectionResponse where
  rnf :: GetTaskProtectionResponse -> ()
rnf GetTaskProtectionResponse' {Int
Maybe [Failure]
Maybe [ProtectedTask]
httpStatus :: Int
protectedTasks :: Maybe [ProtectedTask]
failures :: Maybe [Failure]
$sel:httpStatus:GetTaskProtectionResponse' :: GetTaskProtectionResponse -> Int
$sel:protectedTasks:GetTaskProtectionResponse' :: GetTaskProtectionResponse -> Maybe [ProtectedTask]
$sel:failures:GetTaskProtectionResponse' :: GetTaskProtectionResponse -> Maybe [Failure]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Failure]
failures
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [ProtectedTask]
protectedTasks
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus