{-# 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.IAM.GetCredentialReport
-- 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)
--
-- Retrieves a credential report for the Amazon Web Services account. For
-- more information about the credential report, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/credential-reports.html Getting credential reports>
-- in the /IAM User Guide/.
module Amazonka.IAM.GetCredentialReport
  ( -- * Creating a Request
    GetCredentialReport (..),
    newGetCredentialReport,

    -- * Destructuring the Response
    GetCredentialReportResponse (..),
    newGetCredentialReportResponse,

    -- * Response Lenses
    getCredentialReportResponse_content,
    getCredentialReportResponse_generatedTime,
    getCredentialReportResponse_reportFormat,
    getCredentialReportResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IAM.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

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

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

instance Core.AWSRequest GetCredentialReport where
  type
    AWSResponse GetCredentialReport =
      GetCredentialReportResponse
  request :: GetCredentialReport -> Request GetCredentialReport
request = Service -> GetCredentialReport -> Request GetCredentialReport
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy GetCredentialReport
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetCredentialReport)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse GetCredentialReport))
-> Logger
-> Service
-> Proxy GetCredentialReport
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetCredentialReport)))
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
"GetCredentialReportResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Base64
-> Maybe ISO8601
-> Maybe ReportFormatType
-> Int
-> GetCredentialReportResponse
GetCredentialReportResponse'
            (Maybe Base64
 -> Maybe ISO8601
 -> Maybe ReportFormatType
 -> Int
 -> GetCredentialReportResponse)
-> Either String (Maybe Base64)
-> Either
     String
     (Maybe ISO8601
      -> Maybe ReportFormatType -> Int -> GetCredentialReportResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Base64)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Content")
            Either
  String
  (Maybe ISO8601
   -> Maybe ReportFormatType -> Int -> GetCredentialReportResponse)
-> Either String (Maybe ISO8601)
-> Either
     String
     (Maybe ReportFormatType -> Int -> GetCredentialReportResponse)
forall (f :: * -> *) a b. Applicative f => 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
"GeneratedTime")
            Either
  String
  (Maybe ReportFormatType -> Int -> GetCredentialReportResponse)
-> Either String (Maybe ReportFormatType)
-> Either String (Int -> GetCredentialReportResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe ReportFormatType)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"ReportFormat")
            Either String (Int -> GetCredentialReportResponse)
-> Either String Int -> Either String GetCredentialReportResponse
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 GetCredentialReport

instance Prelude.NFData GetCredentialReport

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

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

instance Core.ToQuery GetCredentialReport where
  toQuery :: GetCredentialReport -> QueryString
toQuery =
    QueryString -> GetCredentialReport -> 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
Core.=: (ByteString
"GetCredentialReport" :: Prelude.ByteString),
            ByteString
"Version"
              ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-05-08" :: Prelude.ByteString)
          ]
      )

-- | Contains the response to a successful GetCredentialReport request.
--
-- /See:/ 'newGetCredentialReportResponse' smart constructor.
data GetCredentialReportResponse = GetCredentialReportResponse'
  { -- | Contains the credential report. The report is Base64-encoded.
    GetCredentialReportResponse -> Maybe Base64
content :: Prelude.Maybe Core.Base64,
    -- | The date and time when the credential report was created, in
    -- <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>.
    GetCredentialReportResponse -> Maybe ISO8601
generatedTime :: Prelude.Maybe Core.ISO8601,
    -- | The format (MIME type) of the credential report.
    GetCredentialReportResponse -> Maybe ReportFormatType
reportFormat :: Prelude.Maybe ReportFormatType,
    -- | The response's http status code.
    GetCredentialReportResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetCredentialReportResponse -> GetCredentialReportResponse -> Bool
(GetCredentialReportResponse
 -> GetCredentialReportResponse -> Bool)
-> (GetCredentialReportResponse
    -> GetCredentialReportResponse -> Bool)
-> Eq GetCredentialReportResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCredentialReportResponse -> GetCredentialReportResponse -> Bool
$c/= :: GetCredentialReportResponse -> GetCredentialReportResponse -> Bool
== :: GetCredentialReportResponse -> GetCredentialReportResponse -> Bool
$c== :: GetCredentialReportResponse -> GetCredentialReportResponse -> Bool
Prelude.Eq, ReadPrec [GetCredentialReportResponse]
ReadPrec GetCredentialReportResponse
Int -> ReadS GetCredentialReportResponse
ReadS [GetCredentialReportResponse]
(Int -> ReadS GetCredentialReportResponse)
-> ReadS [GetCredentialReportResponse]
-> ReadPrec GetCredentialReportResponse
-> ReadPrec [GetCredentialReportResponse]
-> Read GetCredentialReportResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCredentialReportResponse]
$creadListPrec :: ReadPrec [GetCredentialReportResponse]
readPrec :: ReadPrec GetCredentialReportResponse
$creadPrec :: ReadPrec GetCredentialReportResponse
readList :: ReadS [GetCredentialReportResponse]
$creadList :: ReadS [GetCredentialReportResponse]
readsPrec :: Int -> ReadS GetCredentialReportResponse
$creadsPrec :: Int -> ReadS GetCredentialReportResponse
Prelude.Read, Int -> GetCredentialReportResponse -> ShowS
[GetCredentialReportResponse] -> ShowS
GetCredentialReportResponse -> String
(Int -> GetCredentialReportResponse -> ShowS)
-> (GetCredentialReportResponse -> String)
-> ([GetCredentialReportResponse] -> ShowS)
-> Show GetCredentialReportResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCredentialReportResponse] -> ShowS
$cshowList :: [GetCredentialReportResponse] -> ShowS
show :: GetCredentialReportResponse -> String
$cshow :: GetCredentialReportResponse -> String
showsPrec :: Int -> GetCredentialReportResponse -> ShowS
$cshowsPrec :: Int -> GetCredentialReportResponse -> ShowS
Prelude.Show, (forall x.
 GetCredentialReportResponse -> Rep GetCredentialReportResponse x)
-> (forall x.
    Rep GetCredentialReportResponse x -> GetCredentialReportResponse)
-> Generic GetCredentialReportResponse
forall x.
Rep GetCredentialReportResponse x -> GetCredentialReportResponse
forall x.
GetCredentialReportResponse -> Rep GetCredentialReportResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetCredentialReportResponse x -> GetCredentialReportResponse
$cfrom :: forall x.
GetCredentialReportResponse -> Rep GetCredentialReportResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetCredentialReportResponse' 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:
--
-- 'content', 'getCredentialReportResponse_content' - Contains the credential report. The report is Base64-encoded.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
--
-- 'generatedTime', 'getCredentialReportResponse_generatedTime' - The date and time when the credential report was created, in
-- <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>.
--
-- 'reportFormat', 'getCredentialReportResponse_reportFormat' - The format (MIME type) of the credential report.
--
-- 'httpStatus', 'getCredentialReportResponse_httpStatus' - The response's http status code.
newGetCredentialReportResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetCredentialReportResponse
newGetCredentialReportResponse :: Int -> GetCredentialReportResponse
newGetCredentialReportResponse Int
pHttpStatus_ =
  GetCredentialReportResponse' :: Maybe Base64
-> Maybe ISO8601
-> Maybe ReportFormatType
-> Int
-> GetCredentialReportResponse
GetCredentialReportResponse'
    { $sel:content:GetCredentialReportResponse' :: Maybe Base64
content =
        Maybe Base64
forall a. Maybe a
Prelude.Nothing,
      $sel:generatedTime:GetCredentialReportResponse' :: Maybe ISO8601
generatedTime = Maybe ISO8601
forall a. Maybe a
Prelude.Nothing,
      $sel:reportFormat:GetCredentialReportResponse' :: Maybe ReportFormatType
reportFormat = Maybe ReportFormatType
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetCredentialReportResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Contains the credential report. The report is Base64-encoded.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
getCredentialReportResponse_content :: Lens.Lens' GetCredentialReportResponse (Prelude.Maybe Prelude.ByteString)
getCredentialReportResponse_content :: (Maybe ByteString -> f (Maybe ByteString))
-> GetCredentialReportResponse -> f GetCredentialReportResponse
getCredentialReportResponse_content = (GetCredentialReportResponse -> Maybe Base64)
-> (GetCredentialReportResponse
    -> Maybe Base64 -> GetCredentialReportResponse)
-> Lens
     GetCredentialReportResponse
     GetCredentialReportResponse
     (Maybe Base64)
     (Maybe Base64)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCredentialReportResponse' {Maybe Base64
content :: Maybe Base64
$sel:content:GetCredentialReportResponse' :: GetCredentialReportResponse -> Maybe Base64
content} -> Maybe Base64
content) (\s :: GetCredentialReportResponse
s@GetCredentialReportResponse' {} Maybe Base64
a -> GetCredentialReportResponse
s {$sel:content:GetCredentialReportResponse' :: Maybe Base64
content = Maybe Base64
a} :: GetCredentialReportResponse) ((Maybe Base64 -> f (Maybe Base64))
 -> GetCredentialReportResponse -> f GetCredentialReportResponse)
-> ((Maybe ByteString -> f (Maybe ByteString))
    -> Maybe Base64 -> f (Maybe Base64))
-> (Maybe ByteString -> f (Maybe ByteString))
-> GetCredentialReportResponse
-> f GetCredentialReportResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso Base64 Base64 ByteString ByteString
-> Iso
     (Maybe Base64) (Maybe Base64) (Maybe ByteString) (Maybe ByteString)
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 Base64 Base64 ByteString ByteString
Iso' Base64 ByteString
Core._Base64

-- | The date and time when the credential report was created, in
-- <http://www.iso.org/iso/iso8601 ISO 8601 date-time format>.
getCredentialReportResponse_generatedTime :: Lens.Lens' GetCredentialReportResponse (Prelude.Maybe Prelude.UTCTime)
getCredentialReportResponse_generatedTime :: (Maybe UTCTime -> f (Maybe UTCTime))
-> GetCredentialReportResponse -> f GetCredentialReportResponse
getCredentialReportResponse_generatedTime = (GetCredentialReportResponse -> Maybe ISO8601)
-> (GetCredentialReportResponse
    -> Maybe ISO8601 -> GetCredentialReportResponse)
-> Lens
     GetCredentialReportResponse
     GetCredentialReportResponse
     (Maybe ISO8601)
     (Maybe ISO8601)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCredentialReportResponse' {Maybe ISO8601
generatedTime :: Maybe ISO8601
$sel:generatedTime:GetCredentialReportResponse' :: GetCredentialReportResponse -> Maybe ISO8601
generatedTime} -> Maybe ISO8601
generatedTime) (\s :: GetCredentialReportResponse
s@GetCredentialReportResponse' {} Maybe ISO8601
a -> GetCredentialReportResponse
s {$sel:generatedTime:GetCredentialReportResponse' :: Maybe ISO8601
generatedTime = Maybe ISO8601
a} :: GetCredentialReportResponse) ((Maybe ISO8601 -> f (Maybe ISO8601))
 -> GetCredentialReportResponse -> f GetCredentialReportResponse)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe ISO8601 -> f (Maybe ISO8601))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> GetCredentialReportResponse
-> f GetCredentialReportResponse
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 format (MIME type) of the credential report.
getCredentialReportResponse_reportFormat :: Lens.Lens' GetCredentialReportResponse (Prelude.Maybe ReportFormatType)
getCredentialReportResponse_reportFormat :: (Maybe ReportFormatType -> f (Maybe ReportFormatType))
-> GetCredentialReportResponse -> f GetCredentialReportResponse
getCredentialReportResponse_reportFormat = (GetCredentialReportResponse -> Maybe ReportFormatType)
-> (GetCredentialReportResponse
    -> Maybe ReportFormatType -> GetCredentialReportResponse)
-> Lens
     GetCredentialReportResponse
     GetCredentialReportResponse
     (Maybe ReportFormatType)
     (Maybe ReportFormatType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCredentialReportResponse' {Maybe ReportFormatType
reportFormat :: Maybe ReportFormatType
$sel:reportFormat:GetCredentialReportResponse' :: GetCredentialReportResponse -> Maybe ReportFormatType
reportFormat} -> Maybe ReportFormatType
reportFormat) (\s :: GetCredentialReportResponse
s@GetCredentialReportResponse' {} Maybe ReportFormatType
a -> GetCredentialReportResponse
s {$sel:reportFormat:GetCredentialReportResponse' :: Maybe ReportFormatType
reportFormat = Maybe ReportFormatType
a} :: GetCredentialReportResponse)

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

instance Prelude.NFData GetCredentialReportResponse