    {-# LANGUAGE MultiParamTypeClasses #-}
    {-# LANGUAGE RecordWildCards       #-}
    {-# LANGUAGE TupleSections         #-}
    {-# LANGUAGE TypeFamilies          #-}
    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           Prelude
    import           Text.XML.Cursor     (($//))

    -- | Creates a new AWS secret access key and corresponding AWS access key ID
    -- for the given user name.
    --
    -- If a user name is not provided, IAM will determine the user name based on
    -- the access key signing the request.
    --
    -- <http://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateAccessKey.html>
    data CreateAccessKey = CreateAccessKey (Maybe Text)
        deriving (CreateAccessKey -> CreateAccessKey -> Bool
    (CreateAccessKey -> CreateAccessKey -> Bool)
    -> (CreateAccessKey -> CreateAccessKey -> Bool)
    -> Eq CreateAccessKey
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: CreateAccessKey -> CreateAccessKey -> Bool
    == :: CreateAccessKey -> CreateAccessKey -> Bool
    $c/= :: CreateAccessKey -> CreateAccessKey -> Bool
    /= :: CreateAccessKey -> CreateAccessKey -> Bool
    Eq, Eq CreateAccessKey
    Eq CreateAccessKey =>
    (CreateAccessKey -> CreateAccessKey -> Ordering)
    -> (CreateAccessKey -> CreateAccessKey -> Bool)
    -> (CreateAccessKey -> CreateAccessKey -> Bool)
    -> (CreateAccessKey -> CreateAccessKey -> Bool)
    -> (CreateAccessKey -> CreateAccessKey -> Bool)
    -> (CreateAccessKey -> CreateAccessKey -> CreateAccessKey)
    -> (CreateAccessKey -> CreateAccessKey -> CreateAccessKey)
    -> Ord CreateAccessKey
    CreateAccessKey -> CreateAccessKey -> Bool
    CreateAccessKey -> CreateAccessKey -> Ordering
    CreateAccessKey -> CreateAccessKey -> CreateAccessKey
    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 :: CreateAccessKey -> CreateAccessKey -> Ordering
    compare :: CreateAccessKey -> CreateAccessKey -> Ordering
    $c< :: CreateAccessKey -> CreateAccessKey -> Bool
    < :: CreateAccessKey -> CreateAccessKey -> Bool
    $c<= :: CreateAccessKey -> CreateAccessKey -> Bool
    <= :: CreateAccessKey -> CreateAccessKey -> Bool
    $c> :: CreateAccessKey -> CreateAccessKey -> Bool
    > :: CreateAccessKey -> CreateAccessKey -> Bool
    $c>= :: CreateAccessKey -> CreateAccessKey -> Bool
    >= :: CreateAccessKey -> CreateAccessKey -> Bool
    $cmax :: CreateAccessKey -> CreateAccessKey -> CreateAccessKey
    max :: CreateAccessKey -> CreateAccessKey -> CreateAccessKey
    $cmin :: CreateAccessKey -> CreateAccessKey -> CreateAccessKey
    min :: CreateAccessKey -> CreateAccessKey -> CreateAccessKey
    Ord, Int -> CreateAccessKey -> ShowS
    [CreateAccessKey] -> ShowS
    CreateAccessKey -> String
    (Int -> CreateAccessKey -> ShowS)
    -> (CreateAccessKey -> String)
    -> ([CreateAccessKey] -> ShowS)
    -> Show CreateAccessKey
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> CreateAccessKey -> ShowS
    showsPrec :: Int -> CreateAccessKey -> ShowS
    $cshow :: CreateAccessKey -> String
    show :: CreateAccessKey -> String
    $cshowList :: [CreateAccessKey] -> ShowS
    showList :: [CreateAccessKey] -> ShowS
    Show, Typeable)

    instance SignQuery CreateAccessKey where
        type ServiceConfiguration CreateAccessKey = IamConfiguration
        signQuery :: forall queryType.
    CreateAccessKey
    -> ServiceConfiguration CreateAccessKey queryType
    -> SignatureData
    -> SignedQuery
    signQuery (CreateAccessKey Maybe Text
    user)
            = ByteString
    -> [Maybe (ByteString, Text)]
    -> IamConfiguration queryType
    -> SignatureData
    -> SignedQuery
    forall qt.
    ByteString
    -> [Maybe (ByteString, Text)]
    -> IamConfiguration qt
    -> SignatureData
    -> SignedQuery
    iamAction' ByteString
    "CreateAccessKey" [(ByteString
    "UserName",) (Text -> (ByteString, Text))
    -> Maybe Text -> Maybe (ByteString, Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Maybe Text
    user]

    -- | Represents the IAM @AccessKey@ data type.
    --
    -- <http://docs.aws.amazon.com/IAM/latest/APIReference/API_AccessKey.html>
    data AccessKey
        = AccessKey {
            AccessKey -> Text
    akAccessKeyId     :: Text
          -- ^ The Access Key ID.
          , AccessKey -> Maybe UTCTime
    akCreateDate      :: Maybe UTCTime
          -- ^ Date and time at which the access key was created.
          , AccessKey -> Text
    akSecretAccessKey :: Text
          -- ^ Secret key used to sign requests. The secret key is accessible only
          -- during key creation.
          , AccessKey -> AccessKeyStatus
    akStatus          :: AccessKeyStatus
          -- ^ Whether the access key is active or not.
          , AccessKey -> Text
    akUserName        :: Text
          -- ^ The user name for which this key is defined.
          }
        deriving (AccessKey -> AccessKey -> Bool
    (AccessKey -> AccessKey -> Bool)
    -> (AccessKey -> AccessKey -> Bool) -> Eq AccessKey
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: AccessKey -> AccessKey -> Bool
    == :: AccessKey -> AccessKey -> Bool
    $c/= :: AccessKey -> AccessKey -> Bool
    /= :: AccessKey -> AccessKey -> Bool
    Eq, Eq AccessKey
    Eq AccessKey =>
    (AccessKey -> AccessKey -> Ordering)
    -> (AccessKey -> AccessKey -> Bool)
    -> (AccessKey -> AccessKey -> Bool)
    -> (AccessKey -> AccessKey -> Bool)
    -> (AccessKey -> AccessKey -> Bool)
    -> (AccessKey -> AccessKey -> AccessKey)
    -> (AccessKey -> AccessKey -> AccessKey)
    -> Ord AccessKey
    AccessKey -> AccessKey -> Bool
    AccessKey -> AccessKey -> Ordering
    AccessKey -> AccessKey -> AccessKey
    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 :: AccessKey -> AccessKey -> Ordering
    compare :: AccessKey -> AccessKey -> Ordering
    $c< :: AccessKey -> AccessKey -> Bool
    < :: AccessKey -> AccessKey -> Bool
    $c<= :: AccessKey -> AccessKey -> Bool
    <= :: AccessKey -> AccessKey -> Bool
    $c> :: AccessKey -> AccessKey -> Bool
    > :: AccessKey -> AccessKey -> Bool
    $c>= :: AccessKey -> AccessKey -> Bool
    >= :: AccessKey -> AccessKey -> Bool
    $cmax :: AccessKey -> AccessKey -> AccessKey
    max :: AccessKey -> AccessKey -> AccessKey
    $cmin :: AccessKey -> AccessKey -> AccessKey
    min :: AccessKey -> AccessKey -> AccessKey
    Ord, Int -> AccessKey -> ShowS
    [AccessKey] -> ShowS
    AccessKey -> String
    (Int -> AccessKey -> ShowS)
    -> (AccessKey -> String)
    -> ([AccessKey] -> ShowS)
    -> Show AccessKey
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> AccessKey -> ShowS
    showsPrec :: Int -> AccessKey -> ShowS
    $cshow :: AccessKey -> String
    show :: AccessKey -> String
    $cshowList :: [AccessKey] -> ShowS
    showList :: [AccessKey] -> ShowS
    Show, Typeable)

    data CreateAccessKeyResponse
        = CreateAccessKeyResponse AccessKey
        deriving (CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    (CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool)
    -> (CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool)
    -> Eq CreateAccessKeyResponse
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    == :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    $c/= :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    /= :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    Eq, Eq CreateAccessKeyResponse
    Eq CreateAccessKeyResponse =>
    (CreateAccessKeyResponse -> CreateAccessKeyResponse -> Ordering)
    -> (CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool)
    -> (CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool)
    -> (CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool)
    -> (CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool)
    -> (CreateAccessKeyResponse
        -> CreateAccessKeyResponse -> CreateAccessKeyResponse)
    -> (CreateAccessKeyResponse
        -> CreateAccessKeyResponse -> CreateAccessKeyResponse)
    -> Ord CreateAccessKeyResponse
    CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    CreateAccessKeyResponse -> CreateAccessKeyResponse -> Ordering
    CreateAccessKeyResponse
    -> CreateAccessKeyResponse -> CreateAccessKeyResponse
    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 :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Ordering
    compare :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Ordering
    $c< :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    < :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    $c<= :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    <= :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    $c> :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    > :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    $c>= :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    >= :: CreateAccessKeyResponse -> CreateAccessKeyResponse -> Bool
    $cmax :: CreateAccessKeyResponse
    -> CreateAccessKeyResponse -> CreateAccessKeyResponse
    max :: CreateAccessKeyResponse
    -> CreateAccessKeyResponse -> CreateAccessKeyResponse
    $cmin :: CreateAccessKeyResponse
    -> CreateAccessKeyResponse -> CreateAccessKeyResponse
    min :: CreateAccessKeyResponse
    -> CreateAccessKeyResponse -> CreateAccessKeyResponse
    Ord, Int -> CreateAccessKeyResponse -> ShowS
    [CreateAccessKeyResponse] -> ShowS
    CreateAccessKeyResponse -> String
    (Int -> CreateAccessKeyResponse -> ShowS)
    -> (CreateAccessKeyResponse -> String)
    -> ([CreateAccessKeyResponse] -> ShowS)
    -> Show CreateAccessKeyResponse
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> CreateAccessKeyResponse -> ShowS
    showsPrec :: Int -> CreateAccessKeyResponse -> ShowS
    $cshow :: CreateAccessKeyResponse -> String
    show :: CreateAccessKeyResponse -> String
    $cshowList :: [CreateAccessKeyResponse] -> ShowS
    showList :: [CreateAccessKeyResponse] -> ShowS
    Show, Typeable)

    instance ResponseConsumer CreateAccessKey CreateAccessKeyResponse where
        type ResponseMetadata CreateAccessKeyResponse = IamMetadata
        responseConsumer :: Request
    -> CreateAccessKey
    -> IORef (ResponseMetadata CreateAccessKeyResponse)
    -> HTTPResponseConsumer CreateAccessKeyResponse
    responseConsumer Request
    _ CreateAccessKey
    _
            = (Cursor -> Response IamMetadata CreateAccessKeyResponse)
    -> IORef IamMetadata
    -> HTTPResponseConsumer CreateAccessKeyResponse
    forall a.
    (Cursor -> Response IamMetadata a)
    -> IORef IamMetadata -> HTTPResponseConsumer a
    iamResponseConsumer ((Cursor -> Response IamMetadata CreateAccessKeyResponse)
     -> IORef IamMetadata
     -> HTTPResponseConsumer CreateAccessKeyResponse)
    -> (Cursor -> Response IamMetadata CreateAccessKeyResponse)
    -> IORef IamMetadata
    -> HTTPResponseConsumer CreateAccessKeyResponse
    forall a b. (a -> b) -> a -> b
    $ \Cursor
    cursor -> do
                let attr :: Text -> Response IamMetadata Text
    attr Text
    name = String -> [Text] -> Response IamMetadata Text
    forall (m :: * -> *) a. MonadThrow m => String -> [a] -> m a
    force (String
    "Missing " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ Text -> String
    Text.unpack Text
    name) ([Text] -> Response IamMetadata Text)
    -> [Text] -> Response IamMetadata Text
    forall a b. (a -> b) -> a -> b
    $
                                Cursor
    cursor Cursor -> (Cursor -> [Text]) -> [Text]
    forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
    $// Text -> Cursor -> [Text]
    elContent Text
    name
                akAccessKeyId     <- Text -> Response IamMetadata Text
    attr Text
    "AccessKeyId"
                akSecretAccessKey <- attr "SecretAccessKey"
                akStatus          <- readAccessKeyStatus <$> attr "Status"
                akUserName        <- attr "UserName"
                akCreateDate      <- readDate cursor
                return $ CreateAccessKeyResponse AccessKey{..}
            where
              readDate :: Cursor -> f (Maybe UTCTime)
    readDate Cursor
    c = case Cursor
    c 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) -> f UTCTime -> f (Maybe UTCTime)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> String -> f UTCTime
    forall (m :: * -> *). MonadThrow m => String -> m UTCTime
    parseDateTime String
    x
                            [String]
    _     -> Maybe UTCTime -> f (Maybe UTCTime)
    forall a. a -> f a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe UTCTime
    forall a. Maybe a
    Nothing
              readAccessKeyStatus :: Text -> AccessKeyStatus
    readAccessKeyStatus Text
    s
                  | Text -> Text
    Text.toCaseFold Text
    s Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == Text
    "Active" = AccessKeyStatus
    AccessKeyActive
                  | Bool
    otherwise                     = AccessKeyStatus
    AccessKeyInactive

    instance Transaction CreateAccessKey CreateAccessKeyResponse

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