{-# 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.OpsWorks.GrantAccess
-- 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)
--
-- This action can be used only with Windows stacks.
--
-- Grants RDP access to a Windows instance for a specified time period.
module Amazonka.OpsWorks.GrantAccess
  ( -- * Creating a Request
    GrantAccess (..),
    newGrantAccess,

    -- * Request Lenses
    grantAccess_validForInMinutes,
    grantAccess_instanceId,

    -- * Destructuring the Response
    GrantAccessResponse (..),
    newGrantAccessResponse,

    -- * Response Lenses
    grantAccessResponse_temporaryCredential,
    grantAccessResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGrantAccess' smart constructor.
data GrantAccess = GrantAccess'
  { -- | The length of time (in minutes) that the grant is valid. When the grant
    -- expires at the end of this period, the user will no longer be able to
    -- use the credentials to log in. If the user is logged in at the time, he
    -- or she automatically will be logged out.
    GrantAccess -> Maybe Natural
validForInMinutes :: Prelude.Maybe Prelude.Natural,
    -- | The instance\'s AWS OpsWorks Stacks ID.
    GrantAccess -> Text
instanceId :: Prelude.Text
  }
  deriving (GrantAccess -> GrantAccess -> Bool
(GrantAccess -> GrantAccess -> Bool)
-> (GrantAccess -> GrantAccess -> Bool) -> Eq GrantAccess
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GrantAccess -> GrantAccess -> Bool
$c/= :: GrantAccess -> GrantAccess -> Bool
== :: GrantAccess -> GrantAccess -> Bool
$c== :: GrantAccess -> GrantAccess -> Bool
Prelude.Eq, ReadPrec [GrantAccess]
ReadPrec GrantAccess
Int -> ReadS GrantAccess
ReadS [GrantAccess]
(Int -> ReadS GrantAccess)
-> ReadS [GrantAccess]
-> ReadPrec GrantAccess
-> ReadPrec [GrantAccess]
-> Read GrantAccess
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GrantAccess]
$creadListPrec :: ReadPrec [GrantAccess]
readPrec :: ReadPrec GrantAccess
$creadPrec :: ReadPrec GrantAccess
readList :: ReadS [GrantAccess]
$creadList :: ReadS [GrantAccess]
readsPrec :: Int -> ReadS GrantAccess
$creadsPrec :: Int -> ReadS GrantAccess
Prelude.Read, Int -> GrantAccess -> ShowS
[GrantAccess] -> ShowS
GrantAccess -> String
(Int -> GrantAccess -> ShowS)
-> (GrantAccess -> String)
-> ([GrantAccess] -> ShowS)
-> Show GrantAccess
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GrantAccess] -> ShowS
$cshowList :: [GrantAccess] -> ShowS
show :: GrantAccess -> String
$cshow :: GrantAccess -> String
showsPrec :: Int -> GrantAccess -> ShowS
$cshowsPrec :: Int -> GrantAccess -> ShowS
Prelude.Show, (forall x. GrantAccess -> Rep GrantAccess x)
-> (forall x. Rep GrantAccess x -> GrantAccess)
-> Generic GrantAccess
forall x. Rep GrantAccess x -> GrantAccess
forall x. GrantAccess -> Rep GrantAccess x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GrantAccess x -> GrantAccess
$cfrom :: forall x. GrantAccess -> Rep GrantAccess x
Prelude.Generic)

-- |
-- Create a value of 'GrantAccess' 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:
--
-- 'validForInMinutes', 'grantAccess_validForInMinutes' - The length of time (in minutes) that the grant is valid. When the grant
-- expires at the end of this period, the user will no longer be able to
-- use the credentials to log in. If the user is logged in at the time, he
-- or she automatically will be logged out.
--
-- 'instanceId', 'grantAccess_instanceId' - The instance\'s AWS OpsWorks Stacks ID.
newGrantAccess ::
  -- | 'instanceId'
  Prelude.Text ->
  GrantAccess
newGrantAccess :: Text -> GrantAccess
newGrantAccess Text
pInstanceId_ =
  GrantAccess' :: Maybe Natural -> Text -> GrantAccess
GrantAccess'
    { $sel:validForInMinutes:GrantAccess' :: Maybe Natural
validForInMinutes = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:instanceId:GrantAccess' :: Text
instanceId = Text
pInstanceId_
    }

-- | The length of time (in minutes) that the grant is valid. When the grant
-- expires at the end of this period, the user will no longer be able to
-- use the credentials to log in. If the user is logged in at the time, he
-- or she automatically will be logged out.
grantAccess_validForInMinutes :: Lens.Lens' GrantAccess (Prelude.Maybe Prelude.Natural)
grantAccess_validForInMinutes :: (Maybe Natural -> f (Maybe Natural))
-> GrantAccess -> f GrantAccess
grantAccess_validForInMinutes = (GrantAccess -> Maybe Natural)
-> (GrantAccess -> Maybe Natural -> GrantAccess)
-> Lens GrantAccess GrantAccess (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrantAccess' {Maybe Natural
validForInMinutes :: Maybe Natural
$sel:validForInMinutes:GrantAccess' :: GrantAccess -> Maybe Natural
validForInMinutes} -> Maybe Natural
validForInMinutes) (\s :: GrantAccess
s@GrantAccess' {} Maybe Natural
a -> GrantAccess
s {$sel:validForInMinutes:GrantAccess' :: Maybe Natural
validForInMinutes = Maybe Natural
a} :: GrantAccess)

-- | The instance\'s AWS OpsWorks Stacks ID.
grantAccess_instanceId :: Lens.Lens' GrantAccess Prelude.Text
grantAccess_instanceId :: (Text -> f Text) -> GrantAccess -> f GrantAccess
grantAccess_instanceId = (GrantAccess -> Text)
-> (GrantAccess -> Text -> GrantAccess)
-> Lens GrantAccess GrantAccess Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrantAccess' {Text
instanceId :: Text
$sel:instanceId:GrantAccess' :: GrantAccess -> Text
instanceId} -> Text
instanceId) (\s :: GrantAccess
s@GrantAccess' {} Text
a -> GrantAccess
s {$sel:instanceId:GrantAccess' :: Text
instanceId = Text
a} :: GrantAccess)

instance Core.AWSRequest GrantAccess where
  type AWSResponse GrantAccess = GrantAccessResponse
  request :: GrantAccess -> Request GrantAccess
request = Service -> GrantAccess -> Request GrantAccess
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GrantAccess
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GrantAccess)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GrantAccess))
-> Logger
-> Service
-> Proxy GrantAccess
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GrantAccess)))
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 TemporaryCredential -> Int -> GrantAccessResponse
GrantAccessResponse'
            (Maybe TemporaryCredential -> Int -> GrantAccessResponse)
-> Either String (Maybe TemporaryCredential)
-> Either String (Int -> GrantAccessResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe TemporaryCredential)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"TemporaryCredential")
            Either String (Int -> GrantAccessResponse)
-> Either String Int -> Either String GrantAccessResponse
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 GrantAccess

instance Prelude.NFData GrantAccess

instance Core.ToHeaders GrantAccess where
  toHeaders :: GrantAccess -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GrantAccess -> 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
"OpsWorks_20130218.GrantAccess" ::
                          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 GrantAccess where
  toJSON :: GrantAccess -> Value
toJSON GrantAccess' {Maybe Natural
Text
instanceId :: Text
validForInMinutes :: Maybe Natural
$sel:instanceId:GrantAccess' :: GrantAccess -> Text
$sel:validForInMinutes:GrantAccess' :: GrantAccess -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ValidForInMinutes" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
validForInMinutes,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"InstanceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
instanceId)
          ]
      )

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

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

-- | Contains the response to a @GrantAccess@ request.
--
-- /See:/ 'newGrantAccessResponse' smart constructor.
data GrantAccessResponse = GrantAccessResponse'
  { -- | A @TemporaryCredential@ object that contains the data needed to log in
    -- to the instance by RDP clients, such as the Microsoft Remote Desktop
    -- Connection.
    GrantAccessResponse -> Maybe TemporaryCredential
temporaryCredential :: Prelude.Maybe TemporaryCredential,
    -- | The response's http status code.
    GrantAccessResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GrantAccessResponse -> GrantAccessResponse -> Bool
(GrantAccessResponse -> GrantAccessResponse -> Bool)
-> (GrantAccessResponse -> GrantAccessResponse -> Bool)
-> Eq GrantAccessResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GrantAccessResponse -> GrantAccessResponse -> Bool
$c/= :: GrantAccessResponse -> GrantAccessResponse -> Bool
== :: GrantAccessResponse -> GrantAccessResponse -> Bool
$c== :: GrantAccessResponse -> GrantAccessResponse -> Bool
Prelude.Eq, ReadPrec [GrantAccessResponse]
ReadPrec GrantAccessResponse
Int -> ReadS GrantAccessResponse
ReadS [GrantAccessResponse]
(Int -> ReadS GrantAccessResponse)
-> ReadS [GrantAccessResponse]
-> ReadPrec GrantAccessResponse
-> ReadPrec [GrantAccessResponse]
-> Read GrantAccessResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GrantAccessResponse]
$creadListPrec :: ReadPrec [GrantAccessResponse]
readPrec :: ReadPrec GrantAccessResponse
$creadPrec :: ReadPrec GrantAccessResponse
readList :: ReadS [GrantAccessResponse]
$creadList :: ReadS [GrantAccessResponse]
readsPrec :: Int -> ReadS GrantAccessResponse
$creadsPrec :: Int -> ReadS GrantAccessResponse
Prelude.Read, Int -> GrantAccessResponse -> ShowS
[GrantAccessResponse] -> ShowS
GrantAccessResponse -> String
(Int -> GrantAccessResponse -> ShowS)
-> (GrantAccessResponse -> String)
-> ([GrantAccessResponse] -> ShowS)
-> Show GrantAccessResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GrantAccessResponse] -> ShowS
$cshowList :: [GrantAccessResponse] -> ShowS
show :: GrantAccessResponse -> String
$cshow :: GrantAccessResponse -> String
showsPrec :: Int -> GrantAccessResponse -> ShowS
$cshowsPrec :: Int -> GrantAccessResponse -> ShowS
Prelude.Show, (forall x. GrantAccessResponse -> Rep GrantAccessResponse x)
-> (forall x. Rep GrantAccessResponse x -> GrantAccessResponse)
-> Generic GrantAccessResponse
forall x. Rep GrantAccessResponse x -> GrantAccessResponse
forall x. GrantAccessResponse -> Rep GrantAccessResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GrantAccessResponse x -> GrantAccessResponse
$cfrom :: forall x. GrantAccessResponse -> Rep GrantAccessResponse x
Prelude.Generic)

-- |
-- Create a value of 'GrantAccessResponse' 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:
--
-- 'temporaryCredential', 'grantAccessResponse_temporaryCredential' - A @TemporaryCredential@ object that contains the data needed to log in
-- to the instance by RDP clients, such as the Microsoft Remote Desktop
-- Connection.
--
-- 'httpStatus', 'grantAccessResponse_httpStatus' - The response's http status code.
newGrantAccessResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GrantAccessResponse
newGrantAccessResponse :: Int -> GrantAccessResponse
newGrantAccessResponse Int
pHttpStatus_ =
  GrantAccessResponse' :: Maybe TemporaryCredential -> Int -> GrantAccessResponse
GrantAccessResponse'
    { $sel:temporaryCredential:GrantAccessResponse' :: Maybe TemporaryCredential
temporaryCredential =
        Maybe TemporaryCredential
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GrantAccessResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A @TemporaryCredential@ object that contains the data needed to log in
-- to the instance by RDP clients, such as the Microsoft Remote Desktop
-- Connection.
grantAccessResponse_temporaryCredential :: Lens.Lens' GrantAccessResponse (Prelude.Maybe TemporaryCredential)
grantAccessResponse_temporaryCredential :: (Maybe TemporaryCredential -> f (Maybe TemporaryCredential))
-> GrantAccessResponse -> f GrantAccessResponse
grantAccessResponse_temporaryCredential = (GrantAccessResponse -> Maybe TemporaryCredential)
-> (GrantAccessResponse
    -> Maybe TemporaryCredential -> GrantAccessResponse)
-> Lens
     GrantAccessResponse
     GrantAccessResponse
     (Maybe TemporaryCredential)
     (Maybe TemporaryCredential)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrantAccessResponse' {Maybe TemporaryCredential
temporaryCredential :: Maybe TemporaryCredential
$sel:temporaryCredential:GrantAccessResponse' :: GrantAccessResponse -> Maybe TemporaryCredential
temporaryCredential} -> Maybe TemporaryCredential
temporaryCredential) (\s :: GrantAccessResponse
s@GrantAccessResponse' {} Maybe TemporaryCredential
a -> GrantAccessResponse
s {$sel:temporaryCredential:GrantAccessResponse' :: Maybe TemporaryCredential
temporaryCredential = Maybe TemporaryCredential
a} :: GrantAccessResponse)

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

instance Prelude.NFData GrantAccessResponse