{-# 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.GetAccessKeyInfo
-- 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 the account identifier for the specified access key ID.
--
-- Access keys consist of two parts: an access key ID (for example,
-- @AKIAIOSFODNN7EXAMPLE@) and a secret access key (for example,
-- @wJalrXUtnFEMI\/K7MDENG\/bPxRfiCYEXAMPLEKEY@). For more information
-- about access keys, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html Managing Access Keys for IAM Users>
-- in the /IAM User Guide/.
--
-- When you pass an access key ID to this operation, it returns the ID of
-- the Amazon Web Services account to which the keys belong. Access key IDs
-- beginning with @AKIA@ are long-term credentials for an IAM user or the
-- Amazon Web Services account root user. Access key IDs beginning with
-- @ASIA@ are temporary credentials that are created using STS operations.
-- If the account in the response belongs to you, you can sign in as the
-- root user and review your root user access keys. Then, you can pull a
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_getting-report.html credentials report>
-- to learn which IAM user owns the keys. To learn who requested the
-- temporary credentials for an @ASIA@ access key, view the STS events in
-- your
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/cloudtrail-integration.html CloudTrail logs>
-- in the /IAM User Guide/.
--
-- This operation does not indicate the state of the access key. The key
-- might be active, inactive, or deleted. Active keys might not have
-- permissions to perform an operation. Providing a deleted access key
-- might return an error that the key doesn\'t exist.
module Amazonka.STS.GetAccessKeyInfo
  ( -- * Creating a Request
    GetAccessKeyInfo (..),
    newGetAccessKeyInfo,

    -- * Request Lenses
    getAccessKeyInfo_accessKeyId,

    -- * Destructuring the Response
    GetAccessKeyInfoResponse (..),
    newGetAccessKeyInfoResponse,

    -- * Response Lenses
    getAccessKeyInfoResponse_account,
    getAccessKeyInfoResponse_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:/ 'newGetAccessKeyInfo' smart constructor.
data GetAccessKeyInfo = GetAccessKeyInfo'
  { -- | The identifier of an access key.
    --
    -- This parameter allows (through its regex pattern) a string of characters
    -- that can consist of any upper- or lowercase letter or digit.
    GetAccessKeyInfo -> AccessKey
accessKeyId :: Core.AccessKey
  }
  deriving (GetAccessKeyInfo -> GetAccessKeyInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAccessKeyInfo -> GetAccessKeyInfo -> Bool
$c/= :: GetAccessKeyInfo -> GetAccessKeyInfo -> Bool
== :: GetAccessKeyInfo -> GetAccessKeyInfo -> Bool
$c== :: GetAccessKeyInfo -> GetAccessKeyInfo -> Bool
Prelude.Eq, ReadPrec [GetAccessKeyInfo]
ReadPrec GetAccessKeyInfo
Int -> ReadS GetAccessKeyInfo
ReadS [GetAccessKeyInfo]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetAccessKeyInfo]
$creadListPrec :: ReadPrec [GetAccessKeyInfo]
readPrec :: ReadPrec GetAccessKeyInfo
$creadPrec :: ReadPrec GetAccessKeyInfo
readList :: ReadS [GetAccessKeyInfo]
$creadList :: ReadS [GetAccessKeyInfo]
readsPrec :: Int -> ReadS GetAccessKeyInfo
$creadsPrec :: Int -> ReadS GetAccessKeyInfo
Prelude.Read, Int -> GetAccessKeyInfo -> ShowS
[GetAccessKeyInfo] -> ShowS
GetAccessKeyInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAccessKeyInfo] -> ShowS
$cshowList :: [GetAccessKeyInfo] -> ShowS
show :: GetAccessKeyInfo -> String
$cshow :: GetAccessKeyInfo -> String
showsPrec :: Int -> GetAccessKeyInfo -> ShowS
$cshowsPrec :: Int -> GetAccessKeyInfo -> ShowS
Prelude.Show, forall x. Rep GetAccessKeyInfo x -> GetAccessKeyInfo
forall x. GetAccessKeyInfo -> Rep GetAccessKeyInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetAccessKeyInfo x -> GetAccessKeyInfo
$cfrom :: forall x. GetAccessKeyInfo -> Rep GetAccessKeyInfo x
Prelude.Generic)

-- |
-- Create a value of 'GetAccessKeyInfo' 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:
--
-- 'accessKeyId', 'getAccessKeyInfo_accessKeyId' - The identifier of an access key.
--
-- This parameter allows (through its regex pattern) a string of characters
-- that can consist of any upper- or lowercase letter or digit.
newGetAccessKeyInfo ::
  -- | 'accessKeyId'
  Core.AccessKey ->
  GetAccessKeyInfo
newGetAccessKeyInfo :: AccessKey -> GetAccessKeyInfo
newGetAccessKeyInfo AccessKey
pAccessKeyId_ =
  GetAccessKeyInfo' {$sel:accessKeyId:GetAccessKeyInfo' :: AccessKey
accessKeyId = AccessKey
pAccessKeyId_}

-- | The identifier of an access key.
--
-- This parameter allows (through its regex pattern) a string of characters
-- that can consist of any upper- or lowercase letter or digit.
getAccessKeyInfo_accessKeyId :: Lens.Lens' GetAccessKeyInfo Core.AccessKey
getAccessKeyInfo_accessKeyId :: Lens' GetAccessKeyInfo AccessKey
getAccessKeyInfo_accessKeyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAccessKeyInfo' {AccessKey
accessKeyId :: AccessKey
$sel:accessKeyId:GetAccessKeyInfo' :: GetAccessKeyInfo -> AccessKey
accessKeyId} -> AccessKey
accessKeyId) (\s :: GetAccessKeyInfo
s@GetAccessKeyInfo' {} AccessKey
a -> GetAccessKeyInfo
s {$sel:accessKeyId:GetAccessKeyInfo' :: AccessKey
accessKeyId = AccessKey
a} :: GetAccessKeyInfo)

instance Core.AWSRequest GetAccessKeyInfo where
  type
    AWSResponse GetAccessKeyInfo =
      GetAccessKeyInfoResponse
  request :: (Service -> Service)
-> GetAccessKeyInfo -> Request GetAccessKeyInfo
request Service -> Service
overrides =
    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 GetAccessKeyInfo
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetAccessKeyInfo)))
response =
    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
"GetAccessKeyInfoResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Text -> Int -> GetAccessKeyInfoResponse
GetAccessKeyInfoResponse'
            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
"Account")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetAccessKeyInfo where
  hashWithSalt :: Int -> GetAccessKeyInfo -> Int
hashWithSalt Int
_salt GetAccessKeyInfo' {AccessKey
accessKeyId :: AccessKey
$sel:accessKeyId:GetAccessKeyInfo' :: GetAccessKeyInfo -> AccessKey
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` AccessKey
accessKeyId

instance Prelude.NFData GetAccessKeyInfo where
  rnf :: GetAccessKeyInfo -> ()
rnf GetAccessKeyInfo' {AccessKey
accessKeyId :: AccessKey
$sel:accessKeyId:GetAccessKeyInfo' :: GetAccessKeyInfo -> AccessKey
..} = forall a. NFData a => a -> ()
Prelude.rnf AccessKey
accessKeyId

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

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

instance Data.ToQuery GetAccessKeyInfo where
  toQuery :: GetAccessKeyInfo -> QueryString
toQuery GetAccessKeyInfo' {AccessKey
accessKeyId :: AccessKey
$sel:accessKeyId:GetAccessKeyInfo' :: GetAccessKeyInfo -> AccessKey
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"GetAccessKeyInfo" :: Prelude.ByteString),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2011-06-15" :: Prelude.ByteString),
        ByteString
"AccessKeyId" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: AccessKey
accessKeyId
      ]

-- | /See:/ 'newGetAccessKeyInfoResponse' smart constructor.
data GetAccessKeyInfoResponse = GetAccessKeyInfoResponse'
  { -- | The number used to identify the Amazon Web Services account.
    GetAccessKeyInfoResponse -> Maybe Text
account :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetAccessKeyInfoResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetAccessKeyInfoResponse -> GetAccessKeyInfoResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAccessKeyInfoResponse -> GetAccessKeyInfoResponse -> Bool
$c/= :: GetAccessKeyInfoResponse -> GetAccessKeyInfoResponse -> Bool
== :: GetAccessKeyInfoResponse -> GetAccessKeyInfoResponse -> Bool
$c== :: GetAccessKeyInfoResponse -> GetAccessKeyInfoResponse -> Bool
Prelude.Eq, ReadPrec [GetAccessKeyInfoResponse]
ReadPrec GetAccessKeyInfoResponse
Int -> ReadS GetAccessKeyInfoResponse
ReadS [GetAccessKeyInfoResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetAccessKeyInfoResponse]
$creadListPrec :: ReadPrec [GetAccessKeyInfoResponse]
readPrec :: ReadPrec GetAccessKeyInfoResponse
$creadPrec :: ReadPrec GetAccessKeyInfoResponse
readList :: ReadS [GetAccessKeyInfoResponse]
$creadList :: ReadS [GetAccessKeyInfoResponse]
readsPrec :: Int -> ReadS GetAccessKeyInfoResponse
$creadsPrec :: Int -> ReadS GetAccessKeyInfoResponse
Prelude.Read, Int -> GetAccessKeyInfoResponse -> ShowS
[GetAccessKeyInfoResponse] -> ShowS
GetAccessKeyInfoResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAccessKeyInfoResponse] -> ShowS
$cshowList :: [GetAccessKeyInfoResponse] -> ShowS
show :: GetAccessKeyInfoResponse -> String
$cshow :: GetAccessKeyInfoResponse -> String
showsPrec :: Int -> GetAccessKeyInfoResponse -> ShowS
$cshowsPrec :: Int -> GetAccessKeyInfoResponse -> ShowS
Prelude.Show, forall x.
Rep GetAccessKeyInfoResponse x -> GetAccessKeyInfoResponse
forall x.
GetAccessKeyInfoResponse -> Rep GetAccessKeyInfoResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetAccessKeyInfoResponse x -> GetAccessKeyInfoResponse
$cfrom :: forall x.
GetAccessKeyInfoResponse -> Rep GetAccessKeyInfoResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetAccessKeyInfoResponse' 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', 'getAccessKeyInfoResponse_account' - The number used to identify the Amazon Web Services account.
--
-- 'httpStatus', 'getAccessKeyInfoResponse_httpStatus' - The response's http status code.
newGetAccessKeyInfoResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetAccessKeyInfoResponse
newGetAccessKeyInfoResponse :: Int -> GetAccessKeyInfoResponse
newGetAccessKeyInfoResponse Int
pHttpStatus_ =
  GetAccessKeyInfoResponse'
    { $sel:account:GetAccessKeyInfoResponse' :: Maybe Text
account =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetAccessKeyInfoResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The number used to identify the Amazon Web Services account.
getAccessKeyInfoResponse_account :: Lens.Lens' GetAccessKeyInfoResponse (Prelude.Maybe Prelude.Text)
getAccessKeyInfoResponse_account :: Lens' GetAccessKeyInfoResponse (Maybe Text)
getAccessKeyInfoResponse_account = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAccessKeyInfoResponse' {Maybe Text
account :: Maybe Text
$sel:account:GetAccessKeyInfoResponse' :: GetAccessKeyInfoResponse -> Maybe Text
account} -> Maybe Text
account) (\s :: GetAccessKeyInfoResponse
s@GetAccessKeyInfoResponse' {} Maybe Text
a -> GetAccessKeyInfoResponse
s {$sel:account:GetAccessKeyInfoResponse' :: Maybe Text
account = Maybe Text
a} :: GetAccessKeyInfoResponse)

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

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