{-# 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListAccessKeys -> ListAccessKeys -> Bool
$c/= :: ListAccessKeys -> ListAccessKeys -> Bool
== :: ListAccessKeys -> ListAccessKeys -> Bool
$c== :: ListAccessKeys -> ListAccessKeys -> Bool
Eq, Eq 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
min :: ListAccessKeys -> ListAccessKeys -> ListAccessKeys
$cmin :: ListAccessKeys -> ListAccessKeys -> ListAccessKeys
max :: ListAccessKeys -> ListAccessKeys -> ListAccessKeys
$cmax :: ListAccessKeys -> ListAccessKeys -> ListAccessKeys
>= :: ListAccessKeys -> ListAccessKeys -> Bool
$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
compare :: ListAccessKeys -> ListAccessKeys -> Ordering
$ccompare :: ListAccessKeys -> ListAccessKeys -> Ordering
Ord, Int -> ListAccessKeys -> ShowS
[ListAccessKeys] -> ShowS
ListAccessKeys -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListAccessKeys] -> ShowS
$cshowList :: [ListAccessKeys] -> ShowS
show :: ListAccessKeys -> String
$cshow :: ListAccessKeys -> String
showsPrec :: Int -> ListAccessKeys -> ShowS
$cshowsPrec :: Int -> 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
lakMaxItems :: Maybe Integer
lakMarker :: Maybe Text
lakUserName :: Maybe Text
lakMaxItems :: ListAccessKeys -> Maybe Integer
lakMarker :: ListAccessKeys -> Maybe Text
lakUserName :: ListAccessKeys -> Maybe Text
..}
        = forall qt.
ByteString
-> [Maybe (ByteString, Text)]
-> IamConfiguration qt
-> SignatureData
-> SignedQuery
iamAction' ByteString
"ListAccessKeys" forall a b. (a -> b) -> a -> b
$ [
              (ByteString
"UserName",) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
lakUserName
            ] 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
$c/= :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
== :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
$c== :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
Eq, Eq 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
min :: AccessKeyMetadata -> AccessKeyMetadata -> AccessKeyMetadata
$cmin :: AccessKeyMetadata -> AccessKeyMetadata -> AccessKeyMetadata
max :: AccessKeyMetadata -> AccessKeyMetadata -> AccessKeyMetadata
$cmax :: AccessKeyMetadata -> AccessKeyMetadata -> AccessKeyMetadata
>= :: AccessKeyMetadata -> AccessKeyMetadata -> Bool
$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
compare :: AccessKeyMetadata -> AccessKeyMetadata -> Ordering
$ccompare :: AccessKeyMetadata -> AccessKeyMetadata -> Ordering
Ord, Int -> AccessKeyMetadata -> ShowS
[AccessKeyMetadata] -> ShowS
AccessKeyMetadata -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AccessKeyMetadata] -> ShowS
$cshowList :: [AccessKeyMetadata] -> ShowS
show :: AccessKeyMetadata -> String
$cshow :: AccessKeyMetadata -> String
showsPrec :: Int -> AccessKeyMetadata -> ShowS
$cshowsPrec :: Int -> 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
$c/= :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
== :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
$c== :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
Eq, Eq 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
min :: ListAccessKeysResponse
-> ListAccessKeysResponse -> ListAccessKeysResponse
$cmin :: ListAccessKeysResponse
-> ListAccessKeysResponse -> ListAccessKeysResponse
max :: ListAccessKeysResponse
-> ListAccessKeysResponse -> ListAccessKeysResponse
$cmax :: ListAccessKeysResponse
-> ListAccessKeysResponse -> ListAccessKeysResponse
>= :: ListAccessKeysResponse -> ListAccessKeysResponse -> Bool
$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
compare :: ListAccessKeysResponse -> ListAccessKeysResponse -> Ordering
$ccompare :: ListAccessKeysResponse -> ListAccessKeysResponse -> Ordering
Ord, Int -> ListAccessKeysResponse -> ShowS
[ListAccessKeysResponse] -> ShowS
ListAccessKeysResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListAccessKeysResponse] -> ShowS
$cshowList :: [ListAccessKeysResponse] -> ShowS
show :: ListAccessKeysResponse -> String
$cshow :: ListAccessKeysResponse -> String
showsPrec :: Int -> ListAccessKeysResponse -> ShowS
$cshowsPrec :: Int -> ListAccessKeysResponse -> ShowS
Show, Typeable)

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

            mhead :: [a] -> Maybe a
mhead (a
x:[a]
_) = forall a. a -> Maybe a
Just a
x
            mhead  [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     -> forall a. Maybe a
Nothing
            Just Text
marker -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ListAccessKeys
request { lakMarker :: Maybe Text
lakMarker = forall a. a -> Maybe a
Just Text
marker }

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