Exemplo n.º 1
0
    def run(self):
        """
        Compare argument to AWS Account Id.

        :raises: InvalidHookArgumentSyntaxError, if argument is not a valid 
                 AWS Account Id.
        """

        account_id_re = re.compile(r'\d{12}')
        if not (self.argument and account_id_re.match(self.argument)):
            raise InvalidHookArgumentSyntaxError(
                '{}: argument "{}" is not a valid AWS account Id.'.format(
                    __name__, self.argument))

        response = self.stack.connection_manager.call(
            service="sts",
            command="get_caller_identity",
        )
        account_id = response["Account"]

        if not account_id == self.argument:
            raise SceptreException(
                '{}: account verification failed - current account "{}" does '
                'not match specified account Id "{}".'.format(
                    __name__, account_id, self.argument))
        else:
            self.logger.debug('{} - verification succeeded for Id {}'.format(
                __name__, account_id))
            return True
Exemplo n.º 2
0
    def test_invalid_response_reraises_exception(self):
        connection_manager = MagicMock(spec=ConnectionManager)
        connection_manager.call.side_effect = SceptreException("BOOM!")

        template_handler = S3(
            name="vpc",
            arguments={"path": "my-fancy-bucket/account/vpc.yaml"},
            connection_manager=connection_manager)

        with pytest.raises(SceptreException) as e:
            template_handler.handle()

        assert str(e.value) == "BOOM!"
Exemplo n.º 3
0
 def raises_exception():
     raise SceptreException()