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

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

-- | Contains information about the last time that an IAM role was used. This
-- includes the date and time and the Region in which the role was last
-- used. Activity is only reported for the trailing 400 days. This period
-- can be shorter if your Region began supporting these features within the
-- last year. The role might have been used more than 400 days ago. For
-- more information, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_access-advisor.html#access-advisor_tracking-period Regions where data is tracked>
-- in the /IAM User Guide/.
--
-- This data type is returned as a response element in the GetRole and
-- GetAccountAuthorizationDetails operations.
--
-- /See:/ 'newRoleLastUsed' smart constructor.
data RoleLastUsed = RoleLastUsed'
  { -- | The date and time,
    -- in <http://www.iso.org/iso/iso8601 ISO 8601 date-time format> that the
    -- role was last used.
    --
    -- This field is null if the role has not been used within the IAM tracking
    -- period. For more information about the tracking period, see
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_access-advisor.html#access-advisor_tracking-period Regions where data is tracked>
    -- in the /IAM User Guide/.
    RoleLastUsed -> Maybe ISO8601
lastUsedDate :: Prelude.Maybe Core.ISO8601,
    -- | The name of the Amazon Web Services Region in which the role was last
    -- used.
    RoleLastUsed -> Maybe Text
region :: Prelude.Maybe Prelude.Text
  }
  deriving (RoleLastUsed -> RoleLastUsed -> Bool
(RoleLastUsed -> RoleLastUsed -> Bool)
-> (RoleLastUsed -> RoleLastUsed -> Bool) -> Eq RoleLastUsed
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RoleLastUsed -> RoleLastUsed -> Bool
$c/= :: RoleLastUsed -> RoleLastUsed -> Bool
== :: RoleLastUsed -> RoleLastUsed -> Bool
$c== :: RoleLastUsed -> RoleLastUsed -> Bool
Prelude.Eq, ReadPrec [RoleLastUsed]
ReadPrec RoleLastUsed
Int -> ReadS RoleLastUsed
ReadS [RoleLastUsed]
(Int -> ReadS RoleLastUsed)
-> ReadS [RoleLastUsed]
-> ReadPrec RoleLastUsed
-> ReadPrec [RoleLastUsed]
-> Read RoleLastUsed
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RoleLastUsed]
$creadListPrec :: ReadPrec [RoleLastUsed]
readPrec :: ReadPrec RoleLastUsed
$creadPrec :: ReadPrec RoleLastUsed
readList :: ReadS [RoleLastUsed]
$creadList :: ReadS [RoleLastUsed]
readsPrec :: Int -> ReadS RoleLastUsed
$creadsPrec :: Int -> ReadS RoleLastUsed
Prelude.Read, Int -> RoleLastUsed -> ShowS
[RoleLastUsed] -> ShowS
RoleLastUsed -> String
(Int -> RoleLastUsed -> ShowS)
-> (RoleLastUsed -> String)
-> ([RoleLastUsed] -> ShowS)
-> Show RoleLastUsed
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RoleLastUsed] -> ShowS
$cshowList :: [RoleLastUsed] -> ShowS
show :: RoleLastUsed -> String
$cshow :: RoleLastUsed -> String
showsPrec :: Int -> RoleLastUsed -> ShowS
$cshowsPrec :: Int -> RoleLastUsed -> ShowS
Prelude.Show, (forall x. RoleLastUsed -> Rep RoleLastUsed x)
-> (forall x. Rep RoleLastUsed x -> RoleLastUsed)
-> Generic RoleLastUsed
forall x. Rep RoleLastUsed x -> RoleLastUsed
forall x. RoleLastUsed -> Rep RoleLastUsed x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RoleLastUsed x -> RoleLastUsed
$cfrom :: forall x. RoleLastUsed -> Rep RoleLastUsed x
Prelude.Generic)

-- |
-- Create a value of 'RoleLastUsed' 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:
--
-- 'lastUsedDate', 'roleLastUsed_lastUsedDate' - The date and time,
-- in <http://www.iso.org/iso/iso8601 ISO 8601 date-time format> that the
-- role was last used.
--
-- This field is null if the role has not been used within the IAM tracking
-- period. For more information about the tracking period, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_access-advisor.html#access-advisor_tracking-period Regions where data is tracked>
-- in the /IAM User Guide/.
--
-- 'region', 'roleLastUsed_region' - The name of the Amazon Web Services Region in which the role was last
-- used.
newRoleLastUsed ::
  RoleLastUsed
newRoleLastUsed :: RoleLastUsed
newRoleLastUsed =
  RoleLastUsed' :: Maybe ISO8601 -> Maybe Text -> RoleLastUsed
RoleLastUsed'
    { $sel:lastUsedDate:RoleLastUsed' :: Maybe ISO8601
lastUsedDate = Maybe ISO8601
forall a. Maybe a
Prelude.Nothing,
      $sel:region:RoleLastUsed' :: Maybe Text
region = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The date and time,
-- in <http://www.iso.org/iso/iso8601 ISO 8601 date-time format> that the
-- role was last used.
--
-- This field is null if the role has not been used within the IAM tracking
-- period. For more information about the tracking period, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_access-advisor.html#access-advisor_tracking-period Regions where data is tracked>
-- in the /IAM User Guide/.
roleLastUsed_lastUsedDate :: Lens.Lens' RoleLastUsed (Prelude.Maybe Prelude.UTCTime)
roleLastUsed_lastUsedDate :: (Maybe UTCTime -> f (Maybe UTCTime))
-> RoleLastUsed -> f RoleLastUsed
roleLastUsed_lastUsedDate = (RoleLastUsed -> Maybe ISO8601)
-> (RoleLastUsed -> Maybe ISO8601 -> RoleLastUsed)
-> Lens RoleLastUsed RoleLastUsed (Maybe ISO8601) (Maybe ISO8601)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RoleLastUsed' {Maybe ISO8601
lastUsedDate :: Maybe ISO8601
$sel:lastUsedDate:RoleLastUsed' :: RoleLastUsed -> Maybe ISO8601
lastUsedDate} -> Maybe ISO8601
lastUsedDate) (\s :: RoleLastUsed
s@RoleLastUsed' {} Maybe ISO8601
a -> RoleLastUsed
s {$sel:lastUsedDate:RoleLastUsed' :: Maybe ISO8601
lastUsedDate = Maybe ISO8601
a} :: RoleLastUsed) ((Maybe ISO8601 -> f (Maybe ISO8601))
 -> RoleLastUsed -> f RoleLastUsed)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe ISO8601 -> f (Maybe ISO8601))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> RoleLastUsed
-> f RoleLastUsed
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 Amazon Web Services Region in which the role was last
-- used.
roleLastUsed_region :: Lens.Lens' RoleLastUsed (Prelude.Maybe Prelude.Text)
roleLastUsed_region :: (Maybe Text -> f (Maybe Text)) -> RoleLastUsed -> f RoleLastUsed
roleLastUsed_region = (RoleLastUsed -> Maybe Text)
-> (RoleLastUsed -> Maybe Text -> RoleLastUsed)
-> Lens RoleLastUsed RoleLastUsed (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RoleLastUsed' {Maybe Text
region :: Maybe Text
$sel:region:RoleLastUsed' :: RoleLastUsed -> Maybe Text
region} -> Maybe Text
region) (\s :: RoleLastUsed
s@RoleLastUsed' {} Maybe Text
a -> RoleLastUsed
s {$sel:region:RoleLastUsed' :: Maybe Text
region = Maybe Text
a} :: RoleLastUsed)

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

instance Prelude.Hashable RoleLastUsed

instance Prelude.NFData RoleLastUsed