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, ($/), ($//), (&|))
data ListAccessKeys
= ListAccessKeys {
lakUserName :: Maybe Text
, lakMarker :: Maybe Text
, lakMaxItems :: Maybe Integer
}
deriving (Eq, Ord, Show, Typeable)
instance SignQuery ListAccessKeys where
type ServiceConfiguration ListAccessKeys = IamConfiguration
signQuery ListAccessKeys{..}
= iamAction' "ListAccessKeys" $ [
("UserName",) <$> lakUserName
] <> markedIter lakMarker lakMaxItems
data AccessKeyMetadata
= AccessKeyMetadata {
akmAccessKeyId :: Maybe Text
, akmCreateDate :: Maybe UTCTime
, akmStatus :: Maybe Text
, akmUserName :: Maybe Text
}
deriving (Eq, Ord, Show, Typeable)
data ListAccessKeysResponse
= ListAccessKeysResponse {
lakrAccessKeyMetadata :: [AccessKeyMetadata]
, lakrIsTruncated :: Bool
, lakrMarker :: Maybe Text
}
deriving (Eq, Ord, Show, Typeable)
instance ResponseConsumer ListAccessKeys ListAccessKeysResponse where
type ResponseMetadata ListAccessKeysResponse = IamMetadata
responseConsumer _ _
= iamResponseConsumer $ \cursor -> do
(lakrIsTruncated, lakrMarker) <- markedIterResponse cursor
lakrAccessKeyMetadata <- sequence $
cursor $// laxElement "member" &| buildAKM
return ListAccessKeysResponse{..}
where
buildAKM m = do
let mattr name = mhead $ m $/ elContent name
let akmAccessKeyId = mattr "AccessKeyId"
akmStatus = mattr "Status"
akmUserName = mattr "UserName"
akmCreateDate <- case m $/ elCont "CreateDate" of
(x:_) -> Just <$> parseDateTime x
_ -> return Nothing
return AccessKeyMetadata{..}
mhead (x:_) = Just x
mhead _ = Nothing
instance Transaction ListAccessKeys ListAccessKeysResponse
instance IteratedTransaction ListAccessKeys ListAccessKeysResponse where
nextIteratedRequest request response
= case lakrMarker response of
Nothing -> Nothing
Just marker -> Just $ request { lakMarker = Just marker }
instance AsMemoryResponse ListAccessKeysResponse where
type MemoryResponse ListAccessKeysResponse = ListAccessKeysResponse
loadToMemory = return