{-# 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.SSM.CancelCommand
-- 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)
--
-- Attempts to cancel the command specified by the Command ID. There is no
-- guarantee that the command will be terminated and the underlying process
-- stopped.
module Amazonka.SSM.CancelCommand
  ( -- * Creating a Request
    CancelCommand (..),
    newCancelCommand,

    -- * Request Lenses
    cancelCommand_instanceIds,
    cancelCommand_commandId,

    -- * Destructuring the Response
    CancelCommandResponse (..),
    newCancelCommandResponse,

    -- * Response Lenses
    cancelCommandResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SSM.Types

-- |
--
-- /See:/ 'newCancelCommand' smart constructor.
data CancelCommand = CancelCommand'
  { -- | (Optional) A list of instance IDs on which you want to cancel the
    -- command. If not provided, the command is canceled on every instance on
    -- which it was requested.
    CancelCommand -> Maybe [Text]
instanceIds :: Prelude.Maybe [Prelude.Text],
    -- | The ID of the command you want to cancel.
    CancelCommand -> Text
commandId :: Prelude.Text
  }
  deriving (CancelCommand -> CancelCommand -> Bool
(CancelCommand -> CancelCommand -> Bool)
-> (CancelCommand -> CancelCommand -> Bool) -> Eq CancelCommand
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelCommand -> CancelCommand -> Bool
$c/= :: CancelCommand -> CancelCommand -> Bool
== :: CancelCommand -> CancelCommand -> Bool
$c== :: CancelCommand -> CancelCommand -> Bool
Prelude.Eq, ReadPrec [CancelCommand]
ReadPrec CancelCommand
Int -> ReadS CancelCommand
ReadS [CancelCommand]
(Int -> ReadS CancelCommand)
-> ReadS [CancelCommand]
-> ReadPrec CancelCommand
-> ReadPrec [CancelCommand]
-> Read CancelCommand
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelCommand]
$creadListPrec :: ReadPrec [CancelCommand]
readPrec :: ReadPrec CancelCommand
$creadPrec :: ReadPrec CancelCommand
readList :: ReadS [CancelCommand]
$creadList :: ReadS [CancelCommand]
readsPrec :: Int -> ReadS CancelCommand
$creadsPrec :: Int -> ReadS CancelCommand
Prelude.Read, Int -> CancelCommand -> ShowS
[CancelCommand] -> ShowS
CancelCommand -> String
(Int -> CancelCommand -> ShowS)
-> (CancelCommand -> String)
-> ([CancelCommand] -> ShowS)
-> Show CancelCommand
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelCommand] -> ShowS
$cshowList :: [CancelCommand] -> ShowS
show :: CancelCommand -> String
$cshow :: CancelCommand -> String
showsPrec :: Int -> CancelCommand -> ShowS
$cshowsPrec :: Int -> CancelCommand -> ShowS
Prelude.Show, (forall x. CancelCommand -> Rep CancelCommand x)
-> (forall x. Rep CancelCommand x -> CancelCommand)
-> Generic CancelCommand
forall x. Rep CancelCommand x -> CancelCommand
forall x. CancelCommand -> Rep CancelCommand x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelCommand x -> CancelCommand
$cfrom :: forall x. CancelCommand -> Rep CancelCommand x
Prelude.Generic)

-- |
-- Create a value of 'CancelCommand' 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:
--
-- 'instanceIds', 'cancelCommand_instanceIds' - (Optional) A list of instance IDs on which you want to cancel the
-- command. If not provided, the command is canceled on every instance on
-- which it was requested.
--
-- 'commandId', 'cancelCommand_commandId' - The ID of the command you want to cancel.
newCancelCommand ::
  -- | 'commandId'
  Prelude.Text ->
  CancelCommand
newCancelCommand :: Text -> CancelCommand
newCancelCommand Text
pCommandId_ =
  CancelCommand' :: Maybe [Text] -> Text -> CancelCommand
CancelCommand'
    { $sel:instanceIds:CancelCommand' :: Maybe [Text]
instanceIds = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:commandId:CancelCommand' :: Text
commandId = Text
pCommandId_
    }

-- | (Optional) A list of instance IDs on which you want to cancel the
-- command. If not provided, the command is canceled on every instance on
-- which it was requested.
cancelCommand_instanceIds :: Lens.Lens' CancelCommand (Prelude.Maybe [Prelude.Text])
cancelCommand_instanceIds :: (Maybe [Text] -> f (Maybe [Text]))
-> CancelCommand -> f CancelCommand
cancelCommand_instanceIds = (CancelCommand -> Maybe [Text])
-> (CancelCommand -> Maybe [Text] -> CancelCommand)
-> Lens CancelCommand CancelCommand (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelCommand' {Maybe [Text]
instanceIds :: Maybe [Text]
$sel:instanceIds:CancelCommand' :: CancelCommand -> Maybe [Text]
instanceIds} -> Maybe [Text]
instanceIds) (\s :: CancelCommand
s@CancelCommand' {} Maybe [Text]
a -> CancelCommand
s {$sel:instanceIds:CancelCommand' :: Maybe [Text]
instanceIds = Maybe [Text]
a} :: CancelCommand) ((Maybe [Text] -> f (Maybe [Text]))
 -> CancelCommand -> f CancelCommand)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> CancelCommand
-> f CancelCommand
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The ID of the command you want to cancel.
cancelCommand_commandId :: Lens.Lens' CancelCommand Prelude.Text
cancelCommand_commandId :: (Text -> f Text) -> CancelCommand -> f CancelCommand
cancelCommand_commandId = (CancelCommand -> Text)
-> (CancelCommand -> Text -> CancelCommand)
-> Lens CancelCommand CancelCommand Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelCommand' {Text
commandId :: Text
$sel:commandId:CancelCommand' :: CancelCommand -> Text
commandId} -> Text
commandId) (\s :: CancelCommand
s@CancelCommand' {} Text
a -> CancelCommand
s {$sel:commandId:CancelCommand' :: Text
commandId = Text
a} :: CancelCommand)

instance Core.AWSRequest CancelCommand where
  type
    AWSResponse CancelCommand =
      CancelCommandResponse
  request :: CancelCommand -> Request CancelCommand
request = Service -> CancelCommand -> Request CancelCommand
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CancelCommand
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CancelCommand)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse CancelCommand))
-> Logger
-> Service
-> Proxy CancelCommand
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CancelCommand)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> CancelCommandResponse
CancelCommandResponse'
            (Int -> CancelCommandResponse)
-> Either String Int -> Either String CancelCommandResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CancelCommand

instance Prelude.NFData CancelCommand

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

instance Core.ToJSON CancelCommand where
  toJSON :: CancelCommand -> Value
toJSON CancelCommand' {Maybe [Text]
Text
commandId :: Text
instanceIds :: Maybe [Text]
$sel:commandId:CancelCommand' :: CancelCommand -> Text
$sel:instanceIds:CancelCommand' :: CancelCommand -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"InstanceIds" 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]
instanceIds,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"CommandId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
commandId)
          ]
      )

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

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

-- | Whether or not the command was successfully canceled. There is no
-- guarantee that a request can be canceled.
--
-- /See:/ 'newCancelCommandResponse' smart constructor.
data CancelCommandResponse = CancelCommandResponse'
  { -- | The response's http status code.
    CancelCommandResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CancelCommandResponse -> CancelCommandResponse -> Bool
(CancelCommandResponse -> CancelCommandResponse -> Bool)
-> (CancelCommandResponse -> CancelCommandResponse -> Bool)
-> Eq CancelCommandResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelCommandResponse -> CancelCommandResponse -> Bool
$c/= :: CancelCommandResponse -> CancelCommandResponse -> Bool
== :: CancelCommandResponse -> CancelCommandResponse -> Bool
$c== :: CancelCommandResponse -> CancelCommandResponse -> Bool
Prelude.Eq, ReadPrec [CancelCommandResponse]
ReadPrec CancelCommandResponse
Int -> ReadS CancelCommandResponse
ReadS [CancelCommandResponse]
(Int -> ReadS CancelCommandResponse)
-> ReadS [CancelCommandResponse]
-> ReadPrec CancelCommandResponse
-> ReadPrec [CancelCommandResponse]
-> Read CancelCommandResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelCommandResponse]
$creadListPrec :: ReadPrec [CancelCommandResponse]
readPrec :: ReadPrec CancelCommandResponse
$creadPrec :: ReadPrec CancelCommandResponse
readList :: ReadS [CancelCommandResponse]
$creadList :: ReadS [CancelCommandResponse]
readsPrec :: Int -> ReadS CancelCommandResponse
$creadsPrec :: Int -> ReadS CancelCommandResponse
Prelude.Read, Int -> CancelCommandResponse -> ShowS
[CancelCommandResponse] -> ShowS
CancelCommandResponse -> String
(Int -> CancelCommandResponse -> ShowS)
-> (CancelCommandResponse -> String)
-> ([CancelCommandResponse] -> ShowS)
-> Show CancelCommandResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelCommandResponse] -> ShowS
$cshowList :: [CancelCommandResponse] -> ShowS
show :: CancelCommandResponse -> String
$cshow :: CancelCommandResponse -> String
showsPrec :: Int -> CancelCommandResponse -> ShowS
$cshowsPrec :: Int -> CancelCommandResponse -> ShowS
Prelude.Show, (forall x. CancelCommandResponse -> Rep CancelCommandResponse x)
-> (forall x. Rep CancelCommandResponse x -> CancelCommandResponse)
-> Generic CancelCommandResponse
forall x. Rep CancelCommandResponse x -> CancelCommandResponse
forall x. CancelCommandResponse -> Rep CancelCommandResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelCommandResponse x -> CancelCommandResponse
$cfrom :: forall x. CancelCommandResponse -> Rep CancelCommandResponse x
Prelude.Generic)

-- |
-- Create a value of 'CancelCommandResponse' 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:
--
-- 'httpStatus', 'cancelCommandResponse_httpStatus' - The response's http status code.
newCancelCommandResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CancelCommandResponse
newCancelCommandResponse :: Int -> CancelCommandResponse
newCancelCommandResponse Int
pHttpStatus_ =
  CancelCommandResponse' :: Int -> CancelCommandResponse
CancelCommandResponse' {$sel:httpStatus:CancelCommandResponse' :: Int
httpStatus = Int
pHttpStatus_}

-- | The response's http status code.
cancelCommandResponse_httpStatus :: Lens.Lens' CancelCommandResponse Prelude.Int
cancelCommandResponse_httpStatus :: (Int -> f Int) -> CancelCommandResponse -> f CancelCommandResponse
cancelCommandResponse_httpStatus = (CancelCommandResponse -> Int)
-> (CancelCommandResponse -> Int -> CancelCommandResponse)
-> Lens CancelCommandResponse CancelCommandResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelCommandResponse' {Int
httpStatus :: Int
$sel:httpStatus:CancelCommandResponse' :: CancelCommandResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CancelCommandResponse
s@CancelCommandResponse' {} Int
a -> CancelCommandResponse
s {$sel:httpStatus:CancelCommandResponse' :: Int
httpStatus = Int
a} :: CancelCommandResponse)

instance Prelude.NFData CancelCommandResponse