module Aws.Iam.Commands.CreateAccessKey
( CreateAccessKey(..)
, CreateAccessKeyResponse(..)
, AccessKey(..)
) where
import Aws.Core
import Aws.Iam.Core
import Aws.Iam.Internal
import Control.Applicative
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Time
import Data.Typeable
import Text.XML.Cursor (($//))
data CreateAccessKey = CreateAccessKey (Maybe Text)
deriving (Eq, Ord, Show, Typeable)
instance SignQuery CreateAccessKey where
type ServiceConfiguration CreateAccessKey = IamConfiguration
signQuery (CreateAccessKey user)
= iamAction' "CreateAccessKey" [("UserName",) <$> user]
data AccessKey
= AccessKey {
akAccessKeyId :: Text
, akCreateDate :: Maybe UTCTime
, akSecretAccessKey :: Text
, akStatus :: AccessKeyStatus
, akUserName :: Text
}
deriving (Eq, Ord, Show, Typeable)
data CreateAccessKeyResponse
= CreateAccessKeyResponse AccessKey
deriving (Eq, Ord, Show, Typeable)
instance ResponseConsumer CreateAccessKey CreateAccessKeyResponse where
type ResponseMetadata CreateAccessKeyResponse = IamMetadata
responseConsumer _
= iamResponseConsumer $ \cursor -> do
let attr name = force ("Missing " ++ Text.unpack name) $
cursor $// elContent name
akAccessKeyId <- attr "AccessKeyId"
akSecretAccessKey <- attr "SecretAccessKey"
akStatus <- readAccessKeyStatus <$> attr "Status"
akUserName <- attr "UserName"
akCreateDate <- readDate cursor
return $ CreateAccessKeyResponse AccessKey{..}
where
readDate c = case c $// elCont "CreateDate" of
(x:_) -> Just <$> parseDateTime x
_ -> return Nothing
readAccessKeyStatus s
| Text.toCaseFold s == "Active" = AccessKeyActive
| otherwise = AccessKeyInactive
instance Transaction CreateAccessKey CreateAccessKeyResponse
instance AsMemoryResponse CreateAccessKeyResponse where
type MemoryResponse CreateAccessKeyResponse = CreateAccessKeyResponse
loadToMemory = return