{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
module Aws.Iam.Commands.ListAccessKeys
    ( ListAccessKeys(..)
    , ListAccessKeysResponse(..)
    ) where

import           Aws.Core
import           Aws.Iam.Core
import           Aws.Iam.Internal
import           Control.Applicative
import           Data.Text           (Text)
import           Data.Time
import           Data.Typeable
import           Prelude
import           Text.XML.Cursor     (laxElement, ($/), ($//), (&|))

-- | Returns the access keys associated with the specified user.
--
-- <http://docs.aws.amazon.com/IAM/latest/APIReference/API_ListAccessKeys.html>
data ListAccessKeys
    = ListAccessKeys {
        ListAccessKeys -> Maybe Text
lakUserName :: Maybe Text
      -- ^ Name of the user. If the user name is not specified, IAM will
      -- determine the user based on the key sigining the request.
      , ListAccessKeys -> Maybe Text
lakMarker   :: Maybe Text
      -- ^ Used for paginating requests. Marks the position of the last
      -- request.
      , ListAccessKeys -> Maybe Integer
lakMaxItems :: Maybe Integer
      -- ^ Used for paginating requests. Specifies the maximum number of items
      -- to return in the response. Defaults to 100.
      }
    deriving (ListAccessKeys -> ListAccessKeys -> Bool
(ListAccessKeys -> ListAccessKeys -> Bool)
-> (ListAccessKeys -> ListAccessKeys -> Bool) -> Eq ListAccessKeys
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ListAccessKeys -> ListAccessKeys -> Bool
== :: ListAccessKeys -> ListAccessKeys -> Bool
$c/= :: ListAccessKeys -> ListAccessKeys -> Bool
/= :: ListAccessKeys -> ListAccessKeys -> Bool
Eq, Eq ListAccessKeys
Eq ListAccessKeys =>
(ListAccessKeys -> ListAccessKeys -> Ordering)
-> (ListAccessKeys -> ListAccessKeys -> Bool)
-> (ListAccessKeys -> ListAccessKeys -> Bool)
-> (ListAccessKeys -> ListAccessKeys -> Bool)
-> (ListAccessKeys -> ListAccessKeys -> Bool)
-> (ListAccessKeys -> ListAccessKeys -> ListAccessKeys)
-> (ListAccessKeys -> ListAccessKeys -> ListAccessKeys)
-> Ord ListAccessKeys
ListAccessKeys -> ListAccessKeys -> Bool
ListAccessKeys -> ListAccessKeys -> Ordering
ListAccessKeys -> ListAccessKeys -> ListAccessKeys
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ListAccessKeys -> ListAccessKeys -> Ordering
compare :: ListAccessKeys -> ListAccessKeys -> Ordering
$c< :: ListAccessKeys -> ListAccessKeys -> Bool
< :: ListAccessKeys -> ListAccessKeys -> Bool
$c<= :: ListAccessKeys -> ListAccessKeys -> Bool
<= :: ListAccessKeys -> ListAccessKeys -> Bool
$c> :: ListAccessKeys -> ListAccessKeys -> Bool
> :: ListAccessKeys -> ListAccessKeys -> Bool
$c>= :: ListAccessKeys -> ListAccessKeys -> Bool
>= :: ListAccessKeys -> ListAccessKeys -> Bool
$cmax :: ListAccessKeys -> ListAccessKeys -> ListAccessKeys
max :: ListAccessKeys -> ListAccessKeys -> ListAccessKeys
$cmin :: ListAccessKeys -> ListAccessKeys -> ListAccessKeys
min :: ListAccessKeys -> ListAccessKeys -> ListAccessKeys
Ord, Int -> ListAccessKeys -> ShowS
[ListAccessKeys] -> ShowS
ListAccessKeys -> String
(Int -> ListAccessKeys -> ShowS)
-> (ListAccessKeys -> String)
-> ([ListAccessKeys] -> ShowS)
-> Show ListAccessKeys
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ListAccessKeys -> ShowS
showsPrec :: Int -> ListAccessKeys -> ShowS
$cshow :: ListAccessKeys -> String
show :: ListAccessKeys -> String
$cshowList :: [ListAccessKeys] -> ShowS
showList :: [ListAccessKeys] -> ShowS
Show, Typeable)

instance SignQuery ListAccessKeys where
    type ServiceConfiguration ListAccessKeys = IamConfiguration
    signQuery :: forall queryType.
ListAccessKeys
-> ServiceConfiguration ListAccessKeys queryType
-> SignatureData
-> SignedQuery
signQuery ListAccessKeys{Maybe Integer
Maybe Text
lakUserName :: ListAccessKeys -> Maybe Text
lakMarker :: ListAccessKeys -> Maybe Text
lakMaxItems :: ListAccessKeys -> Maybe Integer
lakUserName :: Maybe Text
lakMarker :: Maybe Text
lakMaxItems :: Maybe Integer
..}
        = ByteString
-> [Maybe (ByteString, Text)]
-> IamConfiguration queryType
-> SignatureData
-> SignedQuery
forall qt.
ByteString
-> [Maybe (ByteString, Text)]
-> IamConfiguration qt
-> SignatureData
-> SignedQuery
iamAction' ByteString
"ListAccessKeys" ([Maybe (ByteString, Text)]
 -> IamConfiguration queryType -> SignatureData -> SignedQuery)
-> [Maybe (ByteString, Text)]
-> IamConfiguration queryType
-> SignatureData
-> SignedQuery
forall a b. (a -> b) -> a -> b
$ [
              (ByteString
"UserName",) (Text -> (ByteString, Text))
-> Maybe Text -> Maybe (ByteString, Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
lakUserName
            ] [Maybe (ByteString, Text)]
-> [Maybe (ByteString, Text)] -> [Maybe (ByteString, Text)]
forall a. Semigroup a => a -> a -> a
<> Maybe Text -> Maybe Integer -> [Maybe (ByteString, Text)]
markedIter Maybe Text
lakMarker Maybe Integer
lakMaxItems

-- | Represents the IAM @AccessKeyMetadata@ data type.
--
-- <http://docs.aws.amazon.com/IAM/latest/APIReference/API_AccessKeyMetadata.html>
data AccessKeyMetadata
    = AccessKeyMetadata {
        AccessKeyMetadata -> Maybe Text
akmAccessKeyId :: Maybe Text
      -- ^ ID of the access key.
      , AccessKeyMetadata -> Maybe UTCTime
akmCreateDate  :: Maybe UTCTime
      -- ^ Date and time at which the access key was created.
      , AccessKeyMetadata -> Maybe Text
akmStatus      :: Maybe Text
      -- ^ Whether the access key is active.
      , AccessKeyMetadata -> Maybe Text
akmUserName    :: Maybe Text
      -- ^ Name of the user with whom the access key is associated.
      }
    deriving (AccessKeyMetadata -> AccessKeyMetadata -> Bool
(AccessKeyMetadata -> AccessKeyMetadata -> Bool)
-> (AccessKeyMetadata -> AccessKeyMetadata -> Bool)
-> Eq AccessKeyMetadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
== :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
$c/= :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
/= :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
Eq, Eq AccessKeyMetadata
Eq AccessKeyMetadata =>
(AccessKeyMetadata -> AccessKeyMetadata -> Ordering)
-> (AccessKeyMetadata -> AccessKeyMetadata -> Bool)
-> (AccessKeyMetadata -> AccessKeyMetadata -> Bool)
-> (AccessKeyMetadata -> AccessKeyMetadata -> Bool)
-> (AccessKeyMetadata -> AccessKeyMetadata -> Bool)
-> (AccessKeyMetadata -> AccessKeyMetadata -> AccessKeyMetadata)
-> (AccessKeyMetadata -> AccessKeyMetadata -> AccessKeyMetadata)
-> Ord AccessKeyMetadata
AccessKeyMetadata -> AccessKeyMetadata -> Bool
AccessKeyMetadata -> AccessKeyMetadata -> Ordering
AccessKeyMetadata -> AccessKeyMetadata -> AccessKeyMetadata
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: AccessKeyMetadata -> AccessKeyMetadata -> Ordering
compare :: AccessKeyMetadata -> AccessKeyMetadata -> Ordering
$c< :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
< :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
$c<= :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
<= :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
$c> :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
> :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
$c>= :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
>= :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
$cmax :: AccessKeyMetadata -> AccessKeyMetadata -> AccessKeyMetadata
max :: AccessKeyMetadata -> AccessKeyMetadata -> AccessKeyMetadata
$cmin :: AccessKeyMetadata -> AccessKeyMetadata -> AccessKeyMetadata
min :: AccessKeyMetadata -> AccessKeyMetadata -> AccessKeyMetadata
Ord, Int -> AccessKeyMetadata -> ShowS
[AccessKeyMetadata] -> ShowS
AccessKeyMetadata -> String
(Int -> AccessKeyMetadata -> ShowS)
-> (AccessKeyMetadata -> String)
-> ([AccessKeyMetadata] -> ShowS)
-> Show AccessKeyMetadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AccessKeyMetadata -> ShowS
showsPrec :: Int -> AccessKeyMetadata -> ShowS
$cshow :: AccessKeyMetadata -> String
show :: AccessKeyMetadata -> String
$cshowList :: [AccessKeyMetadata] -> ShowS
showList :: [AccessKeyMetadata] -> ShowS
Show, Typeable)

data ListAccessKeysResponse
    = ListAccessKeysResponse {
        ListAccessKeysResponse -> [AccessKeyMetadata]
lakrAccessKeyMetadata :: [AccessKeyMetadata]
      -- ^ List of 'AccessKeyMetadata' objects
      , ListAccessKeysResponse -> Bool
lakrIsTruncated       :: Bool
      -- ^ @True@ if the request was truncated because of too many items.
      , ListAccessKeysResponse -> Maybe Text
lakrMarker            :: Maybe Text
      -- ^ Marks the position at which the request was truncated. This value
      -- must be passed with the next request to continue listing from the
      -- last position.
      }
    deriving (ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
(ListAccessKeysResponse -> ListAccessKeysResponse -> Bool)
-> (ListAccessKeysResponse -> ListAccessKeysResponse -> Bool)
-> Eq ListAccessKeysResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
== :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
$c/= :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
/= :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
Eq, Eq ListAccessKeysResponse
Eq ListAccessKeysResponse =>
(ListAccessKeysResponse -> ListAccessKeysResponse -> Ordering)
-> (ListAccessKeysResponse -> ListAccessKeysResponse -> Bool)
-> (ListAccessKeysResponse -> ListAccessKeysResponse -> Bool)
-> (ListAccessKeysResponse -> ListAccessKeysResponse -> Bool)
-> (ListAccessKeysResponse -> ListAccessKeysResponse -> Bool)
-> (ListAccessKeysResponse
    -> ListAccessKeysResponse -> ListAccessKeysResponse)
-> (ListAccessKeysResponse
    -> ListAccessKeysResponse -> ListAccessKeysResponse)
-> Ord ListAccessKeysResponse
ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
ListAccessKeysResponse -> ListAccessKeysResponse -> Ordering
ListAccessKeysResponse
-> ListAccessKeysResponse -> ListAccessKeysResponse
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ListAccessKeysResponse -> ListAccessKeysResponse -> Ordering
compare :: ListAccessKeysResponse -> ListAccessKeysResponse -> Ordering
$c< :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
< :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
$c<= :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
<= :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
$c> :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
> :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
$c>= :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
>= :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
$cmax :: ListAccessKeysResponse
-> ListAccessKeysResponse -> ListAccessKeysResponse
max :: ListAccessKeysResponse
-> ListAccessKeysResponse -> ListAccessKeysResponse
$cmin :: ListAccessKeysResponse
-> ListAccessKeysResponse -> ListAccessKeysResponse
min :: ListAccessKeysResponse
-> ListAccessKeysResponse -> ListAccessKeysResponse
Ord, Int -> ListAccessKeysResponse -> ShowS
[ListAccessKeysResponse] -> ShowS
ListAccessKeysResponse -> String
(Int -> ListAccessKeysResponse -> ShowS)
-> (ListAccessKeysResponse -> String)
-> ([ListAccessKeysResponse] -> ShowS)
-> Show ListAccessKeysResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ListAccessKeysResponse -> ShowS
showsPrec :: Int -> ListAccessKeysResponse -> ShowS
$cshow :: ListAccessKeysResponse -> String
show :: ListAccessKeysResponse -> String
$cshowList :: [ListAccessKeysResponse] -> ShowS
showList :: [ListAccessKeysResponse] -> ShowS
Show, Typeable)

instance ResponseConsumer ListAccessKeys ListAccessKeysResponse where
    type ResponseMetadata ListAccessKeysResponse = IamMetadata
    responseConsumer :: Request
-> ListAccessKeys
-> IORef (ResponseMetadata ListAccessKeysResponse)
-> HTTPResponseConsumer ListAccessKeysResponse
responseConsumer Request
_ ListAccessKeys
_
        = (Cursor -> Response IamMetadata ListAccessKeysResponse)
-> IORef IamMetadata -> HTTPResponseConsumer ListAccessKeysResponse
forall a.
(Cursor -> Response IamMetadata a)
-> IORef IamMetadata -> HTTPResponseConsumer a
iamResponseConsumer ((Cursor -> Response IamMetadata ListAccessKeysResponse)
 -> IORef IamMetadata
 -> HTTPResponseConsumer ListAccessKeysResponse)
-> (Cursor -> Response IamMetadata ListAccessKeysResponse)
-> IORef IamMetadata
-> HTTPResponseConsumer ListAccessKeysResponse
forall a b. (a -> b) -> a -> b
$ \Cursor
cursor -> do
            (Bool
lakrIsTruncated, Maybe Text
lakrMarker) <- Cursor -> Response IamMetadata (Bool, Maybe Text)
forall (m :: * -> *).
MonadThrow m =>
Cursor -> m (Bool, Maybe Text)
markedIterResponse Cursor
cursor
            [AccessKeyMetadata]
lakrAccessKeyMetadata <- [Response IamMetadata AccessKeyMetadata]
-> Response IamMetadata [AccessKeyMetadata]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([Response IamMetadata AccessKeyMetadata]
 -> Response IamMetadata [AccessKeyMetadata])
-> [Response IamMetadata AccessKeyMetadata]
-> Response IamMetadata [AccessKeyMetadata]
forall a b. (a -> b) -> a -> b
$
                Cursor
cursor Cursor
-> (Cursor -> [Response IamMetadata AccessKeyMetadata])
-> [Response IamMetadata AccessKeyMetadata]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Axis
laxElement Text
"member" Axis
-> (Cursor -> Response IamMetadata AccessKeyMetadata)
-> Cursor
-> [Response IamMetadata AccessKeyMetadata]
forall node a b.
(Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
&| Cursor -> Response IamMetadata AccessKeyMetadata
forall {m :: * -> *}. MonadThrow m => Cursor -> m AccessKeyMetadata
buildAKM
            ListAccessKeysResponse
-> Response IamMetadata ListAccessKeysResponse
forall a. a -> Response IamMetadata a
forall (m :: * -> *) a. Monad m => a -> m a
return ListAccessKeysResponse{Bool
[AccessKeyMetadata]
Maybe Text
lakrAccessKeyMetadata :: [AccessKeyMetadata]
lakrIsTruncated :: Bool
lakrMarker :: Maybe Text
lakrIsTruncated :: Bool
lakrMarker :: Maybe Text
lakrAccessKeyMetadata :: [AccessKeyMetadata]
..}
        where
            buildAKM :: Cursor -> m AccessKeyMetadata
buildAKM Cursor
m = do
                let mattr :: Text -> Maybe Text
mattr Text
name = [Text] -> Maybe Text
forall {a}. [a] -> Maybe a
mhead ([Text] -> Maybe Text) -> [Text] -> Maybe Text
forall a b. (a -> b) -> a -> b
$ Cursor
m Cursor -> (Cursor -> [Text]) -> [Text]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Text -> Cursor -> [Text]
elContent Text
name
                let akmAccessKeyId :: Maybe Text
akmAccessKeyId = Text -> Maybe Text
mattr Text
"AccessKeyId"
                    akmStatus :: Maybe Text
akmStatus      = Text -> Maybe Text
mattr Text
"Status"
                    akmUserName :: Maybe Text
akmUserName    = Text -> Maybe Text
mattr Text
"UserName"
                Maybe UTCTime
akmCreateDate <- case Cursor
m Cursor -> (Cursor -> [String]) -> [String]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Text -> Cursor -> [String]
elCont Text
"CreateDate" of
                                    (String
x:[String]
_) -> UTCTime -> Maybe UTCTime
forall a. a -> Maybe a
Just (UTCTime -> Maybe UTCTime) -> m UTCTime -> m (Maybe UTCTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m UTCTime
forall (m :: * -> *). MonadThrow m => String -> m UTCTime
parseDateTime String
x
                                    [String]
_     -> Maybe UTCTime -> m (Maybe UTCTime)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe UTCTime
forall a. Maybe a
Nothing
                AccessKeyMetadata -> m AccessKeyMetadata
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return AccessKeyMetadata{Maybe Text
Maybe UTCTime
akmAccessKeyId :: Maybe Text
akmCreateDate :: Maybe UTCTime
akmStatus :: Maybe Text
akmUserName :: Maybe Text
akmAccessKeyId :: Maybe Text
akmStatus :: Maybe Text
akmUserName :: Maybe Text
akmCreateDate :: Maybe UTCTime
..}

            mhead :: [a] -> Maybe a
mhead (a
x:[a]
_) = a -> Maybe a
forall a. a -> Maybe a
Just a
x
            mhead  [a]
_    = Maybe a
forall a. Maybe a
Nothing

instance Transaction ListAccessKeys ListAccessKeysResponse

instance IteratedTransaction ListAccessKeys ListAccessKeysResponse where
    nextIteratedRequest :: ListAccessKeys -> ListAccessKeysResponse -> Maybe ListAccessKeys
nextIteratedRequest ListAccessKeys
request ListAccessKeysResponse
response
        = case ListAccessKeysResponse -> Maybe Text
lakrMarker ListAccessKeysResponse
response of
            Maybe Text
Nothing     -> Maybe ListAccessKeys
forall a. Maybe a
Nothing
            Just Text
marker -> ListAccessKeys -> Maybe ListAccessKeys
forall a. a -> Maybe a
Just (ListAccessKeys -> Maybe ListAccessKeys)
-> ListAccessKeys -> Maybe ListAccessKeys
forall a b. (a -> b) -> a -> b
$ ListAccessKeys
request { lakMarker = Just marker }

instance AsMemoryResponse ListAccessKeysResponse where
    type MemoryResponse ListAccessKeysResponse = ListAccessKeysResponse
    loadToMemory :: ListAccessKeysResponse
-> ResourceT IO (MemoryResponse ListAccessKeysResponse)
loadToMemory = ListAccessKeysResponse
-> ResourceT IO (MemoryResponse ListAccessKeysResponse)
ListAccessKeysResponse -> ResourceT IO ListAccessKeysResponse
forall a. a -> ResourceT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return