{-# 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-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)
--
-- Permanently ends a session and closes the data connection between the
-- Session Manager client and SSM Agent on the instance. A terminated
-- session isn\'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.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:/ 'newTerminateSession' smart constructor.
data TerminateSession = TerminateSession'
  { -- | The ID of the session to terminate.
    TerminateSession -> Text
sessionId :: Prelude.Text
  }
  deriving (TerminateSession -> TerminateSession -> Bool
(TerminateSession -> TerminateSession -> Bool)
-> (TerminateSession -> TerminateSession -> Bool)
-> Eq TerminateSession
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]
(Int -> ReadS TerminateSession)
-> ReadS [TerminateSession]
-> ReadPrec TerminateSession
-> ReadPrec [TerminateSession]
-> Read 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
(Int -> TerminateSession -> ShowS)
-> (TerminateSession -> String)
-> ([TerminateSession] -> ShowS)
-> Show TerminateSession
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. TerminateSession -> Rep TerminateSession x)
-> (forall x. Rep TerminateSession x -> TerminateSession)
-> Generic TerminateSession
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' :: Text -> TerminateSession
TerminateSession' {$sel:sessionId:TerminateSession' :: Text
sessionId = Text
pSessionId_}

-- | The ID of the session to terminate.
terminateSession_sessionId :: Lens.Lens' TerminateSession Prelude.Text
terminateSession_sessionId :: (Text -> f Text) -> TerminateSession -> f TerminateSession
terminateSession_sessionId = (TerminateSession -> Text)
-> (TerminateSession -> Text -> TerminateSession)
-> Lens TerminateSession TerminateSession Text Text
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 :: TerminateSession -> Request TerminateSession
request = Service -> TerminateSession -> Request TerminateSession
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy TerminateSession
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse TerminateSession)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse TerminateSession))
-> Logger
-> Service
-> Proxy TerminateSession
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse TerminateSession)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> TerminateSessionResponse
TerminateSessionResponse'
            (Maybe Text -> Int -> TerminateSessionResponse)
-> Either String (Maybe Text)
-> Either String (Int -> TerminateSessionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"SessionId")
            Either String (Int -> TerminateSessionResponse)
-> Either String Int -> Either String TerminateSessionResponse
forall (f :: * -> *) a b. Applicative f => 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 TerminateSession

instance Prelude.NFData TerminateSession

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

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

instance Core.ToQuery TerminateSession where
  toQuery :: TerminateSession -> QueryString
toQuery = QueryString -> TerminateSession -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(TerminateSessionResponse -> TerminateSessionResponse -> Bool)
-> (TerminateSessionResponse -> TerminateSessionResponse -> Bool)
-> Eq TerminateSessionResponse
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]
(Int -> ReadS TerminateSessionResponse)
-> ReadS [TerminateSessionResponse]
-> ReadPrec TerminateSessionResponse
-> ReadPrec [TerminateSessionResponse]
-> Read 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
(Int -> TerminateSessionResponse -> ShowS)
-> (TerminateSessionResponse -> String)
-> ([TerminateSessionResponse] -> ShowS)
-> Show TerminateSessionResponse
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.
 TerminateSessionResponse -> Rep TerminateSessionResponse x)
-> (forall x.
    Rep TerminateSessionResponse x -> TerminateSessionResponse)
-> Generic TerminateSessionResponse
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' :: Maybe Text -> Int -> TerminateSessionResponse
TerminateSessionResponse'
    { $sel:sessionId:TerminateSessionResponse' :: Maybe Text
sessionId =
        Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> TerminateSessionResponse -> f TerminateSessionResponse
terminateSessionResponse_sessionId = (TerminateSessionResponse -> Maybe Text)
-> (TerminateSessionResponse
    -> Maybe Text -> TerminateSessionResponse)
-> Lens
     TerminateSessionResponse
     TerminateSessionResponse
     (Maybe Text)
     (Maybe Text)
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 :: (Int -> f Int)
-> TerminateSessionResponse -> f TerminateSessionResponse
terminateSessionResponse_httpStatus = (TerminateSessionResponse -> Int)
-> (TerminateSessionResponse -> Int -> TerminateSessionResponse)
-> Lens TerminateSessionResponse TerminateSessionResponse Int Int
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