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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 Data.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
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]
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
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. 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'
    { $sel:lastUsedDate:RoleLastUsed' :: Maybe ISO8601
lastUsedDate = forall a. Maybe a
Prelude.Nothing,
      $sel:region:RoleLastUsed' :: Maybe Text
region = 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 :: Lens' RoleLastUsed (Maybe UTCTime)
roleLastUsed_lastUsedDate = 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) 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 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 :: Lens' RoleLastUsed (Maybe Text)
roleLastUsed_region = 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 Data.FromXML RoleLastUsed where
  parseXML :: [Node] -> Either String RoleLastUsed
parseXML [Node]
x =
    Maybe ISO8601 -> Maybe Text -> RoleLastUsed
RoleLastUsed'
      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
"LastUsedDate")
      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
"Region")

instance Prelude.Hashable RoleLastUsed where
  hashWithSalt :: Int -> RoleLastUsed -> Int
hashWithSalt Int
_salt RoleLastUsed' {Maybe Text
Maybe ISO8601
region :: Maybe Text
lastUsedDate :: Maybe ISO8601
$sel:region:RoleLastUsed' :: RoleLastUsed -> Maybe Text
$sel:lastUsedDate:RoleLastUsed' :: RoleLastUsed -> Maybe ISO8601
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ISO8601
lastUsedDate
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
region

instance Prelude.NFData RoleLastUsed where
  rnf :: RoleLastUsed -> ()
rnf RoleLastUsed' {Maybe Text
Maybe ISO8601
region :: Maybe Text
lastUsedDate :: Maybe ISO8601
$sel:region:RoleLastUsed' :: RoleLastUsed -> Maybe Text
$sel:lastUsedDate:RoleLastUsed' :: RoleLastUsed -> Maybe ISO8601
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ISO8601
lastUsedDate
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
region