{-# 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-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)
--
-- Reconnects a session to an instance 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_streamUrl,
    resumeSessionResponse_tokenValue,
    resumeSessionResponse_sessionId,
    resumeSessionResponse_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:/ 'newResumeSession' smart constructor.
data ResumeSession = ResumeSession'
  { -- | The ID of the disconnected session to resume.
    ResumeSession -> Text
sessionId :: Prelude.Text
  }
  deriving (ResumeSession -> ResumeSession -> Bool
(ResumeSession -> ResumeSession -> Bool)
-> (ResumeSession -> ResumeSession -> Bool) -> Eq ResumeSession
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]
(Int -> ReadS ResumeSession)
-> ReadS [ResumeSession]
-> ReadPrec ResumeSession
-> ReadPrec [ResumeSession]
-> Read 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
(Int -> ResumeSession -> ShowS)
-> (ResumeSession -> String)
-> ([ResumeSession] -> ShowS)
-> Show ResumeSession
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. ResumeSession -> Rep ResumeSession x)
-> (forall x. Rep ResumeSession x -> ResumeSession)
-> Generic ResumeSession
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' :: Text -> ResumeSession
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 :: (Text -> f Text) -> ResumeSession -> f ResumeSession
resumeSession_sessionId = (ResumeSession -> Text)
-> (ResumeSession -> Text -> ResumeSession)
-> Lens ResumeSession ResumeSession Text Text
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 :: ResumeSession -> Request ResumeSession
request = Service -> ResumeSession -> Request ResumeSession
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ResumeSession
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ResumeSession)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ResumeSession))
-> Logger
-> Service
-> Proxy ResumeSession
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ResumeSession)))
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
-> Maybe Text -> Maybe Text -> Int -> ResumeSessionResponse
ResumeSessionResponse'
            (Maybe Text
 -> Maybe Text -> Maybe Text -> Int -> ResumeSessionResponse)
-> Either String (Maybe Text)
-> Either
     String (Maybe Text -> Maybe Text -> Int -> ResumeSessionResponse)
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
"StreamUrl")
            Either
  String (Maybe Text -> Maybe Text -> Int -> ResumeSessionResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> ResumeSessionResponse)
forall (f :: * -> *) a b. Applicative f => 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
"TokenValue")
            Either String (Maybe Text -> Int -> ResumeSessionResponse)
-> Either String (Maybe Text)
-> Either String (Int -> ResumeSessionResponse)
forall (f :: * -> *) a b. Applicative f => 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 -> ResumeSessionResponse)
-> Either String Int -> Either String ResumeSessionResponse
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 ResumeSession

instance Prelude.NFData ResumeSession

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

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

-- | /See:/ 'newResumeSessionResponse' smart constructor.
data ResumeSessionResponse = ResumeSessionResponse'
  { -- | A URL back to SSM Agent on the instance that the Session Manager client
    -- uses to send commands and receive output from the instance. 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 instance.
    ResumeSessionResponse -> Maybe Text
tokenValue :: Prelude.Maybe Prelude.Text,
    -- | The ID of the session.
    ResumeSessionResponse -> Maybe Text
sessionId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ResumeSessionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ResumeSessionResponse -> ResumeSessionResponse -> Bool
(ResumeSessionResponse -> ResumeSessionResponse -> Bool)
-> (ResumeSessionResponse -> ResumeSessionResponse -> Bool)
-> Eq ResumeSessionResponse
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]
(Int -> ReadS ResumeSessionResponse)
-> ReadS [ResumeSessionResponse]
-> ReadPrec ResumeSessionResponse
-> ReadPrec [ResumeSessionResponse]
-> Read 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
(Int -> ResumeSessionResponse -> ShowS)
-> (ResumeSessionResponse -> String)
-> ([ResumeSessionResponse] -> ShowS)
-> Show ResumeSessionResponse
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. ResumeSessionResponse -> Rep ResumeSessionResponse x)
-> (forall x. Rep ResumeSessionResponse x -> ResumeSessionResponse)
-> Generic ResumeSessionResponse
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:
--
-- 'streamUrl', 'resumeSessionResponse_streamUrl' - A URL back to SSM Agent on the instance that the Session Manager client
-- uses to send commands and receive output from the instance. 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 instance.
--
-- 'sessionId', 'resumeSessionResponse_sessionId' - The ID of the session.
--
-- 'httpStatus', 'resumeSessionResponse_httpStatus' - The response's http status code.
newResumeSessionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ResumeSessionResponse
newResumeSessionResponse :: Int -> ResumeSessionResponse
newResumeSessionResponse Int
pHttpStatus_ =
  ResumeSessionResponse' :: Maybe Text
-> Maybe Text -> Maybe Text -> Int -> ResumeSessionResponse
ResumeSessionResponse'
    { $sel:streamUrl:ResumeSessionResponse' :: Maybe Text
streamUrl = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tokenValue:ResumeSessionResponse' :: Maybe Text
tokenValue = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:sessionId:ResumeSessionResponse' :: Maybe Text
sessionId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ResumeSessionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A URL back to SSM Agent on the instance that the Session Manager client
-- uses to send commands and receive output from the instance. 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 :: (Maybe Text -> f (Maybe Text))
-> ResumeSessionResponse -> f ResumeSessionResponse
resumeSessionResponse_streamUrl = (ResumeSessionResponse -> Maybe Text)
-> (ResumeSessionResponse -> Maybe Text -> ResumeSessionResponse)
-> Lens
     ResumeSessionResponse
     ResumeSessionResponse
     (Maybe Text)
     (Maybe Text)
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 instance.
resumeSessionResponse_tokenValue :: Lens.Lens' ResumeSessionResponse (Prelude.Maybe Prelude.Text)
resumeSessionResponse_tokenValue :: (Maybe Text -> f (Maybe Text))
-> ResumeSessionResponse -> f ResumeSessionResponse
resumeSessionResponse_tokenValue = (ResumeSessionResponse -> Maybe Text)
-> (ResumeSessionResponse -> Maybe Text -> ResumeSessionResponse)
-> Lens
     ResumeSessionResponse
     ResumeSessionResponse
     (Maybe Text)
     (Maybe Text)
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 ID of the session.
resumeSessionResponse_sessionId :: Lens.Lens' ResumeSessionResponse (Prelude.Maybe Prelude.Text)
resumeSessionResponse_sessionId :: (Maybe Text -> f (Maybe Text))
-> ResumeSessionResponse -> f ResumeSessionResponse
resumeSessionResponse_sessionId = (ResumeSessionResponse -> Maybe Text)
-> (ResumeSessionResponse -> Maybe Text -> ResumeSessionResponse)
-> Lens
     ResumeSessionResponse
     ResumeSessionResponse
     (Maybe Text)
     (Maybe Text)
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)

-- | The response's http status code.
resumeSessionResponse_httpStatus :: Lens.Lens' ResumeSessionResponse Prelude.Int
resumeSessionResponse_httpStatus :: (Int -> f Int) -> ResumeSessionResponse -> f ResumeSessionResponse
resumeSessionResponse_httpStatus = (ResumeSessionResponse -> Int)
-> (ResumeSessionResponse -> Int -> ResumeSessionResponse)
-> Lens ResumeSessionResponse ResumeSessionResponse Int Int
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