コード例 #1
0
    def refresh(self):
        """Load dynamic credentials from the AWS Instance Metadata and user
        data HTTP API.

        :raises: tornado_aws.exceptions.NoCredentialsError

        """
        LOGGER.debug('Refreshing EC2 IAM Credentials')
        async = isinstance(self._client, httpclient.AsyncHTTPClient)
        future = concurrent.TracebackFuture() if async else None
        try:
            result = self._fetch_credentials(async)
            if concurrent.is_future(result):

                def on_complete(response):
                    exception = response.exception()
                    if exception:
                        if isinstance(exception, httpclient.HTTPError) and \
                                exception.code == 599:
                            future.set_exception(
                                exceptions.NoCredentialsError())
                        else:
                            future.set_exception(exception)
                        return
                    self._assign_credentials(response.result())
                    future.set_result(True)

                self._ioloop.add_future(result, on_complete)
            else:
                self._assign_credentials(result)
        except (httpclient.HTTPError, OSError) as error:
            LOGGER.error('Error Fetching Credentials: %s', error)
            raise exceptions.NoCredentialsError()
        return future
コード例 #2
0
 def on_complete(response):
     exception = response.exception()
     if exception:
         if isinstance(exception, httpclient.HTTPError) and \
                 exception.code == 599:
             future.set_exception(
                 exceptions.NoCredentialsError())
         else:
             future.set_exception(exception)
         return
     self._assign_credentials(response.result())
     future.set_result(True)
コード例 #3
0
 def test_raises_no_credentials_error(self):
     with mock.patch('tornado_aws.client.AsyncAWSClient.fetch') as fetch:
         fetch.side_effect = aws_exceptions.NoCredentialsError()
         with self.assertRaises(exceptions.NoCredentialsError):
             yield self.client.create_table(self.generic_table_definition())