{-# 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.EntityDetails
-- 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.EntityDetails where

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

-- | An object that contains details about when the IAM entities (users or
-- roles) were last used in an attempt to access the specified Amazon Web
-- Services service.
--
-- This data type is a response element in the
-- GetServiceLastAccessedDetailsWithEntities operation.
--
-- /See:/ 'newEntityDetails' smart constructor.
data EntityDetails = EntityDetails'
  { -- | The date and time,
    -- in <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>, when the
    -- authenticated entity last attempted to access Amazon Web Services.
    -- Amazon Web Services does not report unauthenticated requests.
    --
    -- This field is null if no IAM entities attempted to access the service
    -- within the
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_access-advisor.html#service-last-accessed-reporting-period reporting period>.
    EntityDetails -> Maybe ISO8601
lastAuthenticated :: Prelude.Maybe Core.ISO8601,
    -- | The @EntityInfo@ object that contains details about the entity (user or
    -- role).
    EntityDetails -> EntityInfo
entityInfo :: EntityInfo
  }
  deriving (EntityDetails -> EntityDetails -> Bool
(EntityDetails -> EntityDetails -> Bool)
-> (EntityDetails -> EntityDetails -> Bool) -> Eq EntityDetails
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EntityDetails -> EntityDetails -> Bool
$c/= :: EntityDetails -> EntityDetails -> Bool
== :: EntityDetails -> EntityDetails -> Bool
$c== :: EntityDetails -> EntityDetails -> Bool
Prelude.Eq, ReadPrec [EntityDetails]
ReadPrec EntityDetails
Int -> ReadS EntityDetails
ReadS [EntityDetails]
(Int -> ReadS EntityDetails)
-> ReadS [EntityDetails]
-> ReadPrec EntityDetails
-> ReadPrec [EntityDetails]
-> Read EntityDetails
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EntityDetails]
$creadListPrec :: ReadPrec [EntityDetails]
readPrec :: ReadPrec EntityDetails
$creadPrec :: ReadPrec EntityDetails
readList :: ReadS [EntityDetails]
$creadList :: ReadS [EntityDetails]
readsPrec :: Int -> ReadS EntityDetails
$creadsPrec :: Int -> ReadS EntityDetails
Prelude.Read, Int -> EntityDetails -> ShowS
[EntityDetails] -> ShowS
EntityDetails -> String
(Int -> EntityDetails -> ShowS)
-> (EntityDetails -> String)
-> ([EntityDetails] -> ShowS)
-> Show EntityDetails
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EntityDetails] -> ShowS
$cshowList :: [EntityDetails] -> ShowS
show :: EntityDetails -> String
$cshow :: EntityDetails -> String
showsPrec :: Int -> EntityDetails -> ShowS
$cshowsPrec :: Int -> EntityDetails -> ShowS
Prelude.Show, (forall x. EntityDetails -> Rep EntityDetails x)
-> (forall x. Rep EntityDetails x -> EntityDetails)
-> Generic EntityDetails
forall x. Rep EntityDetails x -> EntityDetails
forall x. EntityDetails -> Rep EntityDetails x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EntityDetails x -> EntityDetails
$cfrom :: forall x. EntityDetails -> Rep EntityDetails x
Prelude.Generic)

-- |
-- Create a value of 'EntityDetails' 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:
--
-- 'lastAuthenticated', 'entityDetails_lastAuthenticated' - The date and time,
-- in <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>, when the
-- authenticated entity last attempted to access Amazon Web Services.
-- Amazon Web Services does not report unauthenticated requests.
--
-- This field is null if no IAM entities attempted to access the service
-- within the
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_access-advisor.html#service-last-accessed-reporting-period reporting period>.
--
-- 'entityInfo', 'entityDetails_entityInfo' - The @EntityInfo@ object that contains details about the entity (user or
-- role).
newEntityDetails ::
  -- | 'entityInfo'
  EntityInfo ->
  EntityDetails
newEntityDetails :: EntityInfo -> EntityDetails
newEntityDetails EntityInfo
pEntityInfo_ =
  EntityDetails' :: Maybe ISO8601 -> EntityInfo -> EntityDetails
EntityDetails'
    { $sel:lastAuthenticated:EntityDetails' :: Maybe ISO8601
lastAuthenticated = Maybe ISO8601
forall a. Maybe a
Prelude.Nothing,
      $sel:entityInfo:EntityDetails' :: EntityInfo
entityInfo = EntityInfo
pEntityInfo_
    }

-- | The date and time,
-- in <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>, when the
-- authenticated entity last attempted to access Amazon Web Services.
-- Amazon Web Services does not report unauthenticated requests.
--
-- This field is null if no IAM entities attempted to access the service
-- within the
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_access-advisor.html#service-last-accessed-reporting-period reporting period>.
entityDetails_lastAuthenticated :: Lens.Lens' EntityDetails (Prelude.Maybe Prelude.UTCTime)
entityDetails_lastAuthenticated :: (Maybe UTCTime -> f (Maybe UTCTime))
-> EntityDetails -> f EntityDetails
entityDetails_lastAuthenticated = (EntityDetails -> Maybe ISO8601)
-> (EntityDetails -> Maybe ISO8601 -> EntityDetails)
-> Lens EntityDetails EntityDetails (Maybe ISO8601) (Maybe ISO8601)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EntityDetails' {Maybe ISO8601
lastAuthenticated :: Maybe ISO8601
$sel:lastAuthenticated:EntityDetails' :: EntityDetails -> Maybe ISO8601
lastAuthenticated} -> Maybe ISO8601
lastAuthenticated) (\s :: EntityDetails
s@EntityDetails' {} Maybe ISO8601
a -> EntityDetails
s {$sel:lastAuthenticated:EntityDetails' :: Maybe ISO8601
lastAuthenticated = Maybe ISO8601
a} :: EntityDetails) ((Maybe ISO8601 -> f (Maybe ISO8601))
 -> EntityDetails -> f EntityDetails)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe ISO8601 -> f (Maybe ISO8601))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> EntityDetails
-> f EntityDetails
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 @EntityInfo@ object that contains details about the entity (user or
-- role).
entityDetails_entityInfo :: Lens.Lens' EntityDetails EntityInfo
entityDetails_entityInfo :: (EntityInfo -> f EntityInfo) -> EntityDetails -> f EntityDetails
entityDetails_entityInfo = (EntityDetails -> EntityInfo)
-> (EntityDetails -> EntityInfo -> EntityDetails)
-> Lens EntityDetails EntityDetails EntityInfo EntityInfo
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EntityDetails' {EntityInfo
entityInfo :: EntityInfo
$sel:entityInfo:EntityDetails' :: EntityDetails -> EntityInfo
entityInfo} -> EntityInfo
entityInfo) (\s :: EntityDetails
s@EntityDetails' {} EntityInfo
a -> EntityDetails
s {$sel:entityInfo:EntityDetails' :: EntityInfo
entityInfo = EntityInfo
a} :: EntityDetails)

instance Core.FromXML EntityDetails where
  parseXML :: [Node] -> Either String EntityDetails
parseXML [Node]
x =
    Maybe ISO8601 -> EntityInfo -> EntityDetails
EntityDetails'
      (Maybe ISO8601 -> EntityInfo -> EntityDetails)
-> Either String (Maybe ISO8601)
-> Either String (EntityInfo -> EntityDetails)
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
"LastAuthenticated")
      Either String (EntityInfo -> EntityDetails)
-> Either String EntityInfo -> Either String EntityDetails
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String EntityInfo
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"EntityInfo")

instance Prelude.Hashable EntityDetails

instance Prelude.NFData EntityDetails