{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
module Aws.Iam.Commands.ListUsers
    ( ListUsers(..)
    , ListUsersResponse(..)
    , User(..)
    ) where

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

-- | Lists users that have the specified path prefix.
--
-- <http://docs.aws.amazon.com/IAM/latest/APIReference/API_ListUsers.html>
data ListUsers
    = ListUsers {
        ListUsers -> Maybe Text
luPathPrefix :: Maybe Text
      -- ^ Users defined under this path will be listed. If omitted, defaults
      -- to @/@, which lists all users.
      , ListUsers -> Maybe Text
luMarker     :: Maybe Text
      -- ^ Used for paginating requests. Marks the position of the last
      -- request.
      , ListUsers -> Maybe Integer
luMaxItems   :: Maybe Integer
      -- ^ Used for paginating requests. Specifies the maximum number of items
      -- to return in the response. Defaults to 100.
      }
    deriving (ListUsers -> ListUsers -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListUsers -> ListUsers -> Bool
$c/= :: ListUsers -> ListUsers -> Bool
== :: ListUsers -> ListUsers -> Bool
$c== :: ListUsers -> ListUsers -> Bool
Eq, Eq ListUsers
ListUsers -> ListUsers -> Bool
ListUsers -> ListUsers -> Ordering
ListUsers -> ListUsers -> ListUsers
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 :: ListUsers -> ListUsers -> ListUsers
$cmin :: ListUsers -> ListUsers -> ListUsers
max :: ListUsers -> ListUsers -> ListUsers
$cmax :: ListUsers -> ListUsers -> ListUsers
>= :: ListUsers -> ListUsers -> Bool
$c>= :: ListUsers -> ListUsers -> Bool
> :: ListUsers -> ListUsers -> Bool
$c> :: ListUsers -> ListUsers -> Bool
<= :: ListUsers -> ListUsers -> Bool
$c<= :: ListUsers -> ListUsers -> Bool
< :: ListUsers -> ListUsers -> Bool
$c< :: ListUsers -> ListUsers -> Bool
compare :: ListUsers -> ListUsers -> Ordering
$ccompare :: ListUsers -> ListUsers -> Ordering
Ord, Int -> ListUsers -> ShowS
[ListUsers] -> ShowS
ListUsers -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListUsers] -> ShowS
$cshowList :: [ListUsers] -> ShowS
show :: ListUsers -> String
$cshow :: ListUsers -> String
showsPrec :: Int -> ListUsers -> ShowS
$cshowsPrec :: Int -> ListUsers -> ShowS
Show, Typeable)

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

data ListUsersResponse
    = ListUsersResponse {
        ListUsersResponse -> [User]
lurUsers       :: [User]
      -- ^ List of 'User's.
      , ListUsersResponse -> Bool
lurIsTruncated :: Bool
      -- ^ @True@ if the request was truncated because of too many items.
      , ListUsersResponse -> Maybe Text
lurMarker      :: 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 (ListUsersResponse -> ListUsersResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListUsersResponse -> ListUsersResponse -> Bool
$c/= :: ListUsersResponse -> ListUsersResponse -> Bool
== :: ListUsersResponse -> ListUsersResponse -> Bool
$c== :: ListUsersResponse -> ListUsersResponse -> Bool
Eq, Eq ListUsersResponse
ListUsersResponse -> ListUsersResponse -> Bool
ListUsersResponse -> ListUsersResponse -> Ordering
ListUsersResponse -> ListUsersResponse -> ListUsersResponse
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 :: ListUsersResponse -> ListUsersResponse -> ListUsersResponse
$cmin :: ListUsersResponse -> ListUsersResponse -> ListUsersResponse
max :: ListUsersResponse -> ListUsersResponse -> ListUsersResponse
$cmax :: ListUsersResponse -> ListUsersResponse -> ListUsersResponse
>= :: ListUsersResponse -> ListUsersResponse -> Bool
$c>= :: ListUsersResponse -> ListUsersResponse -> Bool
> :: ListUsersResponse -> ListUsersResponse -> Bool
$c> :: ListUsersResponse -> ListUsersResponse -> Bool
<= :: ListUsersResponse -> ListUsersResponse -> Bool
$c<= :: ListUsersResponse -> ListUsersResponse -> Bool
< :: ListUsersResponse -> ListUsersResponse -> Bool
$c< :: ListUsersResponse -> ListUsersResponse -> Bool
compare :: ListUsersResponse -> ListUsersResponse -> Ordering
$ccompare :: ListUsersResponse -> ListUsersResponse -> Ordering
Ord, Int -> ListUsersResponse -> ShowS
[ListUsersResponse] -> ShowS
ListUsersResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListUsersResponse] -> ShowS
$cshowList :: [ListUsersResponse] -> ShowS
show :: ListUsersResponse -> String
$cshow :: ListUsersResponse -> String
showsPrec :: Int -> ListUsersResponse -> ShowS
$cshowsPrec :: Int -> ListUsersResponse -> ShowS
Show, Typeable)

instance ResponseConsumer ListUsers ListUsersResponse where
    type ResponseMetadata ListUsersResponse = IamMetadata
    responseConsumer :: Request
-> ListUsers
-> IORef (ResponseMetadata ListUsersResponse)
-> HTTPResponseConsumer ListUsersResponse
responseConsumer Request
_ ListUsers
_
        = forall a.
(Cursor -> Response IamMetadata a)
-> IORef IamMetadata -> HTTPResponseConsumer a
iamResponseConsumer forall a b. (a -> b) -> a -> b
$ \Cursor
cursor -> do
            (Bool
lurIsTruncated, Maybe Text
lurMarker) <- forall (m :: * -> *).
MonadThrow m =>
Cursor -> m (Bool, Maybe Text)
markedIterResponse Cursor
cursor
            [User]
lurUsers <- 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 User
parseUser
            forall (m :: * -> *) a. Monad m => a -> m a
return ListUsersResponse{Bool
[User]
Maybe Text
lurUsers :: [User]
lurMarker :: Maybe Text
lurIsTruncated :: Bool
lurMarker :: Maybe Text
lurIsTruncated :: Bool
lurUsers :: [User]
..}

instance Transaction ListUsers ListUsersResponse

instance IteratedTransaction ListUsers ListUsersResponse where
    nextIteratedRequest :: ListUsers -> ListUsersResponse -> Maybe ListUsers
nextIteratedRequest ListUsers
request ListUsersResponse
response
        = case ListUsersResponse -> Maybe Text
lurMarker ListUsersResponse
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
$ ListUsers
request { luMarker :: Maybe Text
luMarker = forall a. a -> Maybe a
Just Text
marker }

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