Example #1
0
    def call(self, request):
        '''Make API call and translate AWSServiceException to more specific exception'''
        try:
            log.debug(request)
            return_msg = self._client.call(request, self._format)
            log.debug('Request ID: {0}'.format(list(return_msg.json().values())[0]\
                                                ['ResponseMetadata']['RequestId']))

            #TODO: set more specific charset code
            return return_msg.json()

        except AwsServiceException as ex:
            log.debug(misc.to_unicode(ex))

            # Translate general Elastic Beanstalk exception
            if misc.string_equal_ignore_case(ex.code,
                                             AwsErrorCode.OptInRequired):
                raise OptInRequiredException(ex)

            if misc.string_equal_ignore_case(
                    ex.code, AwsErrorCode.InsufficientPrivileges):
                raise InsufficientPrivilegesException(ex)

            if misc.string_equal_ignore_case(
                    ex.code, AwsErrorCode.InvalidParameterValue):
                raise InvalidParameterValueException(ex)

            if misc.string_equal_ignore_case(ex.code,
                                             AwsErrorCode.MissingParameter):
                raise MissingParameterException(ex)

            raise
Example #2
0
    def call(self, request):
        '''Make API call and translate AWSServiceException to more specific exception'''
        try:
            log.debug(request)
            return_msg = self._client.call(request, self._format)
            log.debug(u'Request ID: {0}'.format(return_msg.json().values()[0]\
                                                [u'ResponseMetadata'][u'RequestId']))

            return return_msg.json()

        except AwsServiceException as ex:
            log.debug(misc.to_unicode(ex))

            # Translate general IAM exception
            if misc.string_equal_ignore_case(ex.code,
                                             AwsErrorCode.AccessDenied):
                raise AccessDeniedException(ex)

            elif misc.string_equal_ignore_case(ex.code,
                                               AwsErrorCode.OptInRequired):
                raise OptInRequiredException(ex)

            elif misc.string_equal_ignore_case(
                    ex.code, AwsErrorCode.InsufficientPrivileges):
                raise InsufficientPrivilegesException(ex)

            elif misc.string_equal_ignore_case(
                    ex.code, AwsErrorCode.InvalidParameterValue):
                raise InvalidParameterValueException(ex)

            elif misc.string_equal_ignore_case(ex.code,
                                               AwsErrorCode.MissingParameter):
                raise MissingParameterException(ex)

            elif misc.string_equal_ignore_case(
                    ex.code, IamErrorCode.EntityAlreadyExists):
                raise IamEntityAlreadyExistsException(ex)

            elif misc.string_equal_ignore_case(ex.code,
                                               IamErrorCode.NoSuchEntity):
                raise IamNoSuchEntityException(ex)

            elif misc.string_equal_ignore_case(
                    ex.code, IamErrorCode.MalformedPolicyDocument):
                raise IamMalformedPolicyDocumentException(ex)

            elif misc.string_equal_ignore_case(ex.code,
                                               IamErrorCode.LimitExceeded):
                raise IamLimitExceededException(ex)

            raise