{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}
module Network.AWS.SSM.ListCommands
(
listCommands
, ListCommands
, lcInstanceId
, lcFilters
, lcNextToken
, lcCommandId
, lcMaxResults
, listCommandsResponse
, ListCommandsResponse
, lcrsCommands
, lcrsNextToken
, lcrsResponseStatus
) where
import Network.AWS.Lens
import Network.AWS.Pager
import Network.AWS.Prelude
import Network.AWS.Request
import Network.AWS.Response
import Network.AWS.SSM.Types
import Network.AWS.SSM.Types.Product
data ListCommands = ListCommands'
{ _lcInstanceId :: !(Maybe Text)
, _lcFilters :: !(Maybe (List1 CommandFilter))
, _lcNextToken :: !(Maybe Text)
, _lcCommandId :: !(Maybe Text)
, _lcMaxResults :: !(Maybe Nat)
} deriving (Eq, Read, Show, Data, Typeable, Generic)
listCommands
:: ListCommands
listCommands =
ListCommands'
{ _lcInstanceId = Nothing
, _lcFilters = Nothing
, _lcNextToken = Nothing
, _lcCommandId = Nothing
, _lcMaxResults = Nothing
}
lcInstanceId :: Lens' ListCommands (Maybe Text)
lcInstanceId = lens _lcInstanceId (\ s a -> s{_lcInstanceId = a})
lcFilters :: Lens' ListCommands (Maybe (NonEmpty CommandFilter))
lcFilters = lens _lcFilters (\ s a -> s{_lcFilters = a}) . mapping _List1
lcNextToken :: Lens' ListCommands (Maybe Text)
lcNextToken = lens _lcNextToken (\ s a -> s{_lcNextToken = a})
lcCommandId :: Lens' ListCommands (Maybe Text)
lcCommandId = lens _lcCommandId (\ s a -> s{_lcCommandId = a})
lcMaxResults :: Lens' ListCommands (Maybe Natural)
lcMaxResults = lens _lcMaxResults (\ s a -> s{_lcMaxResults = a}) . mapping _Nat
instance AWSPager ListCommands where
page rq rs
| stop (rs ^. lcrsNextToken) = Nothing
| stop (rs ^. lcrsCommands) = Nothing
| otherwise =
Just $ rq & lcNextToken .~ rs ^. lcrsNextToken
instance AWSRequest ListCommands where
type Rs ListCommands = ListCommandsResponse
request = postJSON ssm
response
= receiveJSON
(\ s h x ->
ListCommandsResponse' <$>
(x .?> "Commands" .!@ mempty) <*> (x .?> "NextToken")
<*> (pure (fromEnum s)))
instance Hashable ListCommands where
instance NFData ListCommands where
instance ToHeaders ListCommands where
toHeaders
= const
(mconcat
["X-Amz-Target" =#
("AmazonSSM.ListCommands" :: ByteString),
"Content-Type" =#
("application/x-amz-json-1.1" :: ByteString)])
instance ToJSON ListCommands where
toJSON ListCommands'{..}
= object
(catMaybes
[("InstanceId" .=) <$> _lcInstanceId,
("Filters" .=) <$> _lcFilters,
("NextToken" .=) <$> _lcNextToken,
("CommandId" .=) <$> _lcCommandId,
("MaxResults" .=) <$> _lcMaxResults])
instance ToPath ListCommands where
toPath = const "/"
instance ToQuery ListCommands where
toQuery = const mempty
data ListCommandsResponse = ListCommandsResponse'
{ _lcrsCommands :: !(Maybe [Command])
, _lcrsNextToken :: !(Maybe Text)
, _lcrsResponseStatus :: !Int
} deriving (Eq, Read, Show, Data, Typeable, Generic)
listCommandsResponse
:: Int
-> ListCommandsResponse
listCommandsResponse pResponseStatus_ =
ListCommandsResponse'
{ _lcrsCommands = Nothing
, _lcrsNextToken = Nothing
, _lcrsResponseStatus = pResponseStatus_
}
lcrsCommands :: Lens' ListCommandsResponse [Command]
lcrsCommands = lens _lcrsCommands (\ s a -> s{_lcrsCommands = a}) . _Default . _Coerce
lcrsNextToken :: Lens' ListCommandsResponse (Maybe Text)
lcrsNextToken = lens _lcrsNextToken (\ s a -> s{_lcrsNextToken = a})
lcrsResponseStatus :: Lens' ListCommandsResponse Int
lcrsResponseStatus = lens _lcrsResponseStatus (\ s a -> s{_lcrsResponseStatus = a})
instance NFData ListCommandsResponse where