{-# 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.TerminateSession
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Permanently ends a session and closes the data connection between the
-- Session Manager client and SSM Agent on the managed node. A terminated
-- session can\'t be resumed.
module Amazonka.SSM.TerminateSession
  ( -- * Creating a Request
    TerminateSession (..),
    newTerminateSession,

    -- * Request Lenses
    terminateSession_sessionId,

    -- * Destructuring the Response
    TerminateSessionResponse (..),
    newTerminateSessionResponse,

    -- * Response Lenses
    terminateSessionResponse_sessionId,
    terminateSessionResponse_httpStatus,
  )
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SSM.Types

-- | /See:/ 'newTerminateSession' smart constructor.
data TerminateSession = TerminateSession'
  { -- | The ID of the session to terminate.
    TerminateSession -> Text
sessionId :: Prelude.Text
  }
  deriving (TerminateSession -> TerminateSession -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TerminateSession -> TerminateSession -> Bool
$c/= :: TerminateSession -> TerminateSession -> Bool
== :: TerminateSession -> TerminateSession -> Bool
$c== :: TerminateSession -> TerminateSession -> Bool
Prelude.Eq, ReadPrec [TerminateSession]
ReadPrec TerminateSession
Int -> ReadS TerminateSession
ReadS [TerminateSession]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TerminateSession]
$creadListPrec :: ReadPrec [TerminateSession]
readPrec :: ReadPrec TerminateSession
$creadPrec :: ReadPrec TerminateSession
readList :: ReadS [TerminateSession]
$creadList :: ReadS [TerminateSession]
readsPrec :: Int -> ReadS TerminateSession
$creadsPrec :: Int -> ReadS TerminateSession
Prelude.Read, Int -> TerminateSession -> ShowS
[TerminateSession] -> ShowS
TerminateSession -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TerminateSession] -> ShowS
$cshowList :: [TerminateSession] -> ShowS
show :: TerminateSession -> String
$cshow :: TerminateSession -> String
showsPrec :: Int -> TerminateSession -> ShowS
$cshowsPrec :: Int -> TerminateSession -> ShowS
Prelude.Show, forall x. Rep TerminateSession x -> TerminateSession
forall x. TerminateSession -> Rep TerminateSession x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TerminateSession x -> TerminateSession
$cfrom :: forall x. TerminateSession -> Rep TerminateSession x
Prelude.Generic)

-- |
-- Create a value of 'TerminateSession' 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:
--
-- 'sessionId', 'terminateSession_sessionId' - The ID of the session to terminate.
newTerminateSession ::
  -- | 'sessionId'
  Prelude.Text ->
  TerminateSession
newTerminateSession :: Text -> TerminateSession
newTerminateSession Text
pSessionId_ =
  TerminateSession' {$sel:sessionId:TerminateSession' :: Text
sessionId = Text
pSessionId_}

-- | The ID of the session to terminate.
terminateSession_sessionId :: Lens.Lens' TerminateSession Prelude.Text
terminateSession_sessionId :: Lens' TerminateSession Text
terminateSession_sessionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TerminateSession' {Text
sessionId :: Text
$sel:sessionId:TerminateSession' :: TerminateSession -> Text
sessionId} -> Text
sessionId) (\s :: TerminateSession
s@TerminateSession' {} Text
a -> TerminateSession
s {$sel:sessionId:TerminateSession' :: Text
sessionId = Text
a} :: TerminateSession)

instance Core.AWSRequest TerminateSession where
  type
    AWSResponse TerminateSession =
      TerminateSessionResponse
  request :: (Service -> Service)
-> TerminateSession -> Request TerminateSession
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 TerminateSession
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse TerminateSession)))
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 Text -> Int -> TerminateSessionResponse
TerminateSessionResponse'
            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
"SessionId")
            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 TerminateSession where
  hashWithSalt :: Int -> TerminateSession -> Int
hashWithSalt Int
_salt TerminateSession' {Text
sessionId :: Text
$sel:sessionId:TerminateSession' :: TerminateSession -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sessionId

instance Prelude.NFData TerminateSession where
  rnf :: TerminateSession -> ()
rnf TerminateSession' {Text
sessionId :: Text
$sel:sessionId:TerminateSession' :: TerminateSession -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
sessionId

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

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

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

-- | /See:/ 'newTerminateSessionResponse' smart constructor.
data TerminateSessionResponse = TerminateSessionResponse'
  { -- | The ID of the session that has been terminated.
    TerminateSessionResponse -> Maybe Text
sessionId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    TerminateSessionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (TerminateSessionResponse -> TerminateSessionResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TerminateSessionResponse -> TerminateSessionResponse -> Bool
$c/= :: TerminateSessionResponse -> TerminateSessionResponse -> Bool
== :: TerminateSessionResponse -> TerminateSessionResponse -> Bool
$c== :: TerminateSessionResponse -> TerminateSessionResponse -> Bool
Prelude.Eq, ReadPrec [TerminateSessionResponse]
ReadPrec TerminateSessionResponse
Int -> ReadS TerminateSessionResponse
ReadS [TerminateSessionResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TerminateSessionResponse]
$creadListPrec :: ReadPrec [TerminateSessionResponse]
readPrec :: ReadPrec TerminateSessionResponse
$creadPrec :: ReadPrec TerminateSessionResponse
readList :: ReadS [TerminateSessionResponse]
$creadList :: ReadS [TerminateSessionResponse]
readsPrec :: Int -> ReadS TerminateSessionResponse
$creadsPrec :: Int -> ReadS TerminateSessionResponse
Prelude.Read, Int -> TerminateSessionResponse -> ShowS
[TerminateSessionResponse] -> ShowS
TerminateSessionResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TerminateSessionResponse] -> ShowS
$cshowList :: [TerminateSessionResponse] -> ShowS
show :: TerminateSessionResponse -> String
$cshow :: TerminateSessionResponse -> String
showsPrec :: Int -> TerminateSessionResponse -> ShowS
$cshowsPrec :: Int -> TerminateSessionResponse -> ShowS
Prelude.Show, forall x.
Rep TerminateSessionResponse x -> TerminateSessionResponse
forall x.
TerminateSessionResponse -> Rep TerminateSessionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep TerminateSessionResponse x -> TerminateSessionResponse
$cfrom :: forall x.
TerminateSessionResponse -> Rep TerminateSessionResponse x
Prelude.Generic)

-- |
-- Create a value of 'TerminateSessionResponse' 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:
--
-- 'sessionId', 'terminateSessionResponse_sessionId' - The ID of the session that has been terminated.
--
-- 'httpStatus', 'terminateSessionResponse_httpStatus' - The response's http status code.
newTerminateSessionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  TerminateSessionResponse
newTerminateSessionResponse :: Int -> TerminateSessionResponse
newTerminateSessionResponse Int
pHttpStatus_ =
  TerminateSessionResponse'
    { $sel:sessionId:TerminateSessionResponse' :: Maybe Text
sessionId =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:TerminateSessionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ID of the session that has been terminated.
terminateSessionResponse_sessionId :: Lens.Lens' TerminateSessionResponse (Prelude.Maybe Prelude.Text)
terminateSessionResponse_sessionId :: Lens' TerminateSessionResponse (Maybe Text)
terminateSessionResponse_sessionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TerminateSessionResponse' {Maybe Text
sessionId :: Maybe Text
$sel:sessionId:TerminateSessionResponse' :: TerminateSessionResponse -> Maybe Text
sessionId} -> Maybe Text
sessionId) (\s :: TerminateSessionResponse
s@TerminateSessionResponse' {} Maybe Text
a -> TerminateSessionResponse
s {$sel:sessionId:TerminateSessionResponse' :: Maybe Text
sessionId = Maybe Text
a} :: TerminateSessionResponse)

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

instance Prelude.NFData TerminateSessionResponse where
  rnf :: TerminateSessionResponse -> ()
rnf TerminateSessionResponse' {Int
Maybe Text
httpStatus :: Int
sessionId :: Maybe Text
$sel:httpStatus:TerminateSessionResponse' :: TerminateSessionResponse -> Int
$sel:sessionId:TerminateSessionResponse' :: TerminateSessionResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
sessionId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus