{-# 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.IoT.TestAuthorization
(
testAuthorization
, TestAuthorization
, taClientId
, taPolicyNamesToAdd
, taPrincipal
, taCognitoIdentityPoolId
, taPolicyNamesToSkip
, taAuthInfos
, testAuthorizationResponse
, TestAuthorizationResponse
, tarsAuthResults
, tarsResponseStatus
) where
import Network.AWS.IoT.Types
import Network.AWS.IoT.Types.Product
import Network.AWS.Lens
import Network.AWS.Prelude
import Network.AWS.Request
import Network.AWS.Response
data TestAuthorization = TestAuthorization'
{ _taClientId :: !(Maybe Text)
, _taPolicyNamesToAdd :: !(Maybe [Text])
, _taPrincipal :: !(Maybe Text)
, _taCognitoIdentityPoolId :: !(Maybe Text)
, _taPolicyNamesToSkip :: !(Maybe [Text])
, _taAuthInfos :: !(List1 AuthInfo)
} deriving (Eq, Read, Show, Data, Typeable, Generic)
testAuthorization
:: NonEmpty AuthInfo
-> TestAuthorization
testAuthorization pAuthInfos_ =
TestAuthorization'
{ _taClientId = Nothing
, _taPolicyNamesToAdd = Nothing
, _taPrincipal = Nothing
, _taCognitoIdentityPoolId = Nothing
, _taPolicyNamesToSkip = Nothing
, _taAuthInfos = _List1 # pAuthInfos_
}
taClientId :: Lens' TestAuthorization (Maybe Text)
taClientId = lens _taClientId (\ s a -> s{_taClientId = a})
taPolicyNamesToAdd :: Lens' TestAuthorization [Text]
taPolicyNamesToAdd = lens _taPolicyNamesToAdd (\ s a -> s{_taPolicyNamesToAdd = a}) . _Default . _Coerce
taPrincipal :: Lens' TestAuthorization (Maybe Text)
taPrincipal = lens _taPrincipal (\ s a -> s{_taPrincipal = a})
taCognitoIdentityPoolId :: Lens' TestAuthorization (Maybe Text)
taCognitoIdentityPoolId = lens _taCognitoIdentityPoolId (\ s a -> s{_taCognitoIdentityPoolId = a})
taPolicyNamesToSkip :: Lens' TestAuthorization [Text]
taPolicyNamesToSkip = lens _taPolicyNamesToSkip (\ s a -> s{_taPolicyNamesToSkip = a}) . _Default . _Coerce
taAuthInfos :: Lens' TestAuthorization (NonEmpty AuthInfo)
taAuthInfos = lens _taAuthInfos (\ s a -> s{_taAuthInfos = a}) . _List1
instance AWSRequest TestAuthorization where
type Rs TestAuthorization = TestAuthorizationResponse
request = postJSON ioT
response
= receiveJSON
(\ s h x ->
TestAuthorizationResponse' <$>
(x .?> "authResults" .!@ mempty) <*>
(pure (fromEnum s)))
instance Hashable TestAuthorization where
instance NFData TestAuthorization where
instance ToHeaders TestAuthorization where
toHeaders = const mempty
instance ToJSON TestAuthorization where
toJSON TestAuthorization'{..}
= object
(catMaybes
[("policyNamesToAdd" .=) <$> _taPolicyNamesToAdd,
("principal" .=) <$> _taPrincipal,
("cognitoIdentityPoolId" .=) <$>
_taCognitoIdentityPoolId,
("policyNamesToSkip" .=) <$> _taPolicyNamesToSkip,
Just ("authInfos" .= _taAuthInfos)])
instance ToPath TestAuthorization where
toPath = const "/test-authorization"
instance ToQuery TestAuthorization where
toQuery TestAuthorization'{..}
= mconcat ["clientId" =: _taClientId]
data TestAuthorizationResponse = TestAuthorizationResponse'
{ _tarsAuthResults :: !(Maybe [AuthResult])
, _tarsResponseStatus :: !Int
} deriving (Eq, Read, Show, Data, Typeable, Generic)
testAuthorizationResponse
:: Int
-> TestAuthorizationResponse
testAuthorizationResponse pResponseStatus_ =
TestAuthorizationResponse'
{_tarsAuthResults = Nothing, _tarsResponseStatus = pResponseStatus_}
tarsAuthResults :: Lens' TestAuthorizationResponse [AuthResult]
tarsAuthResults = lens _tarsAuthResults (\ s a -> s{_tarsAuthResults = a}) . _Default . _Coerce
tarsResponseStatus :: Lens' TestAuthorizationResponse Int
tarsResponseStatus = lens _tarsResponseStatus (\ s a -> s{_tarsResponseStatus = a})
instance NFData TestAuthorizationResponse where