{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.STS.GetCallerIdentity
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns details about the IAM user or role whose credentials are used to
-- call the operation.
--
-- No permissions are required to perform this operation. If an
-- administrator adds a policy to your IAM user or role that explicitly
-- denies access to the @sts:GetCallerIdentity@ action, you can still
-- perform this operation. Permissions are not required because the same
-- information is returned when an IAM user or role is denied access. To
-- view an example response, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_general.html#troubleshoot_general_access-denied-delete-mfa I Am Not Authorized to Perform: iam:DeleteVirtualMFADevice>
-- in the /IAM User Guide/.
module Amazonka.STS.GetCallerIdentity
  ( -- * Creating a Request
    GetCallerIdentity (..),
    newGetCallerIdentity,

    -- * Destructuring the Response
    GetCallerIdentityResponse (..),
    newGetCallerIdentityResponse,

    -- * Response Lenses
    getCallerIdentityResponse_account,
    getCallerIdentityResponse_arn,
    getCallerIdentityResponse_userId,
    getCallerIdentityResponse_httpStatus,
  )
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.STS.Types

-- | /See:/ 'newGetCallerIdentity' smart constructor.
data GetCallerIdentity = GetCallerIdentity'
  {
  }
  deriving (GetCallerIdentity -> GetCallerIdentity -> Bool
(GetCallerIdentity -> GetCallerIdentity -> Bool)
-> (GetCallerIdentity -> GetCallerIdentity -> Bool)
-> Eq GetCallerIdentity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetCallerIdentity -> GetCallerIdentity -> Bool
== :: GetCallerIdentity -> GetCallerIdentity -> Bool
$c/= :: GetCallerIdentity -> GetCallerIdentity -> Bool
/= :: GetCallerIdentity -> GetCallerIdentity -> Bool
Prelude.Eq, ReadPrec [GetCallerIdentity]
ReadPrec GetCallerIdentity
Int -> ReadS GetCallerIdentity
ReadS [GetCallerIdentity]
(Int -> ReadS GetCallerIdentity)
-> ReadS [GetCallerIdentity]
-> ReadPrec GetCallerIdentity
-> ReadPrec [GetCallerIdentity]
-> Read GetCallerIdentity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS GetCallerIdentity
readsPrec :: Int -> ReadS GetCallerIdentity
$creadList :: ReadS [GetCallerIdentity]
readList :: ReadS [GetCallerIdentity]
$creadPrec :: ReadPrec GetCallerIdentity
readPrec :: ReadPrec GetCallerIdentity
$creadListPrec :: ReadPrec [GetCallerIdentity]
readListPrec :: ReadPrec [GetCallerIdentity]
Prelude.Read, Int -> GetCallerIdentity -> ShowS
[GetCallerIdentity] -> ShowS
GetCallerIdentity -> String
(Int -> GetCallerIdentity -> ShowS)
-> (GetCallerIdentity -> String)
-> ([GetCallerIdentity] -> ShowS)
-> Show GetCallerIdentity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetCallerIdentity -> ShowS
showsPrec :: Int -> GetCallerIdentity -> ShowS
$cshow :: GetCallerIdentity -> String
show :: GetCallerIdentity -> String
$cshowList :: [GetCallerIdentity] -> ShowS
showList :: [GetCallerIdentity] -> ShowS
Prelude.Show, (forall x. GetCallerIdentity -> Rep GetCallerIdentity x)
-> (forall x. Rep GetCallerIdentity x -> GetCallerIdentity)
-> Generic GetCallerIdentity
forall x. Rep GetCallerIdentity x -> GetCallerIdentity
forall x. GetCallerIdentity -> Rep GetCallerIdentity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. GetCallerIdentity -> Rep GetCallerIdentity x
from :: forall x. GetCallerIdentity -> Rep GetCallerIdentity x
$cto :: forall x. Rep GetCallerIdentity x -> GetCallerIdentity
to :: forall x. Rep GetCallerIdentity x -> GetCallerIdentity
Prelude.Generic)

-- |
-- Create a value of 'GetCallerIdentity' 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.
newGetCallerIdentity ::
  GetCallerIdentity
newGetCallerIdentity :: GetCallerIdentity
newGetCallerIdentity = GetCallerIdentity
GetCallerIdentity'

instance Core.AWSRequest GetCallerIdentity where
  type
    AWSResponse GetCallerIdentity =
      GetCallerIdentityResponse
  request :: (Service -> Service)
-> GetCallerIdentity -> Request GetCallerIdentity
request Service -> Service
overrides =
    Service -> GetCallerIdentity -> Request GetCallerIdentity
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetCallerIdentity
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetCallerIdentity)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse GetCallerIdentity))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetCallerIdentity
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetCallerIdentity)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"GetCallerIdentityResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Text
-> Maybe Text -> Maybe Text -> Int -> GetCallerIdentityResponse
GetCallerIdentityResponse'
            (Maybe Text
 -> Maybe Text -> Maybe Text -> Int -> GetCallerIdentityResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text -> Maybe Text -> Int -> GetCallerIdentityResponse)
forall (f :: * -> *) a b. Functor 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)
Data..@? Text
"Account")
            Either
  String
  (Maybe Text -> Maybe Text -> Int -> GetCallerIdentityResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> GetCallerIdentityResponse)
forall a b.
Either String (a -> b) -> Either String a -> Either String b
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)
Data..@? Text
"Arn")
            Either String (Maybe Text -> Int -> GetCallerIdentityResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetCallerIdentityResponse)
forall a b.
Either String (a -> b) -> Either String a -> Either String b
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)
Data..@? Text
"UserId")
            Either String (Int -> GetCallerIdentityResponse)
-> Either String Int -> Either String GetCallerIdentityResponse
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetCallerIdentity where
  hashWithSalt :: Int -> GetCallerIdentity -> Int
hashWithSalt Int
_salt GetCallerIdentity
_ =
    Int
_salt Int -> () -> Int
forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ()

instance Prelude.NFData GetCallerIdentity where
  rnf :: GetCallerIdentity -> ()
rnf GetCallerIdentity
_ = ()

instance Data.ToHeaders GetCallerIdentity where
  toHeaders :: GetCallerIdentity -> ResponseHeaders
toHeaders = ResponseHeaders -> GetCallerIdentity -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Data.ToPath GetCallerIdentity where
  toPath :: GetCallerIdentity -> ByteString
toPath = ByteString -> GetCallerIdentity -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery GetCallerIdentity where
  toQuery :: GetCallerIdentity -> QueryString
toQuery =
    QueryString -> GetCallerIdentity -> QueryString
forall a b. a -> b -> a
Prelude.const
      ( [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ ByteString
"Action"
              ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"GetCallerIdentity" :: Prelude.ByteString),
            ByteString
"Version"
              ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2011-06-15" :: Prelude.ByteString)
          ]
      )

-- | Contains the response to a successful GetCallerIdentity request,
-- including information about the entity making the request.
--
-- /See:/ 'newGetCallerIdentityResponse' smart constructor.
data GetCallerIdentityResponse = GetCallerIdentityResponse'
  { -- | The Amazon Web Services account ID number of the account that owns or
    -- contains the calling entity.
    GetCallerIdentityResponse -> Maybe Text
account :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Web Services ARN associated with the calling entity.
    GetCallerIdentityResponse -> Maybe Text
arn :: Prelude.Maybe Prelude.Text,
    -- | The unique identifier of the calling entity. The exact value depends on
    -- the type of entity that is making the call. The values returned are
    -- those listed in the __aws:userid__ column in the
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_variables.html#principaltable Principal table>
    -- found on the __Policy Variables__ reference page in the /IAM User
    -- Guide/.
    GetCallerIdentityResponse -> Maybe Text
userId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetCallerIdentityResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetCallerIdentityResponse -> GetCallerIdentityResponse -> Bool
(GetCallerIdentityResponse -> GetCallerIdentityResponse -> Bool)
-> (GetCallerIdentityResponse -> GetCallerIdentityResponse -> Bool)
-> Eq GetCallerIdentityResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetCallerIdentityResponse -> GetCallerIdentityResponse -> Bool
== :: GetCallerIdentityResponse -> GetCallerIdentityResponse -> Bool
$c/= :: GetCallerIdentityResponse -> GetCallerIdentityResponse -> Bool
/= :: GetCallerIdentityResponse -> GetCallerIdentityResponse -> Bool
Prelude.Eq, ReadPrec [GetCallerIdentityResponse]
ReadPrec GetCallerIdentityResponse
Int -> ReadS GetCallerIdentityResponse
ReadS [GetCallerIdentityResponse]
(Int -> ReadS GetCallerIdentityResponse)
-> ReadS [GetCallerIdentityResponse]
-> ReadPrec GetCallerIdentityResponse
-> ReadPrec [GetCallerIdentityResponse]
-> Read GetCallerIdentityResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS GetCallerIdentityResponse
readsPrec :: Int -> ReadS GetCallerIdentityResponse
$creadList :: ReadS [GetCallerIdentityResponse]
readList :: ReadS [GetCallerIdentityResponse]
$creadPrec :: ReadPrec GetCallerIdentityResponse
readPrec :: ReadPrec GetCallerIdentityResponse
$creadListPrec :: ReadPrec [GetCallerIdentityResponse]
readListPrec :: ReadPrec [GetCallerIdentityResponse]
Prelude.Read, Int -> GetCallerIdentityResponse -> ShowS
[GetCallerIdentityResponse] -> ShowS
GetCallerIdentityResponse -> String
(Int -> GetCallerIdentityResponse -> ShowS)
-> (GetCallerIdentityResponse -> String)
-> ([GetCallerIdentityResponse] -> ShowS)
-> Show GetCallerIdentityResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetCallerIdentityResponse -> ShowS
showsPrec :: Int -> GetCallerIdentityResponse -> ShowS
$cshow :: GetCallerIdentityResponse -> String
show :: GetCallerIdentityResponse -> String
$cshowList :: [GetCallerIdentityResponse] -> ShowS
showList :: [GetCallerIdentityResponse] -> ShowS
Prelude.Show, (forall x.
 GetCallerIdentityResponse -> Rep GetCallerIdentityResponse x)
-> (forall x.
    Rep GetCallerIdentityResponse x -> GetCallerIdentityResponse)
-> Generic GetCallerIdentityResponse
forall x.
Rep GetCallerIdentityResponse x -> GetCallerIdentityResponse
forall x.
GetCallerIdentityResponse -> Rep GetCallerIdentityResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
GetCallerIdentityResponse -> Rep GetCallerIdentityResponse x
from :: forall x.
GetCallerIdentityResponse -> Rep GetCallerIdentityResponse x
$cto :: forall x.
Rep GetCallerIdentityResponse x -> GetCallerIdentityResponse
to :: forall x.
Rep GetCallerIdentityResponse x -> GetCallerIdentityResponse
Prelude.Generic)

-- |
-- Create a value of 'GetCallerIdentityResponse' 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:
--
-- 'account', 'getCallerIdentityResponse_account' - The Amazon Web Services account ID number of the account that owns or
-- contains the calling entity.
--
-- 'arn', 'getCallerIdentityResponse_arn' - The Amazon Web Services ARN associated with the calling entity.
--
-- 'userId', 'getCallerIdentityResponse_userId' - The unique identifier of the calling entity. The exact value depends on
-- the type of entity that is making the call. The values returned are
-- those listed in the __aws:userid__ column in the
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_variables.html#principaltable Principal table>
-- found on the __Policy Variables__ reference page in the /IAM User
-- Guide/.
--
-- 'httpStatus', 'getCallerIdentityResponse_httpStatus' - The response's http status code.
newGetCallerIdentityResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetCallerIdentityResponse
newGetCallerIdentityResponse :: Int -> GetCallerIdentityResponse
newGetCallerIdentityResponse Int
pHttpStatus_ =
  GetCallerIdentityResponse'
    { $sel:account:GetCallerIdentityResponse' :: Maybe Text
account =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:arn:GetCallerIdentityResponse' :: Maybe Text
arn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:userId:GetCallerIdentityResponse' :: Maybe Text
userId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetCallerIdentityResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Web Services account ID number of the account that owns or
-- contains the calling entity.
getCallerIdentityResponse_account :: Lens.Lens' GetCallerIdentityResponse (Prelude.Maybe Prelude.Text)
getCallerIdentityResponse_account :: Lens' GetCallerIdentityResponse (Maybe Text)
getCallerIdentityResponse_account = (GetCallerIdentityResponse -> Maybe Text)
-> (GetCallerIdentityResponse
    -> Maybe Text -> GetCallerIdentityResponse)
-> Lens' GetCallerIdentityResponse (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCallerIdentityResponse' {Maybe Text
$sel:account:GetCallerIdentityResponse' :: GetCallerIdentityResponse -> Maybe Text
account :: Maybe Text
account} -> Maybe Text
account) (\s :: GetCallerIdentityResponse
s@GetCallerIdentityResponse' {} Maybe Text
a -> GetCallerIdentityResponse
s {account = a} :: GetCallerIdentityResponse)

-- | The Amazon Web Services ARN associated with the calling entity.
getCallerIdentityResponse_arn :: Lens.Lens' GetCallerIdentityResponse (Prelude.Maybe Prelude.Text)
getCallerIdentityResponse_arn :: Lens' GetCallerIdentityResponse (Maybe Text)
getCallerIdentityResponse_arn = (GetCallerIdentityResponse -> Maybe Text)
-> (GetCallerIdentityResponse
    -> Maybe Text -> GetCallerIdentityResponse)
-> Lens' GetCallerIdentityResponse (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCallerIdentityResponse' {Maybe Text
$sel:arn:GetCallerIdentityResponse' :: GetCallerIdentityResponse -> Maybe Text
arn :: Maybe Text
arn} -> Maybe Text
arn) (\s :: GetCallerIdentityResponse
s@GetCallerIdentityResponse' {} Maybe Text
a -> GetCallerIdentityResponse
s {arn = a} :: GetCallerIdentityResponse)

-- | The unique identifier of the calling entity. The exact value depends on
-- the type of entity that is making the call. The values returned are
-- those listed in the __aws:userid__ column in the
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_variables.html#principaltable Principal table>
-- found on the __Policy Variables__ reference page in the /IAM User
-- Guide/.
getCallerIdentityResponse_userId :: Lens.Lens' GetCallerIdentityResponse (Prelude.Maybe Prelude.Text)
getCallerIdentityResponse_userId :: Lens' GetCallerIdentityResponse (Maybe Text)
getCallerIdentityResponse_userId = (GetCallerIdentityResponse -> Maybe Text)
-> (GetCallerIdentityResponse
    -> Maybe Text -> GetCallerIdentityResponse)
-> Lens' GetCallerIdentityResponse (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCallerIdentityResponse' {Maybe Text
$sel:userId:GetCallerIdentityResponse' :: GetCallerIdentityResponse -> Maybe Text
userId :: Maybe Text
userId} -> Maybe Text
userId) (\s :: GetCallerIdentityResponse
s@GetCallerIdentityResponse' {} Maybe Text
a -> GetCallerIdentityResponse
s {userId = a} :: GetCallerIdentityResponse)

-- | The response's http status code.
getCallerIdentityResponse_httpStatus :: Lens.Lens' GetCallerIdentityResponse Prelude.Int
getCallerIdentityResponse_httpStatus :: Lens' GetCallerIdentityResponse Int
getCallerIdentityResponse_httpStatus = (GetCallerIdentityResponse -> Int)
-> (GetCallerIdentityResponse -> Int -> GetCallerIdentityResponse)
-> Lens' GetCallerIdentityResponse Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCallerIdentityResponse' {Int
$sel:httpStatus:GetCallerIdentityResponse' :: GetCallerIdentityResponse -> Int
httpStatus :: Int
httpStatus} -> Int
httpStatus) (\s :: GetCallerIdentityResponse
s@GetCallerIdentityResponse' {} Int
a -> GetCallerIdentityResponse
s {httpStatus = a} :: GetCallerIdentityResponse)

instance Prelude.NFData GetCallerIdentityResponse where
  rnf :: GetCallerIdentityResponse -> ()
rnf GetCallerIdentityResponse' {Int
Maybe Text
$sel:account:GetCallerIdentityResponse' :: GetCallerIdentityResponse -> Maybe Text
$sel:arn:GetCallerIdentityResponse' :: GetCallerIdentityResponse -> Maybe Text
$sel:userId:GetCallerIdentityResponse' :: GetCallerIdentityResponse -> Maybe Text
$sel:httpStatus:GetCallerIdentityResponse' :: GetCallerIdentityResponse -> Int
account :: Maybe Text
arn :: Maybe Text
userId :: Maybe Text
httpStatus :: Int
..} =
    Maybe Text -> ()
forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
account
      () -> () -> ()
forall a b. a -> b -> b
`Prelude.seq` Maybe Text -> ()
forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
arn
      () -> () -> ()
forall a b. a -> b -> b
`Prelude.seq` Maybe Text -> ()
forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
userId
      () -> () -> ()
forall a b. a -> b -> b
`Prelude.seq` Int -> ()
forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus