Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 3
0
    def validate_configuration_settings(self,
                                        application_name=None,
                                        option_settings=None,
                                        environment_name=None,
                                        template=None,
                                        version_label=None,
                                        option_remove=None,
                                        template_specification=None):
        request = Request()
        request.set_operation('ValidateConfigurationSettings')
        if application_name is not None:
            request.set_app_name(application_name)
        if option_settings is not None:
            request.set_option_settings(option_settings)
        if environment_name is not None:
            request.set_env_name(environment_name)
        if template is not None:
            request.set_template(template)
        if version_label is not None:
            request.set_version_label(version_label)
        if option_remove is not None:
            request.set_options_to_remove(option_remove)
        if template_specification is not None:
            request.set_template_specification(template_specification)

        try:
            response = self.call(request)
        except AwsServiceException as ex:
            if ex.code.lower() == AwsErrorCode.InsufficientPrivileges.lower():
                raise InsufficientPrivilegesException(ex)
            if ex.code.lower() == AwsErrorCode.MissingParameter.lower():
                raise MissingParameterException(ex)
            if ex.code.lower() == AwsErrorCode.InvalidParameterValue.lower():
                raise InvalidParameterValueException(ex)
            raise

        results = response['ValidateConfigurationSettingsResponse']\
            ['ValidateConfigurationSettingsResult']['Messages']
        request_id = response['ValidateConfigurationSettingsResponse']\
            ['ResponseMetadata']['RequestId']

        messages = []
        if results is not None:
            for result in results:
                messages.append(ValidationMessage.from_json(result))
        return Response(request_id, messages)