{-# 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-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)
--
-- 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.Lens as Lens
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
(GetAccessKeyInfo -> GetAccessKeyInfo -> Bool)
-> (GetAccessKeyInfo -> GetAccessKeyInfo -> Bool)
-> Eq GetAccessKeyInfo
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]
(Int -> ReadS GetAccessKeyInfo)
-> ReadS [GetAccessKeyInfo]
-> ReadPrec GetAccessKeyInfo
-> ReadPrec [GetAccessKeyInfo]
-> Read 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
(Int -> GetAccessKeyInfo -> ShowS)
-> (GetAccessKeyInfo -> String)
-> ([GetAccessKeyInfo] -> ShowS)
-> Show GetAccessKeyInfo
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. GetAccessKeyInfo -> Rep GetAccessKeyInfo x)
-> (forall x. Rep GetAccessKeyInfo x -> GetAccessKeyInfo)
-> Generic GetAccessKeyInfo
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' :: AccessKey -> GetAccessKeyInfo
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 :: (AccessKey -> f AccessKey)
-> GetAccessKeyInfo -> f GetAccessKeyInfo
getAccessKeyInfo_accessKeyId = (GetAccessKeyInfo -> AccessKey)
-> (GetAccessKeyInfo -> AccessKey -> GetAccessKeyInfo)
-> Lens GetAccessKeyInfo GetAccessKeyInfo AccessKey AccessKey
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 :: GetAccessKeyInfo -> Request GetAccessKeyInfo
request = Service -> GetAccessKeyInfo -> Request GetAccessKeyInfo
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy GetAccessKeyInfo
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetAccessKeyInfo)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse GetAccessKeyInfo))
-> Logger
-> Service
-> Proxy GetAccessKeyInfo
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetAccessKeyInfo)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> 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'
            (Maybe Text -> Int -> GetAccessKeyInfoResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetAccessKeyInfoResponse)
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)
Core..@? Text
"Account")
            Either String (Int -> GetAccessKeyInfoResponse)
-> Either String Int -> Either String GetAccessKeyInfoResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
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 GetAccessKeyInfo

instance Prelude.NFData GetAccessKeyInfo

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

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

instance Core.ToQuery GetAccessKeyInfo where
  toQuery :: GetAccessKeyInfo -> QueryString
toQuery GetAccessKeyInfo' {AccessKey
accessKeyId :: AccessKey
$sel:accessKeyId:GetAccessKeyInfo' :: GetAccessKeyInfo -> AccessKey
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"GetAccessKeyInfo" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2011-06-15" :: Prelude.ByteString),
        ByteString
"AccessKeyId" ByteString -> AccessKey -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: 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
(GetAccessKeyInfoResponse -> GetAccessKeyInfoResponse -> Bool)
-> (GetAccessKeyInfoResponse -> GetAccessKeyInfoResponse -> Bool)
-> Eq GetAccessKeyInfoResponse
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]
(Int -> ReadS GetAccessKeyInfoResponse)
-> ReadS [GetAccessKeyInfoResponse]
-> ReadPrec GetAccessKeyInfoResponse
-> ReadPrec [GetAccessKeyInfoResponse]
-> Read 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
(Int -> GetAccessKeyInfoResponse -> ShowS)
-> (GetAccessKeyInfoResponse -> String)
-> ([GetAccessKeyInfoResponse] -> ShowS)
-> Show GetAccessKeyInfoResponse
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.
 GetAccessKeyInfoResponse -> Rep GetAccessKeyInfoResponse x)
-> (forall x.
    Rep GetAccessKeyInfoResponse x -> GetAccessKeyInfoResponse)
-> Generic GetAccessKeyInfoResponse
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' :: Maybe Text -> Int -> GetAccessKeyInfoResponse
GetAccessKeyInfoResponse'
    { $sel:account:GetAccessKeyInfoResponse' :: Maybe Text
account =
        Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> GetAccessKeyInfoResponse -> f GetAccessKeyInfoResponse
getAccessKeyInfoResponse_account = (GetAccessKeyInfoResponse -> Maybe Text)
-> (GetAccessKeyInfoResponse
    -> Maybe Text -> GetAccessKeyInfoResponse)
-> Lens
     GetAccessKeyInfoResponse
     GetAccessKeyInfoResponse
     (Maybe Text)
     (Maybe Text)
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 :: (Int -> f Int)
-> GetAccessKeyInfoResponse -> f GetAccessKeyInfoResponse
getAccessKeyInfoResponse_httpStatus = (GetAccessKeyInfoResponse -> Int)
-> (GetAccessKeyInfoResponse -> Int -> GetAccessKeyInfoResponse)
-> Lens GetAccessKeyInfoResponse GetAccessKeyInfoResponse Int Int
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