Tests if a specified principal is authorized to perform an IoT action on a specified resource. Use this to test and debug the authorization behavior of devices that connect to the IoT device gateway.
Requires permission to access the TestAuthorization action.
Parameters:
-
principal
(Optional[Principal], default:
None
)
–
The principal. Valid principals are CertificateArn (arn:aws:iot:region:accountId:cert/certificateId) and CognitoId (region:id).
-
cognito_identity_pool_id
(Optional[CognitoIdentityPoolId], default:
None
)
–
The Cognito identity pool ID.
-
auth_infos
(AuthInfos)
–
A list of authorization info objects. Simulating authorization will create a response for each authInfo object in the list.
-
client_id
(Optional[ClientId], default:
None
)
–
-
policy_names_to_add
(Optional[PolicyNames], default:
None
)
–
When testing custom authorization, the policies specified here are treated as if they are attached to the principal being authorized.
-
policy_names_to_skip
(Optional[PolicyNames], default:
None
)
–
When testing custom authorization, the policies specified here are treated as if they are not attached to the principal being authorized.
Raises:
Source code in docs_src/capo_iot/_services/io_t.py
| def test_authorization(
self,
auth_infos: "capo_iot.types.auth_infos.AuthInfos",
*,
config_overrides: Optional[IoTClientConfig] = None,
principal: Optional["capo_iot.types.principal.Principal"] = None,
cognito_identity_pool_id: Optional[
"capo_iot.types.cognito_identity_pool_id.CognitoIdentityPoolId"
] = None,
client_id: Optional["capo_iot.types.client_id.ClientId"] = None,
policy_names_to_add: Optional["capo_iot.types.policy_names.PolicyNames"] = None,
policy_names_to_skip: Optional[
"capo_iot.types.policy_names.PolicyNames"
] = None,
) -> "capo_iot.types.test_authorization_response.TestAuthorizationResponse":
"""<p>Tests if a specified principal is authorized to perform an IoT action on a specified resource. Use this to test and debug the authorization behavior of devices that connect to the IoT device gateway.</p> <p>Requires permission to access the <a href="https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions">TestAuthorization</a> action.</p>
Args:
principal: <p>The principal. Valid principals are CertificateArn (arn:aws:iot:<i>region</i>:<i>accountId</i>:cert/<i>certificateId</i>) and CognitoId (<i>region</i>:<i>id</i>).</p>
cognito_identity_pool_id: <p>The Cognito identity pool ID.</p>
auth_infos: <p>A list of authorization info objects. Simulating authorization will create a response for each <code>authInfo</code> object in the list.</p>
client_id: <p>The MQTT client ID.</p>
policy_names_to_add: <p>When testing custom authorization, the policies specified here are treated as if they are attached to the principal being authorized.</p>
policy_names_to_skip: <p>When testing custom authorization, the policies specified here are treated as if they are not attached to the principal being authorized.</p>
Raises:
capo_iot.errors.internal_failure_exception.InternalFailureException: <p>An unexpected error has occurred.</p>
capo_iot.errors.invalid_request_exception.InvalidRequestException: <p>The request is not valid.</p>
capo_iot.errors.limit_exceeded_exception.LimitExceededException: <p>A limit has been exceeded.</p>
capo_iot.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource does not exist.</p>
capo_iot.errors.service_unavailable_exception.ServiceUnavailableException: <p>The service is temporarily unavailable.</p>
capo_iot.errors.throttling_exception.ThrottlingException: <p>The rate exceeds the limit.</p>
capo_iot.errors.unauthorized_exception.UnauthorizedException: <p>You are not authorized to perform this operation.</p>
capo_iot.errors.UnknownServiceError: The service returned an error code this client does not model.
"""
def _handler(
req: "OperationRequest[capo_iot.types.test_authorization_request.TestAuthorizationRequest]",
) -> OperationResponse[
"capo_iot.types.test_authorization_response.TestAuthorizationResponse"
]:
import capo_iot._operations.aws_iot_service.test_authorization
output, http_response = (
capo_iot._operations.aws_iot_service.test_authorization.test_authorization(
req.options, req.input
)
)
return OperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("TestAuthorization")
)
input_: capo_iot.types.test_authorization_request.TestAuthorizationRequest = {
"auth_infos": auth_infos
}
if principal is not None:
input_["principal"] = principal
if cognito_identity_pool_id is not None:
input_["cognito_identity_pool_id"] = cognito_identity_pool_id
if client_id is not None:
input_["client_id"] = client_id
if policy_names_to_add is not None:
input_["policy_names_to_add"] = policy_names_to_add
if policy_names_to_skip is not None:
input_["policy_names_to_skip"] = policy_names_to_skip
response = execute_pipeline(
OperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
response.response.close()
return response.output
|