{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.TemporaryCredential
-- 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)
module Amazonka.OpsWorks.Types.TemporaryCredential where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains the data needed by RDP clients such as the Microsoft Remote
-- Desktop Connection to log in to the instance.
--
-- /See:/ 'newTemporaryCredential' smart constructor.
data TemporaryCredential = TemporaryCredential'
  { -- | The instance\'s AWS OpsWorks Stacks ID.
    TemporaryCredential -> Maybe Text
instanceId :: Prelude.Maybe Prelude.Text,
    -- | The user name.
    TemporaryCredential -> Maybe Text
username :: Prelude.Maybe Prelude.Text,
    -- | The password.
    TemporaryCredential -> Maybe Text
password :: Prelude.Maybe Prelude.Text,
    -- | 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 they are logged in at the time, they
    -- will be automatically logged out.
    TemporaryCredential -> Maybe Int
validForInMinutes :: Prelude.Maybe Prelude.Int
  }
  deriving (TemporaryCredential -> TemporaryCredential -> Bool
(TemporaryCredential -> TemporaryCredential -> Bool)
-> (TemporaryCredential -> TemporaryCredential -> Bool)
-> Eq TemporaryCredential
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TemporaryCredential -> TemporaryCredential -> Bool
$c/= :: TemporaryCredential -> TemporaryCredential -> Bool
== :: TemporaryCredential -> TemporaryCredential -> Bool
$c== :: TemporaryCredential -> TemporaryCredential -> Bool
Prelude.Eq, ReadPrec [TemporaryCredential]
ReadPrec TemporaryCredential
Int -> ReadS TemporaryCredential
ReadS [TemporaryCredential]
(Int -> ReadS TemporaryCredential)
-> ReadS [TemporaryCredential]
-> ReadPrec TemporaryCredential
-> ReadPrec [TemporaryCredential]
-> Read TemporaryCredential
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TemporaryCredential]
$creadListPrec :: ReadPrec [TemporaryCredential]
readPrec :: ReadPrec TemporaryCredential
$creadPrec :: ReadPrec TemporaryCredential
readList :: ReadS [TemporaryCredential]
$creadList :: ReadS [TemporaryCredential]
readsPrec :: Int -> ReadS TemporaryCredential
$creadsPrec :: Int -> ReadS TemporaryCredential
Prelude.Read, Int -> TemporaryCredential -> ShowS
[TemporaryCredential] -> ShowS
TemporaryCredential -> String
(Int -> TemporaryCredential -> ShowS)
-> (TemporaryCredential -> String)
-> ([TemporaryCredential] -> ShowS)
-> Show TemporaryCredential
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TemporaryCredential] -> ShowS
$cshowList :: [TemporaryCredential] -> ShowS
show :: TemporaryCredential -> String
$cshow :: TemporaryCredential -> String
showsPrec :: Int -> TemporaryCredential -> ShowS
$cshowsPrec :: Int -> TemporaryCredential -> ShowS
Prelude.Show, (forall x. TemporaryCredential -> Rep TemporaryCredential x)
-> (forall x. Rep TemporaryCredential x -> TemporaryCredential)
-> Generic TemporaryCredential
forall x. Rep TemporaryCredential x -> TemporaryCredential
forall x. TemporaryCredential -> Rep TemporaryCredential x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TemporaryCredential x -> TemporaryCredential
$cfrom :: forall x. TemporaryCredential -> Rep TemporaryCredential x
Prelude.Generic)

-- |
-- Create a value of 'TemporaryCredential' 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:
--
-- 'instanceId', 'temporaryCredential_instanceId' - The instance\'s AWS OpsWorks Stacks ID.
--
-- 'username', 'temporaryCredential_username' - The user name.
--
-- 'password', 'temporaryCredential_password' - The password.
--
-- 'validForInMinutes', 'temporaryCredential_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 they are logged in at the time, they
-- will be automatically logged out.
newTemporaryCredential ::
  TemporaryCredential
newTemporaryCredential :: TemporaryCredential
newTemporaryCredential =
  TemporaryCredential' :: Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Int -> TemporaryCredential
TemporaryCredential'
    { $sel:instanceId:TemporaryCredential' :: Maybe Text
instanceId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:username:TemporaryCredential' :: Maybe Text
username = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:password:TemporaryCredential' :: Maybe Text
password = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:validForInMinutes:TemporaryCredential' :: Maybe Int
validForInMinutes = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

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

-- | The user name.
temporaryCredential_username :: Lens.Lens' TemporaryCredential (Prelude.Maybe Prelude.Text)
temporaryCredential_username :: (Maybe Text -> f (Maybe Text))
-> TemporaryCredential -> f TemporaryCredential
temporaryCredential_username = (TemporaryCredential -> Maybe Text)
-> (TemporaryCredential -> Maybe Text -> TemporaryCredential)
-> Lens
     TemporaryCredential TemporaryCredential (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TemporaryCredential' {Maybe Text
username :: Maybe Text
$sel:username:TemporaryCredential' :: TemporaryCredential -> Maybe Text
username} -> Maybe Text
username) (\s :: TemporaryCredential
s@TemporaryCredential' {} Maybe Text
a -> TemporaryCredential
s {$sel:username:TemporaryCredential' :: Maybe Text
username = Maybe Text
a} :: TemporaryCredential)

-- | The password.
temporaryCredential_password :: Lens.Lens' TemporaryCredential (Prelude.Maybe Prelude.Text)
temporaryCredential_password :: (Maybe Text -> f (Maybe Text))
-> TemporaryCredential -> f TemporaryCredential
temporaryCredential_password = (TemporaryCredential -> Maybe Text)
-> (TemporaryCredential -> Maybe Text -> TemporaryCredential)
-> Lens
     TemporaryCredential TemporaryCredential (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TemporaryCredential' {Maybe Text
password :: Maybe Text
$sel:password:TemporaryCredential' :: TemporaryCredential -> Maybe Text
password} -> Maybe Text
password) (\s :: TemporaryCredential
s@TemporaryCredential' {} Maybe Text
a -> TemporaryCredential
s {$sel:password:TemporaryCredential' :: Maybe Text
password = Maybe Text
a} :: TemporaryCredential)

-- | 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 they are logged in at the time, they
-- will be automatically logged out.
temporaryCredential_validForInMinutes :: Lens.Lens' TemporaryCredential (Prelude.Maybe Prelude.Int)
temporaryCredential_validForInMinutes :: (Maybe Int -> f (Maybe Int))
-> TemporaryCredential -> f TemporaryCredential
temporaryCredential_validForInMinutes = (TemporaryCredential -> Maybe Int)
-> (TemporaryCredential -> Maybe Int -> TemporaryCredential)
-> Lens
     TemporaryCredential TemporaryCredential (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TemporaryCredential' {Maybe Int
validForInMinutes :: Maybe Int
$sel:validForInMinutes:TemporaryCredential' :: TemporaryCredential -> Maybe Int
validForInMinutes} -> Maybe Int
validForInMinutes) (\s :: TemporaryCredential
s@TemporaryCredential' {} Maybe Int
a -> TemporaryCredential
s {$sel:validForInMinutes:TemporaryCredential' :: Maybe Int
validForInMinutes = Maybe Int
a} :: TemporaryCredential)

instance Core.FromJSON TemporaryCredential where
  parseJSON :: Value -> Parser TemporaryCredential
parseJSON =
    String
-> (Object -> Parser TemporaryCredential)
-> Value
-> Parser TemporaryCredential
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TemporaryCredential"
      ( \Object
x ->
          Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Int -> TemporaryCredential
TemporaryCredential'
            (Maybe Text
 -> Maybe Text -> Maybe Text -> Maybe Int -> TemporaryCredential)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text -> Maybe Text -> Maybe Int -> TemporaryCredential)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"InstanceId")
            Parser
  (Maybe Text -> Maybe Text -> Maybe Int -> TemporaryCredential)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Int -> TemporaryCredential)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Username")
            Parser (Maybe Text -> Maybe Int -> TemporaryCredential)
-> Parser (Maybe Text) -> Parser (Maybe Int -> TemporaryCredential)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Password")
            Parser (Maybe Int -> TemporaryCredential)
-> Parser (Maybe Int) -> Parser TemporaryCredential
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ValidForInMinutes")
      )

instance Prelude.Hashable TemporaryCredential

instance Prelude.NFData TemporaryCredential