{-# 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
(ListUsers -> ListUsers -> Bool)
-> (ListUsers -> ListUsers -> Bool) -> Eq ListUsers
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
Eq ListUsers
-> (ListUsers -> ListUsers -> Ordering)
-> (ListUsers -> ListUsers -> Bool)
-> (ListUsers -> ListUsers -> Bool)
-> (ListUsers -> ListUsers -> Bool)
-> (ListUsers -> ListUsers -> Bool)
-> (ListUsers -> ListUsers -> ListUsers)
-> (ListUsers -> ListUsers -> ListUsers)
-> Ord 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
$cp1Ord :: Eq ListUsers
Ord, Int -> ListUsers -> ShowS
[ListUsers] -> ShowS
ListUsers -> String
(Int -> ListUsers -> ShowS)
-> (ListUsers -> String)
-> ([ListUsers] -> ShowS)
-> Show ListUsers
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 :: 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
..}
        = ByteString
-> [Maybe (ByteString, Text)]
-> IamConfiguration queryType
-> SignatureData
-> SignedQuery
forall qt.
ByteString
-> [Maybe (ByteString, Text)]
-> IamConfiguration qt
-> SignatureData
-> SignedQuery
iamAction' ByteString
"ListUsers" ([Maybe (ByteString, Text)]
 -> IamConfiguration queryType -> SignatureData -> SignedQuery)
-> [Maybe (ByteString, Text)]
-> IamConfiguration queryType
-> SignatureData
-> SignedQuery
forall a b. (a -> b) -> a -> b
$ [
              (ByteString
"PathPrefix",) (Text -> (ByteString, Text))
-> Maybe Text -> Maybe (ByteString, Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
luPathPrefix
            ] [Maybe (ByteString, Text)]
-> [Maybe (ByteString, Text)] -> [Maybe (ByteString, Text)]
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
(ListUsersResponse -> ListUsersResponse -> Bool)
-> (ListUsersResponse -> ListUsersResponse -> Bool)
-> Eq ListUsersResponse
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
Eq ListUsersResponse
-> (ListUsersResponse -> ListUsersResponse -> Ordering)
-> (ListUsersResponse -> ListUsersResponse -> Bool)
-> (ListUsersResponse -> ListUsersResponse -> Bool)
-> (ListUsersResponse -> ListUsersResponse -> Bool)
-> (ListUsersResponse -> ListUsersResponse -> Bool)
-> (ListUsersResponse -> ListUsersResponse -> ListUsersResponse)
-> (ListUsersResponse -> ListUsersResponse -> ListUsersResponse)
-> Ord 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
$cp1Ord :: Eq ListUsersResponse
Ord, Int -> ListUsersResponse -> ShowS
[ListUsersResponse] -> ShowS
ListUsersResponse -> String
(Int -> ListUsersResponse -> ShowS)
-> (ListUsersResponse -> String)
-> ([ListUsersResponse] -> ShowS)
-> Show ListUsersResponse
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
_
        = (Cursor -> Response IamMetadata ListUsersResponse)
-> IORef IamMetadata -> HTTPResponseConsumer ListUsersResponse
forall a.
(Cursor -> Response IamMetadata a)
-> IORef IamMetadata -> HTTPResponseConsumer a
iamResponseConsumer ((Cursor -> Response IamMetadata ListUsersResponse)
 -> IORef IamMetadata -> HTTPResponseConsumer ListUsersResponse)
-> (Cursor -> Response IamMetadata ListUsersResponse)
-> IORef IamMetadata
-> HTTPResponseConsumer ListUsersResponse
forall a b. (a -> b) -> a -> b
$ \Cursor
cursor -> do
            (Bool
lurIsTruncated, Maybe Text
lurMarker) <- Cursor -> Response IamMetadata (Bool, Maybe Text)
forall (m :: * -> *).
MonadThrow m =>
Cursor -> m (Bool, Maybe Text)
markedIterResponse Cursor
cursor
            [User]
lurUsers <- [Response IamMetadata User] -> Response IamMetadata [User]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([Response IamMetadata User] -> Response IamMetadata [User])
-> [Response IamMetadata User] -> Response IamMetadata [User]
forall a b. (a -> b) -> a -> b
$
                Cursor
cursor Cursor
-> (Cursor -> [Response IamMetadata User])
-> [Response IamMetadata User]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Axis
laxElement Text
"member" Axis
-> (Cursor -> Response IamMetadata User)
-> Cursor
-> [Response IamMetadata User]
forall node a b.
(Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
&| Cursor -> Response IamMetadata User
forall (m :: * -> *). MonadThrow m => Cursor -> m User
parseUser
            ListUsersResponse -> Response IamMetadata ListUsersResponse
forall (m :: * -> *) a. Monad m => a -> m a
return ListUsersResponse :: [User] -> Bool -> Maybe Text -> ListUsersResponse
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     -> Maybe ListUsers
forall a. Maybe a
Nothing
            Just Text
marker -> ListUsers -> Maybe ListUsers
forall a. a -> Maybe a
Just (ListUsers -> Maybe ListUsers) -> ListUsers -> Maybe ListUsers
forall a b. (a -> b) -> a -> b
$ ListUsers
request { luMarker :: Maybe Text
luMarker = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
marker }

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