예제 #1
0
    def __call__(self, req):
        """Generate a WSGI response based on the exception passed to ctor."""
        code = self.wrapped_exc.status_int
        message = self.wrapped_exc.explanation

        if code == 501:
            message = "The requested function is not supported"
        code = str(code)

        if "AWSAccessKeyId" not in req.params:
            raise webob.exc.HTTPBadRequest()
        user_id, _sep, project_id = req.params["AWSAccessKeyId"].partition(":")
        project_id = project_id or user_id
        remote_address = getattr(req, "remote_address", "127.0.0.1")
        if FLAGS.use_forwarded_for:
            remote_address = req.headers.get("X-Forwarded-For", remote_address)

        ctxt = context.RequestContext(user_id, project_id, remote_address=remote_address)

        resp = webob.Response()
        resp.status = self.wrapped_exc.status_int
        resp.headers["Content-Type"] = "text/xml"
        resp.body = str(
            '<?xml version="1.0"?>\n'
            "<Response><Errors><Error><Code>%s</Code>"
            "<Message>%s</Message></Error></Errors>"
            "<RequestID>%s</RequestID></Response>"
            % (utils.utf8(code), utils.utf8(message), utils.utf8(ctxt.request_id))
        )

        return resp
예제 #2
0
def cloudwatch_error(req, request_id, code, message):
    """Helper to send an cloudwatch_compatible error"""
    LOG.error(_('%(code)s: %(message)s') % locals())
    resp = webob.Response()
    resp.status = code
    resp.headers['Content-Type'] = 'text/xml'
    resp.body = str('<?xml version="1.0"?>\n'
                    '<ErrorResponse xmlns="http://monitoring.amazonaws.com/doc/2010-08-01/">'
                    '<Error><Code>%s</Code><Message>%s</Message></Error>'
                    '<RequestId>%s</RequestId></ErrorResponse>' % 
                    (code, utils.utf8(message), utils.utf8(request_id)))
    return resp
예제 #3
0
def cloudwatch_error(req, request_id, code, message):
    """Helper to send an cloudwatch_compatible error"""
    LOG.error(_('%(code)s: %(message)s') % locals())
    resp = webob.Response()
    resp.status = code
    resp.headers['Content-Type'] = 'text/xml'
    resp.body = str('<?xml version="1.0"?>\n'
                    '<ErrorResponse xmlns="http://monitoring.amazonaws.com/doc/2010-08-01/">'
                    '<Error><Code>%s</Code><Message>%s</Message></Error>'
                    '<RequestId>%s</RequestId></ErrorResponse>' % 
                    (code, utils.utf8(message), utils.utf8(request_id)))
    return resp
예제 #4
0
파일: faults.py 프로젝트: akshatknsl/synaps
def ec2_error_response(request_id, code, message, status=500):
    """Helper to construct an EC2 compatible error reposne."""
    LOG.debug(_('EC2 error response: %(code)s: %(message)s') %
                {'code': code, 'message': message})
    resp = webob.Response()
    resp.status = status
    resp.headers['Content-Type'] = 'text/xml'
    resp.body = str('<?xml version="1.0"?>\n'
                    '<ErrorResponse xmlns="http://monitoring.amazonaws.com/doc/2010-08-01/">'
                    '<Error><Code>%s</Code><Message>%s</Message></Error>'
                    '<RequestId>%s</RequestId></ErrorResponse>' %
                    (utils.xhtml_escape(utils.utf8(code)),
                     utils.xhtml_escape(utils.utf8(message)),
                     utils.xhtml_escape(utils.utf8(request_id))))
    return resp
예제 #5
0
 def parse_filter(filter_dict):
     if not filter_dict:
         return None
     
     full_filter, name_filter, value_filter = [], [], []
     
     for k, v in filter_dict.iteritems():
         k, v = utils.utf8(k), utils.utf8(v)
         if k and v:
             full_filter.append((k, v))
         elif k and not v:
             name_filter.append(k)
         elif not k and v:
             value_filter.append(v)
         else:
             msg = "Invalid dimension filter - both name and value "\
                   "can not be empty."
             raise exception.InvalidRequest(msg)
     
     return full_filter, name_filter, value_filter        
예제 #6
0
        def parse_filter(filter_dict):
            if not filter_dict:
                return None

            full_filter, name_filter, value_filter = [], [], []

            for k, v in filter_dict.iteritems():
                k, v = utils.utf8(k), utils.utf8(v)
                if k and v:
                    full_filter.append((k, v))
                elif k and not v:
                    name_filter.append(k)
                elif not k and v:
                    value_filter.append(v)
                else:
                    msg = "Invalid dimension filter - both name and value "\
                          "can not be empty."
                    raise exception.InvalidRequest(msg)

            return full_filter, name_filter, value_filter
예제 #7
0
        def apply_filter(metric, filters):
            if not filters:
                return True

            dimensions = metric.get('dimensions')
            dimensions = json.loads(dimensions) if dimensions else {}
            full_filter, name_filter, value_filter = filters
            
            if full_filter:
                if not set(full_filter).issubset(set(dimensions.items())):
                    return False
            
            if name_filter:
                if set(dimensions.keys()) != set(name_filter):
                    return False
                
            if value_filter:
                for v_in_dim in dimensions.values():
                    for v in value_filter:
                        if v in utils.utf8(v_in_dim):
                            return True
                return False
            return True
예제 #8
0
        def apply_filter(metric, filters):
            if not filters:
                return True

            dimensions = metric.get('dimensions')
            dimensions = json.loads(dimensions) if dimensions else {}
            full_filter, name_filter, value_filter = filters

            if full_filter:
                if not set(full_filter).issubset(set(dimensions.items())):
                    return False

            if name_filter:
                if set(dimensions.keys()) != set(name_filter):
                    return False

            if value_filter:
                for v_in_dim in dimensions.values():
                    for v in value_filter:
                        if v in utils.utf8(v_in_dim):
                            return True
                return False
            return True
예제 #9
0
 def _build_mc_key(self, user, role, project=None):
     key_parts = ['rolecache', User.safe_id(user), str(role)]
     if project:
         key_parts.append(Project.safe_id(project))
     return utils.utf8('-'.join(key_parts))
예제 #10
0
 def _build_mc_key(self, user, role, project=None):
     key_parts = ['rolecache', User.safe_id(user), str(role)]
     if project:
         key_parts.append(Project.safe_id(project))
     return utils.utf8('-'.join(key_parts))