{-# 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.User
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IAM.Types.User where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IAM.Types.AttachedPermissionsBoundary
import Amazonka.IAM.Types.Tag
import qualified Amazonka.Prelude as Prelude

-- | Contains information about an IAM user entity.
--
-- This data type is used as a response element in the following
-- operations:
--
-- -   CreateUser
--
-- -   GetUser
--
-- -   ListUsers
--
-- /See:/ 'newUser' smart constructor.
data User = User'
  { -- | The date and time, in
    -- <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>, when the
    -- user\'s password was last used to sign in to an Amazon Web Services
    -- website. For a list of Amazon Web Services websites that capture a
    -- user\'s last sign-in time, see the
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/credential-reports.html Credential reports>
    -- topic in the /IAM User Guide/. If a password is used more than once in a
    -- five-minute span, only the first use is returned in this field. If the
    -- field is null (no value), then it indicates that they never signed in
    -- with a password. This can be because:
    --
    -- -   The user never had a password.
    --
    -- -   A password exists but has not been used since IAM started tracking
    --     this information on October 20, 2014.
    --
    -- A null value does not mean that the user /never/ had a password. Also,
    -- if the user does not currently have a password but had one in the past,
    -- then this field contains the date and time the most recent password was
    -- used.
    --
    -- This value is returned only in the GetUser and ListUsers operations.
    User -> Maybe ISO8601
passwordLastUsed :: Prelude.Maybe Data.ISO8601,
    -- | The path to the user. For more information about paths, see
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html IAM identifiers>
    -- in the /IAM User Guide/.
    --
    -- The ARN of the policy used to set the permissions boundary for the user.
    User -> Maybe Text
path :: Prelude.Maybe Prelude.Text,
    -- | For more information about permissions boundaries, see
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html Permissions boundaries for IAM identities>
    -- in the /IAM User Guide/.
    User -> Maybe AttachedPermissionsBoundary
permissionsBoundary :: Prelude.Maybe AttachedPermissionsBoundary,
    -- | A list of tags that are associated with the user. For more information
    -- about tagging, see
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/id_tags.html Tagging IAM resources>
    -- in the /IAM User Guide/.
    User -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The friendly name identifying the user.
    User -> Text
userName :: Prelude.Text,
    -- | The stable and unique string identifying the user. For more information
    -- about IDs, see
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html IAM identifiers>
    -- in the /IAM User Guide/.
    User -> Text
userId :: Prelude.Text,
    -- | The Amazon Resource Name (ARN) that identifies the user. For more
    -- information about ARNs and how to use ARNs in policies, see
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html IAM Identifiers>
    -- in the /IAM User Guide/.
    User -> Text
arn :: Prelude.Text,
    -- | The date and time, in
    -- <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>, when the
    -- user was created.
    User -> ISO8601
createDate :: Data.ISO8601
  }
  deriving (User -> User -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: User -> User -> Bool
$c/= :: User -> User -> Bool
== :: User -> User -> Bool
$c== :: User -> User -> Bool
Prelude.Eq, ReadPrec [User]
ReadPrec User
Int -> ReadS User
ReadS [User]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [User]
$creadListPrec :: ReadPrec [User]
readPrec :: ReadPrec User
$creadPrec :: ReadPrec User
readList :: ReadS [User]
$creadList :: ReadS [User]
readsPrec :: Int -> ReadS User
$creadsPrec :: Int -> ReadS User
Prelude.Read, Int -> User -> ShowS
[User] -> ShowS
User -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [User] -> ShowS
$cshowList :: [User] -> ShowS
show :: User -> String
$cshow :: User -> String
showsPrec :: Int -> User -> ShowS
$cshowsPrec :: Int -> User -> ShowS
Prelude.Show, forall x. Rep User x -> User
forall x. User -> Rep User x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep User x -> User
$cfrom :: forall x. User -> Rep User x
Prelude.Generic)

-- |
-- Create a value of 'User' 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:
--
-- 'passwordLastUsed', 'user_passwordLastUsed' - The date and time, in
-- <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>, when the
-- user\'s password was last used to sign in to an Amazon Web Services
-- website. For a list of Amazon Web Services websites that capture a
-- user\'s last sign-in time, see the
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/credential-reports.html Credential reports>
-- topic in the /IAM User Guide/. If a password is used more than once in a
-- five-minute span, only the first use is returned in this field. If the
-- field is null (no value), then it indicates that they never signed in
-- with a password. This can be because:
--
-- -   The user never had a password.
--
-- -   A password exists but has not been used since IAM started tracking
--     this information on October 20, 2014.
--
-- A null value does not mean that the user /never/ had a password. Also,
-- if the user does not currently have a password but had one in the past,
-- then this field contains the date and time the most recent password was
-- used.
--
-- This value is returned only in the GetUser and ListUsers operations.
--
-- 'path', 'user_path' - The path to the user. For more information about paths, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html IAM identifiers>
-- in the /IAM User Guide/.
--
-- The ARN of the policy used to set the permissions boundary for the user.
--
-- 'permissionsBoundary', 'user_permissionsBoundary' - For more information about permissions boundaries, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html Permissions boundaries for IAM identities>
-- in the /IAM User Guide/.
--
-- 'tags', 'user_tags' - A list of tags that are associated with the user. For more information
-- about tagging, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/id_tags.html Tagging IAM resources>
-- in the /IAM User Guide/.
--
-- 'userName', 'user_userName' - The friendly name identifying the user.
--
-- 'userId', 'user_userId' - The stable and unique string identifying the user. For more information
-- about IDs, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html IAM identifiers>
-- in the /IAM User Guide/.
--
-- 'arn', 'user_arn' - The Amazon Resource Name (ARN) that identifies the user. For more
-- information about ARNs and how to use ARNs in policies, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html IAM Identifiers>
-- in the /IAM User Guide/.
--
-- 'createDate', 'user_createDate' - The date and time, in
-- <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>, when the
-- user was created.
newUser ::
  -- | 'userName'
  Prelude.Text ->
  -- | 'userId'
  Prelude.Text ->
  -- | 'arn'
  Prelude.Text ->
  -- | 'createDate'
  Prelude.UTCTime ->
  User
newUser :: Text -> Text -> Text -> UTCTime -> User
newUser Text
pUserName_ Text
pUserId_ Text
pArn_ UTCTime
pCreateDate_ =
  User'
    { $sel:passwordLastUsed:User' :: Maybe ISO8601
passwordLastUsed = forall a. Maybe a
Prelude.Nothing,
      $sel:path:User' :: Maybe Text
path = forall a. Maybe a
Prelude.Nothing,
      $sel:permissionsBoundary:User' :: Maybe AttachedPermissionsBoundary
permissionsBoundary = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:User' :: Maybe [Tag]
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:userName:User' :: Text
userName = Text
pUserName_,
      $sel:userId:User' :: Text
userId = Text
pUserId_,
      $sel:arn:User' :: Text
arn = Text
pArn_,
      $sel:createDate:User' :: ISO8601
createDate = forall (a :: Format). Iso' (Time a) UTCTime
Data._Time forall t b. AReview t b -> b -> t
Lens.# UTCTime
pCreateDate_
    }

-- | The date and time, in
-- <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>, when the
-- user\'s password was last used to sign in to an Amazon Web Services
-- website. For a list of Amazon Web Services websites that capture a
-- user\'s last sign-in time, see the
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/credential-reports.html Credential reports>
-- topic in the /IAM User Guide/. If a password is used more than once in a
-- five-minute span, only the first use is returned in this field. If the
-- field is null (no value), then it indicates that they never signed in
-- with a password. This can be because:
--
-- -   The user never had a password.
--
-- -   A password exists but has not been used since IAM started tracking
--     this information on October 20, 2014.
--
-- A null value does not mean that the user /never/ had a password. Also,
-- if the user does not currently have a password but had one in the past,
-- then this field contains the date and time the most recent password was
-- used.
--
-- This value is returned only in the GetUser and ListUsers operations.
user_passwordLastUsed :: Lens.Lens' User (Prelude.Maybe Prelude.UTCTime)
user_passwordLastUsed :: Lens' User (Maybe UTCTime)
user_passwordLastUsed = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\User' {Maybe ISO8601
passwordLastUsed :: Maybe ISO8601
$sel:passwordLastUsed:User' :: User -> Maybe ISO8601
passwordLastUsed} -> Maybe ISO8601
passwordLastUsed) (\s :: User
s@User' {} Maybe ISO8601
a -> User
s {$sel:passwordLastUsed:User' :: Maybe ISO8601
passwordLastUsed = Maybe ISO8601
a} :: User) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The path to the user. For more information about paths, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html IAM identifiers>
-- in the /IAM User Guide/.
--
-- The ARN of the policy used to set the permissions boundary for the user.
user_path :: Lens.Lens' User (Prelude.Maybe Prelude.Text)
user_path :: Lens' User (Maybe Text)
user_path = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\User' {Maybe Text
path :: Maybe Text
$sel:path:User' :: User -> Maybe Text
path} -> Maybe Text
path) (\s :: User
s@User' {} Maybe Text
a -> User
s {$sel:path:User' :: Maybe Text
path = Maybe Text
a} :: User)

-- | For more information about permissions boundaries, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html Permissions boundaries for IAM identities>
-- in the /IAM User Guide/.
user_permissionsBoundary :: Lens.Lens' User (Prelude.Maybe AttachedPermissionsBoundary)
user_permissionsBoundary :: Lens' User (Maybe AttachedPermissionsBoundary)
user_permissionsBoundary = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\User' {Maybe AttachedPermissionsBoundary
permissionsBoundary :: Maybe AttachedPermissionsBoundary
$sel:permissionsBoundary:User' :: User -> Maybe AttachedPermissionsBoundary
permissionsBoundary} -> Maybe AttachedPermissionsBoundary
permissionsBoundary) (\s :: User
s@User' {} Maybe AttachedPermissionsBoundary
a -> User
s {$sel:permissionsBoundary:User' :: Maybe AttachedPermissionsBoundary
permissionsBoundary = Maybe AttachedPermissionsBoundary
a} :: User)

-- | A list of tags that are associated with the user. For more information
-- about tagging, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/id_tags.html Tagging IAM resources>
-- in the /IAM User Guide/.
user_tags :: Lens.Lens' User (Prelude.Maybe [Tag])
user_tags :: Lens' User (Maybe [Tag])
user_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\User' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:User' :: User -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: User
s@User' {} Maybe [Tag]
a -> User
s {$sel:tags:User' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: User) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The friendly name identifying the user.
user_userName :: Lens.Lens' User Prelude.Text
user_userName :: Lens' User Text
user_userName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\User' {Text
userName :: Text
$sel:userName:User' :: User -> Text
userName} -> Text
userName) (\s :: User
s@User' {} Text
a -> User
s {$sel:userName:User' :: Text
userName = Text
a} :: User)

-- | The stable and unique string identifying the user. For more information
-- about IDs, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html IAM identifiers>
-- in the /IAM User Guide/.
user_userId :: Lens.Lens' User Prelude.Text
user_userId :: Lens' User Text
user_userId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\User' {Text
userId :: Text
$sel:userId:User' :: User -> Text
userId} -> Text
userId) (\s :: User
s@User' {} Text
a -> User
s {$sel:userId:User' :: Text
userId = Text
a} :: User)

-- | The Amazon Resource Name (ARN) that identifies the user. For more
-- information about ARNs and how to use ARNs in policies, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html IAM Identifiers>
-- in the /IAM User Guide/.
user_arn :: Lens.Lens' User Prelude.Text
user_arn :: Lens' User Text
user_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\User' {Text
arn :: Text
$sel:arn:User' :: User -> Text
arn} -> Text
arn) (\s :: User
s@User' {} Text
a -> User
s {$sel:arn:User' :: Text
arn = Text
a} :: User)

-- | The date and time, in
-- <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>, when the
-- user was created.
user_createDate :: Lens.Lens' User Prelude.UTCTime
user_createDate :: Lens' User UTCTime
user_createDate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\User' {ISO8601
createDate :: ISO8601
$sel:createDate:User' :: User -> ISO8601
createDate} -> ISO8601
createDate) (\s :: User
s@User' {} ISO8601
a -> User
s {$sel:createDate:User' :: ISO8601
createDate = ISO8601
a} :: User) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

instance Data.FromXML User where
  parseXML :: [Node] -> Either String User
parseXML [Node]
x =
    Maybe ISO8601
-> Maybe Text
-> Maybe AttachedPermissionsBoundary
-> Maybe [Tag]
-> Text
-> Text
-> Text
-> ISO8601
-> User
User'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"PasswordLastUsed")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Path")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"PermissionsBoundary")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x
                      forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Tags"
                      forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                      forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"member")
                  )
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"UserName")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"UserId")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Arn")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"CreateDate")

instance Prelude.Hashable User where
  hashWithSalt :: Int -> User -> Int
hashWithSalt Int
_salt User' {Maybe [Tag]
Maybe Text
Maybe ISO8601
Maybe AttachedPermissionsBoundary
Text
ISO8601
createDate :: ISO8601
arn :: Text
userId :: Text
userName :: Text
tags :: Maybe [Tag]
permissionsBoundary :: Maybe AttachedPermissionsBoundary
path :: Maybe Text
passwordLastUsed :: Maybe ISO8601
$sel:createDate:User' :: User -> ISO8601
$sel:arn:User' :: User -> Text
$sel:userId:User' :: User -> Text
$sel:userName:User' :: User -> Text
$sel:tags:User' :: User -> Maybe [Tag]
$sel:permissionsBoundary:User' :: User -> Maybe AttachedPermissionsBoundary
$sel:path:User' :: User -> Maybe Text
$sel:passwordLastUsed:User' :: User -> Maybe ISO8601
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ISO8601
passwordLastUsed
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
path
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AttachedPermissionsBoundary
permissionsBoundary
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Tag]
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
userName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
userId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
arn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ISO8601
createDate

instance Prelude.NFData User where
  rnf :: User -> ()
rnf User' {Maybe [Tag]
Maybe Text
Maybe ISO8601
Maybe AttachedPermissionsBoundary
Text
ISO8601
createDate :: ISO8601
arn :: Text
userId :: Text
userName :: Text
tags :: Maybe [Tag]
permissionsBoundary :: Maybe AttachedPermissionsBoundary
path :: Maybe Text
passwordLastUsed :: Maybe ISO8601
$sel:createDate:User' :: User -> ISO8601
$sel:arn:User' :: User -> Text
$sel:userId:User' :: User -> Text
$sel:userName:User' :: User -> Text
$sel:tags:User' :: User -> Maybe [Tag]
$sel:permissionsBoundary:User' :: User -> Maybe AttachedPermissionsBoundary
$sel:path:User' :: User -> Maybe Text
$sel:passwordLastUsed:User' :: User -> Maybe ISO8601
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ISO8601
passwordLastUsed
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
path
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe AttachedPermissionsBoundary
permissionsBoundary
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Tag]
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
userName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
userId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
arn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ISO8601
createDate