{-# 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.ResumeSession
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Reconnects a session to a managed node after it has been disconnected.
-- Connections can be resumed for disconnected sessions, but not terminated
-- sessions.
--
-- This command is primarily for use by client machines to automatically
-- reconnect during intermittent network issues. It isn\'t intended for any
-- other use.
module Amazonka.SSM.ResumeSession
  ( -- * Creating a Request
    ResumeSession (..),
    newResumeSession,

    -- * Request Lenses
    resumeSession_sessionId,

    -- * Destructuring the Response
    ResumeSessionResponse (..),
    newResumeSessionResponse,

    -- * Response Lenses
    resumeSessionResponse_sessionId,
    resumeSessionResponse_streamUrl,
    resumeSessionResponse_tokenValue,
    resumeSessionResponse_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:/ 'newResumeSession' smart constructor.
data ResumeSession = ResumeSession'
  { -- | The ID of the disconnected session to resume.
    ResumeSession -> Text
sessionId :: Prelude.Text
  }
  deriving (ResumeSession -> ResumeSession -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResumeSession -> ResumeSession -> Bool
$c/= :: ResumeSession -> ResumeSession -> Bool
== :: ResumeSession -> ResumeSession -> Bool
$c== :: ResumeSession -> ResumeSession -> Bool
Prelude.Eq, ReadPrec [ResumeSession]
ReadPrec ResumeSession
Int -> ReadS ResumeSession
ReadS [ResumeSession]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResumeSession]
$creadListPrec :: ReadPrec [ResumeSession]
readPrec :: ReadPrec ResumeSession
$creadPrec :: ReadPrec ResumeSession
readList :: ReadS [ResumeSession]
$creadList :: ReadS [ResumeSession]
readsPrec :: Int -> ReadS ResumeSession
$creadsPrec :: Int -> ReadS ResumeSession
Prelude.Read, Int -> ResumeSession -> ShowS
[ResumeSession] -> ShowS
ResumeSession -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResumeSession] -> ShowS
$cshowList :: [ResumeSession] -> ShowS
show :: ResumeSession -> String
$cshow :: ResumeSession -> String
showsPrec :: Int -> ResumeSession -> ShowS
$cshowsPrec :: Int -> ResumeSession -> ShowS
Prelude.Show, forall x. Rep ResumeSession x -> ResumeSession
forall x. ResumeSession -> Rep ResumeSession x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResumeSession x -> ResumeSession
$cfrom :: forall x. ResumeSession -> Rep ResumeSession x
Prelude.Generic)

-- |
-- Create a value of 'ResumeSession' 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', 'resumeSession_sessionId' - The ID of the disconnected session to resume.
newResumeSession ::
  -- | 'sessionId'
  Prelude.Text ->
  ResumeSession
newResumeSession :: Text -> ResumeSession
newResumeSession Text
pSessionId_ =
  ResumeSession' {$sel:sessionId:ResumeSession' :: Text
sessionId = Text
pSessionId_}

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

instance Core.AWSRequest ResumeSession where
  type
    AWSResponse ResumeSession =
      ResumeSessionResponse
  request :: (Service -> Service) -> ResumeSession -> Request ResumeSession
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 ResumeSession
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ResumeSession)))
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
-> Maybe Text -> Maybe Text -> Int -> ResumeSessionResponse
ResumeSessionResponse'
            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.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"StreamUrl")
            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
"TokenValue")
            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 ResumeSession where
  hashWithSalt :: Int -> ResumeSession -> Int
hashWithSalt Int
_salt ResumeSession' {Text
sessionId :: Text
$sel:sessionId:ResumeSession' :: ResumeSession -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sessionId

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

instance Data.ToHeaders ResumeSession where
  toHeaders :: ResumeSession -> 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.ResumeSession" :: 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 ResumeSession where
  toJSON :: ResumeSession -> Value
toJSON ResumeSession' {Text
sessionId :: Text
$sel:sessionId:ResumeSession' :: ResumeSession -> 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 ResumeSession where
  toPath :: ResumeSession -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newResumeSessionResponse' smart constructor.
data ResumeSessionResponse = ResumeSessionResponse'
  { -- | The ID of the session.
    ResumeSessionResponse -> Maybe Text
sessionId :: Prelude.Maybe Prelude.Text,
    -- | A URL back to SSM Agent on the managed node that the Session Manager
    -- client uses to send commands and receive output from the managed node.
    -- Format:
    -- @wss:\/\/ssmmessages.@__@region@__@.amazonaws.com\/v1\/data-channel\/@__@session-id@__@?stream=(input|output)@.
    --
    -- __region__ represents the Region identifier for an Amazon Web Services
    -- Region supported by Amazon Web Services Systems Manager, such as
    -- @us-east-2@ for the US East (Ohio) Region. For a list of supported
    -- __region__ values, see the __Region__ column in
    -- <https://docs.aws.amazon.com/general/latest/gr/ssm.html#ssm_region Systems Manager service endpoints>
    -- in the /Amazon Web Services General Reference/.
    --
    -- __session-id__ represents the ID of a Session Manager session, such as
    -- @1a2b3c4dEXAMPLE@.
    ResumeSessionResponse -> Maybe Text
streamUrl :: Prelude.Maybe Prelude.Text,
    -- | An encrypted token value containing session and caller information. Used
    -- to authenticate the connection to the managed node.
    ResumeSessionResponse -> Maybe Text
tokenValue :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ResumeSessionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ResumeSessionResponse -> ResumeSessionResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResumeSessionResponse -> ResumeSessionResponse -> Bool
$c/= :: ResumeSessionResponse -> ResumeSessionResponse -> Bool
== :: ResumeSessionResponse -> ResumeSessionResponse -> Bool
$c== :: ResumeSessionResponse -> ResumeSessionResponse -> Bool
Prelude.Eq, ReadPrec [ResumeSessionResponse]
ReadPrec ResumeSessionResponse
Int -> ReadS ResumeSessionResponse
ReadS [ResumeSessionResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResumeSessionResponse]
$creadListPrec :: ReadPrec [ResumeSessionResponse]
readPrec :: ReadPrec ResumeSessionResponse
$creadPrec :: ReadPrec ResumeSessionResponse
readList :: ReadS [ResumeSessionResponse]
$creadList :: ReadS [ResumeSessionResponse]
readsPrec :: Int -> ReadS ResumeSessionResponse
$creadsPrec :: Int -> ReadS ResumeSessionResponse
Prelude.Read, Int -> ResumeSessionResponse -> ShowS
[ResumeSessionResponse] -> ShowS
ResumeSessionResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResumeSessionResponse] -> ShowS
$cshowList :: [ResumeSessionResponse] -> ShowS
show :: ResumeSessionResponse -> String
$cshow :: ResumeSessionResponse -> String
showsPrec :: Int -> ResumeSessionResponse -> ShowS
$cshowsPrec :: Int -> ResumeSessionResponse -> ShowS
Prelude.Show, forall x. Rep ResumeSessionResponse x -> ResumeSessionResponse
forall x. ResumeSessionResponse -> Rep ResumeSessionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResumeSessionResponse x -> ResumeSessionResponse
$cfrom :: forall x. ResumeSessionResponse -> Rep ResumeSessionResponse x
Prelude.Generic)

-- |
-- Create a value of 'ResumeSessionResponse' 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', 'resumeSessionResponse_sessionId' - The ID of the session.
--
-- 'streamUrl', 'resumeSessionResponse_streamUrl' - A URL back to SSM Agent on the managed node that the Session Manager
-- client uses to send commands and receive output from the managed node.
-- Format:
-- @wss:\/\/ssmmessages.@__@region@__@.amazonaws.com\/v1\/data-channel\/@__@session-id@__@?stream=(input|output)@.
--
-- __region__ represents the Region identifier for an Amazon Web Services
-- Region supported by Amazon Web Services Systems Manager, such as
-- @us-east-2@ for the US East (Ohio) Region. For a list of supported
-- __region__ values, see the __Region__ column in
-- <https://docs.aws.amazon.com/general/latest/gr/ssm.html#ssm_region Systems Manager service endpoints>
-- in the /Amazon Web Services General Reference/.
--
-- __session-id__ represents the ID of a Session Manager session, such as
-- @1a2b3c4dEXAMPLE@.
--
-- 'tokenValue', 'resumeSessionResponse_tokenValue' - An encrypted token value containing session and caller information. Used
-- to authenticate the connection to the managed node.
--
-- 'httpStatus', 'resumeSessionResponse_httpStatus' - The response's http status code.
newResumeSessionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ResumeSessionResponse
newResumeSessionResponse :: Int -> ResumeSessionResponse
newResumeSessionResponse Int
pHttpStatus_ =
  ResumeSessionResponse'
    { $sel:sessionId:ResumeSessionResponse' :: Maybe Text
sessionId = forall a. Maybe a
Prelude.Nothing,
      $sel:streamUrl:ResumeSessionResponse' :: Maybe Text
streamUrl = forall a. Maybe a
Prelude.Nothing,
      $sel:tokenValue:ResumeSessionResponse' :: Maybe Text
tokenValue = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ResumeSessionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

-- | A URL back to SSM Agent on the managed node that the Session Manager
-- client uses to send commands and receive output from the managed node.
-- Format:
-- @wss:\/\/ssmmessages.@__@region@__@.amazonaws.com\/v1\/data-channel\/@__@session-id@__@?stream=(input|output)@.
--
-- __region__ represents the Region identifier for an Amazon Web Services
-- Region supported by Amazon Web Services Systems Manager, such as
-- @us-east-2@ for the US East (Ohio) Region. For a list of supported
-- __region__ values, see the __Region__ column in
-- <https://docs.aws.amazon.com/general/latest/gr/ssm.html#ssm_region Systems Manager service endpoints>
-- in the /Amazon Web Services General Reference/.
--
-- __session-id__ represents the ID of a Session Manager session, such as
-- @1a2b3c4dEXAMPLE@.
resumeSessionResponse_streamUrl :: Lens.Lens' ResumeSessionResponse (Prelude.Maybe Prelude.Text)
resumeSessionResponse_streamUrl :: Lens' ResumeSessionResponse (Maybe Text)
resumeSessionResponse_streamUrl = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResumeSessionResponse' {Maybe Text
streamUrl :: Maybe Text
$sel:streamUrl:ResumeSessionResponse' :: ResumeSessionResponse -> Maybe Text
streamUrl} -> Maybe Text
streamUrl) (\s :: ResumeSessionResponse
s@ResumeSessionResponse' {} Maybe Text
a -> ResumeSessionResponse
s {$sel:streamUrl:ResumeSessionResponse' :: Maybe Text
streamUrl = Maybe Text
a} :: ResumeSessionResponse)

-- | An encrypted token value containing session and caller information. Used
-- to authenticate the connection to the managed node.
resumeSessionResponse_tokenValue :: Lens.Lens' ResumeSessionResponse (Prelude.Maybe Prelude.Text)
resumeSessionResponse_tokenValue :: Lens' ResumeSessionResponse (Maybe Text)
resumeSessionResponse_tokenValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResumeSessionResponse' {Maybe Text
tokenValue :: Maybe Text
$sel:tokenValue:ResumeSessionResponse' :: ResumeSessionResponse -> Maybe Text
tokenValue} -> Maybe Text
tokenValue) (\s :: ResumeSessionResponse
s@ResumeSessionResponse' {} Maybe Text
a -> ResumeSessionResponse
s {$sel:tokenValue:ResumeSessionResponse' :: Maybe Text
tokenValue = Maybe Text
a} :: ResumeSessionResponse)

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

instance Prelude.NFData ResumeSessionResponse where
  rnf :: ResumeSessionResponse -> ()
rnf ResumeSessionResponse' {Int
Maybe Text
httpStatus :: Int
tokenValue :: Maybe Text
streamUrl :: Maybe Text
sessionId :: Maybe Text
$sel:httpStatus:ResumeSessionResponse' :: ResumeSessionResponse -> Int
$sel:tokenValue:ResumeSessionResponse' :: ResumeSessionResponse -> Maybe Text
$sel:streamUrl:ResumeSessionResponse' :: ResumeSessionResponse -> Maybe Text
$sel:sessionId:ResumeSessionResponse' :: ResumeSessionResponse -> 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 Maybe Text
streamUrl
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
tokenValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus