Exemplo n.º 1
0
    def test_role_data_extraction_exception_handling(self):
        with self.assertRaises(SystemExit) as sys_exit:
            region = self.region_mock
            mock_credentials = {
                "Credentials": {
                    "AccessKeyId": "mocked_aws_access_key_id",
                }
            }

            instance = AbstractionLayer(region)
            instance.role_data_extraction(mock_credentials)

        self.assertEqual(sys_exit.exception.code, 1)
Exemplo n.º 2
0
    def test_role_data_extraction_try_catch(self):

        region = self.region_mock
        mock_credentials = {
            "Credentials": {
                "AccessKeyId": "mocked_aws_access_key_id",
                "SecretAccessKey": "mocked_aws_access_secret",
                "SessionToken": "mocked_aws_session_token",
            }
        }

        instance = AbstractionLayer(region)
        instance.role_data_extraction(mock_credentials)
def ingest_api_call(response):
    # Logging attributes status for the spinned instances using AssumeRole methodology

    if response["roleArn"]:
        try:
            aws_obj = LayerClass(region=response["region"])
            assume_role = aws_obj.aws_sts_role(api_call=response["apis"],
                                               role_arn=response["roleArn"])
            credentials = aws_obj.role_data_extraction(
                assume_role_credentials=assume_role)
            logger.debug("STS rule controller for AWS ")

        except Exception as err:
            logger.exception("Logging STS Error: " + str(err) + "\n")
            sys.exit(1)

        else:
            return credentials

    else:
        logger.exception("Role ARN missing to execute the Boto3 API call ! ")
        sys.exit(1)