{-# 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.IAM.Types.AccessKeyInfo
-- 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.IAM.Types.AccessKeyInfo where

import qualified Amazonka.Core as Core
import Amazonka.IAM.Types.StatusType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information about an Amazon Web Services access key.
--
-- This data type is used as a response element in the CreateAccessKey and
-- ListAccessKeys operations.
--
-- The @SecretAccessKey@ value is returned only in response to
-- CreateAccessKey. You can get a secret access key only when you first
-- create an access key; you cannot recover the secret access key later. If
-- you lose a secret access key, you must create a new access key.
--
-- /See:/ 'newAccessKeyInfo' smart constructor.
data AccessKeyInfo = AccessKeyInfo'
  { -- | The date when the access key was created.
    AccessKeyInfo -> Maybe ISO8601
createDate :: Prelude.Maybe Core.ISO8601,
    -- | The name of the IAM user that the access key is associated with.
    AccessKeyInfo -> Text
userName :: Prelude.Text,
    -- | The ID for this access key.
    AccessKeyInfo -> AccessKey
accessKeyId :: Core.AccessKey,
    -- | The status of the access key. @Active@ means that the key is valid for
    -- API calls, while @Inactive@ means it is not.
    AccessKeyInfo -> StatusType
status :: StatusType,
    -- | The secret key used to sign requests.
    AccessKeyInfo -> Sensitive Text
secretAccessKey :: Core.Sensitive Prelude.Text
  }
  deriving (AccessKeyInfo -> AccessKeyInfo -> Bool
(AccessKeyInfo -> AccessKeyInfo -> Bool)
-> (AccessKeyInfo -> AccessKeyInfo -> Bool) -> Eq AccessKeyInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AccessKeyInfo -> AccessKeyInfo -> Bool
$c/= :: AccessKeyInfo -> AccessKeyInfo -> Bool
== :: AccessKeyInfo -> AccessKeyInfo -> Bool
$c== :: AccessKeyInfo -> AccessKeyInfo -> Bool
Prelude.Eq, Int -> AccessKeyInfo -> ShowS
[AccessKeyInfo] -> ShowS
AccessKeyInfo -> String
(Int -> AccessKeyInfo -> ShowS)
-> (AccessKeyInfo -> String)
-> ([AccessKeyInfo] -> ShowS)
-> Show AccessKeyInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AccessKeyInfo] -> ShowS
$cshowList :: [AccessKeyInfo] -> ShowS
show :: AccessKeyInfo -> String
$cshow :: AccessKeyInfo -> String
showsPrec :: Int -> AccessKeyInfo -> ShowS
$cshowsPrec :: Int -> AccessKeyInfo -> ShowS
Prelude.Show, (forall x. AccessKeyInfo -> Rep AccessKeyInfo x)
-> (forall x. Rep AccessKeyInfo x -> AccessKeyInfo)
-> Generic AccessKeyInfo
forall x. Rep AccessKeyInfo x -> AccessKeyInfo
forall x. AccessKeyInfo -> Rep AccessKeyInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AccessKeyInfo x -> AccessKeyInfo
$cfrom :: forall x. AccessKeyInfo -> Rep AccessKeyInfo x
Prelude.Generic)

-- |
-- Create a value of 'AccessKeyInfo' 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:
--
-- 'createDate', 'accessKeyInfo_createDate' - The date when the access key was created.
--
-- 'userName', 'accessKeyInfo_userName' - The name of the IAM user that the access key is associated with.
--
-- 'accessKeyId', 'accessKeyInfo_accessKeyId' - The ID for this access key.
--
-- 'status', 'accessKeyInfo_status' - The status of the access key. @Active@ means that the key is valid for
-- API calls, while @Inactive@ means it is not.
--
-- 'secretAccessKey', 'accessKeyInfo_secretAccessKey' - The secret key used to sign requests.
newAccessKeyInfo ::
  -- | 'userName'
  Prelude.Text ->
  -- | 'accessKeyId'
  Core.AccessKey ->
  -- | 'status'
  StatusType ->
  -- | 'secretAccessKey'
  Prelude.Text ->
  AccessKeyInfo
newAccessKeyInfo :: Text -> AccessKey -> StatusType -> Text -> AccessKeyInfo
newAccessKeyInfo
  Text
pUserName_
  AccessKey
pAccessKeyId_
  StatusType
pStatus_
  Text
pSecretAccessKey_ =
    AccessKeyInfo' :: Maybe ISO8601
-> Text
-> AccessKey
-> StatusType
-> Sensitive Text
-> AccessKeyInfo
AccessKeyInfo'
      { $sel:createDate:AccessKeyInfo' :: Maybe ISO8601
createDate = Maybe ISO8601
forall a. Maybe a
Prelude.Nothing,
        $sel:userName:AccessKeyInfo' :: Text
userName = Text
pUserName_,
        $sel:accessKeyId:AccessKeyInfo' :: AccessKey
accessKeyId = AccessKey
pAccessKeyId_,
        $sel:status:AccessKeyInfo' :: StatusType
status = StatusType
pStatus_,
        $sel:secretAccessKey:AccessKeyInfo' :: Sensitive Text
secretAccessKey =
          Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
forall t b. AReview t b -> b -> t
Lens.# Text
pSecretAccessKey_
      }

-- | The date when the access key was created.
accessKeyInfo_createDate :: Lens.Lens' AccessKeyInfo (Prelude.Maybe Prelude.UTCTime)
accessKeyInfo_createDate :: (Maybe UTCTime -> f (Maybe UTCTime))
-> AccessKeyInfo -> f AccessKeyInfo
accessKeyInfo_createDate = (AccessKeyInfo -> Maybe ISO8601)
-> (AccessKeyInfo -> Maybe ISO8601 -> AccessKeyInfo)
-> Lens AccessKeyInfo AccessKeyInfo (Maybe ISO8601) (Maybe ISO8601)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessKeyInfo' {Maybe ISO8601
createDate :: Maybe ISO8601
$sel:createDate:AccessKeyInfo' :: AccessKeyInfo -> Maybe ISO8601
createDate} -> Maybe ISO8601
createDate) (\s :: AccessKeyInfo
s@AccessKeyInfo' {} Maybe ISO8601
a -> AccessKeyInfo
s {$sel:createDate:AccessKeyInfo' :: Maybe ISO8601
createDate = Maybe ISO8601
a} :: AccessKeyInfo) ((Maybe ISO8601 -> f (Maybe ISO8601))
 -> AccessKeyInfo -> f AccessKeyInfo)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe ISO8601 -> f (Maybe ISO8601))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> AccessKeyInfo
-> f AccessKeyInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso ISO8601 ISO8601 UTCTime UTCTime
-> Iso
     (Maybe ISO8601) (Maybe ISO8601) (Maybe UTCTime) (Maybe UTCTime)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso ISO8601 ISO8601 UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The name of the IAM user that the access key is associated with.
accessKeyInfo_userName :: Lens.Lens' AccessKeyInfo Prelude.Text
accessKeyInfo_userName :: (Text -> f Text) -> AccessKeyInfo -> f AccessKeyInfo
accessKeyInfo_userName = (AccessKeyInfo -> Text)
-> (AccessKeyInfo -> Text -> AccessKeyInfo)
-> Lens AccessKeyInfo AccessKeyInfo Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessKeyInfo' {Text
userName :: Text
$sel:userName:AccessKeyInfo' :: AccessKeyInfo -> Text
userName} -> Text
userName) (\s :: AccessKeyInfo
s@AccessKeyInfo' {} Text
a -> AccessKeyInfo
s {$sel:userName:AccessKeyInfo' :: Text
userName = Text
a} :: AccessKeyInfo)

-- | The ID for this access key.
accessKeyInfo_accessKeyId :: Lens.Lens' AccessKeyInfo Core.AccessKey
accessKeyInfo_accessKeyId :: (AccessKey -> f AccessKey) -> AccessKeyInfo -> f AccessKeyInfo
accessKeyInfo_accessKeyId = (AccessKeyInfo -> AccessKey)
-> (AccessKeyInfo -> AccessKey -> AccessKeyInfo)
-> Lens AccessKeyInfo AccessKeyInfo AccessKey AccessKey
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessKeyInfo' {AccessKey
accessKeyId :: AccessKey
$sel:accessKeyId:AccessKeyInfo' :: AccessKeyInfo -> AccessKey
accessKeyId} -> AccessKey
accessKeyId) (\s :: AccessKeyInfo
s@AccessKeyInfo' {} AccessKey
a -> AccessKeyInfo
s {$sel:accessKeyId:AccessKeyInfo' :: AccessKey
accessKeyId = AccessKey
a} :: AccessKeyInfo)

-- | The status of the access key. @Active@ means that the key is valid for
-- API calls, while @Inactive@ means it is not.
accessKeyInfo_status :: Lens.Lens' AccessKeyInfo StatusType
accessKeyInfo_status :: (StatusType -> f StatusType) -> AccessKeyInfo -> f AccessKeyInfo
accessKeyInfo_status = (AccessKeyInfo -> StatusType)
-> (AccessKeyInfo -> StatusType -> AccessKeyInfo)
-> Lens AccessKeyInfo AccessKeyInfo StatusType StatusType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessKeyInfo' {StatusType
status :: StatusType
$sel:status:AccessKeyInfo' :: AccessKeyInfo -> StatusType
status} -> StatusType
status) (\s :: AccessKeyInfo
s@AccessKeyInfo' {} StatusType
a -> AccessKeyInfo
s {$sel:status:AccessKeyInfo' :: StatusType
status = StatusType
a} :: AccessKeyInfo)

-- | The secret key used to sign requests.
accessKeyInfo_secretAccessKey :: Lens.Lens' AccessKeyInfo Prelude.Text
accessKeyInfo_secretAccessKey :: (Text -> f Text) -> AccessKeyInfo -> f AccessKeyInfo
accessKeyInfo_secretAccessKey = (AccessKeyInfo -> Sensitive Text)
-> (AccessKeyInfo -> Sensitive Text -> AccessKeyInfo)
-> Lens
     AccessKeyInfo AccessKeyInfo (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessKeyInfo' {Sensitive Text
secretAccessKey :: Sensitive Text
$sel:secretAccessKey:AccessKeyInfo' :: AccessKeyInfo -> Sensitive Text
secretAccessKey} -> Sensitive Text
secretAccessKey) (\s :: AccessKeyInfo
s@AccessKeyInfo' {} Sensitive Text
a -> AccessKeyInfo
s {$sel:secretAccessKey:AccessKeyInfo' :: Sensitive Text
secretAccessKey = Sensitive Text
a} :: AccessKeyInfo) ((Sensitive Text -> f (Sensitive Text))
 -> AccessKeyInfo -> f AccessKeyInfo)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> AccessKeyInfo
-> f AccessKeyInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

instance Core.FromXML AccessKeyInfo where
  parseXML :: [Node] -> Either String AccessKeyInfo
parseXML [Node]
x =
    Maybe ISO8601
-> Text
-> AccessKey
-> StatusType
-> Sensitive Text
-> AccessKeyInfo
AccessKeyInfo'
      (Maybe ISO8601
 -> Text
 -> AccessKey
 -> StatusType
 -> Sensitive Text
 -> AccessKeyInfo)
-> Either String (Maybe ISO8601)
-> Either
     String
     (Text
      -> AccessKey -> StatusType -> Sensitive Text -> AccessKeyInfo)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe ISO8601)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"CreateDate")
      Either
  String
  (Text
   -> AccessKey -> StatusType -> Sensitive Text -> AccessKeyInfo)
-> Either String Text
-> Either
     String (AccessKey -> StatusType -> Sensitive Text -> AccessKeyInfo)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"UserName")
      Either
  String (AccessKey -> StatusType -> Sensitive Text -> AccessKeyInfo)
-> Either String AccessKey
-> Either String (StatusType -> Sensitive Text -> AccessKeyInfo)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String AccessKey
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"AccessKeyId")
      Either String (StatusType -> Sensitive Text -> AccessKeyInfo)
-> Either String StatusType
-> Either String (Sensitive Text -> AccessKeyInfo)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String StatusType
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Status")
      Either String (Sensitive Text -> AccessKeyInfo)
-> Either String (Sensitive Text) -> Either String AccessKeyInfo
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Sensitive Text)
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"SecretAccessKey")

instance Prelude.Hashable AccessKeyInfo

instance Prelude.NFData AccessKeyInfo