コード例 #1
0
def _validate_dimension_value(value):
    try:
        value[0]
        if len(value) > DIMENSION_VALUE_CONSTRAINTS['MAX_LENGTH']:
            raise exceptions.HTTPUnprocessableEntity(
                'Dimension value %s must be 255 characters or less' % value)
    except (TypeError, IndexError):
        raise exceptions.HTTPUnprocessableEntity(
            'Dimension value cannot be empty')
コード例 #2
0
def _validate_dimension_name(name):
    try:
        if len(name) > DIMENSION_NAME_CONSTRAINTS['MAX_LENGTH']:
            raise exceptions.HTTPUnprocessableEntity(
                'Dimension name %s must be 255 characters or less' % name)
        if name[0] == '_':
            raise exceptions.HTTPUnprocessableEntity(
                'Dimension name %s cannot start with underscore (_)' % name)
        if not DIMENSION_NAME_CONSTRAINTS['PATTERN'].match(name):
            raise exceptions.HTTPUnprocessableEntity(
                'Dimension name %s may not contain: %s' %
                (name, '> < = { } ( ) \' " , ; &'))
    except (TypeError, IndexError):
        raise exceptions.HTTPUnprocessableEntity(
            'Dimension name cannot be empty')
コード例 #3
0
ファイル: logs.py プロジェクト: libeau0911/monasca-api
 def _get_logs(request_body):
     """Get the logs in the HTTP request body."""
     if request_body is None:
         raise falcon.HTTPBadRequest('Bad request', 'Request body is Empty')
     if 'logs' not in request_body:
         raise exceptions.HTTPUnprocessableEntity(
             'Unprocessable Entity Logs not found')
     return request_body['logs']
コード例 #4
0
 def validate_length():
     if (len(application_type) >
             APPLICATION_TYPE_CONSTRAINTS['MAX_LENGTH']):
         msg = ('Application type {type} must be '
                '{length} characters or less')
         raise exceptions.HTTPUnprocessableEntity(
             msg.format(type=application_type,
                        length=APPLICATION_TYPE_CONSTRAINTS['MAX_LENGTH']))
コード例 #5
0
def validate_log_message(log_object):
    """Validates log property.

    Log property should have message property.

    Args:
        log_object (dict): log property
       """
    if 'message' not in log_object:
        raise exceptions.HTTPUnprocessableEntity(
            'Log property should have message')
コード例 #6
0
def validate_dimensions(dimensions):
    """Validates dimensions type.

       Empty dimensions are not being validated.
       For details see:

       :param dict dimensions: dimensions to validate

       * :py:data:`DIMENSION_NAME_CONSTRAINTS`
       * :py:data:`DIMENSION_VALUE_CONSTRAINTS`
       """
    try:
        for dim_name, dim_value in dimensions.items():
            _validate_dimension_name(dim_name)
            _validate_dimension_value(dim_value)
    except AttributeError:
        raise exceptions.HTTPUnprocessableEntity(
            'Dimensions %s must be a dictionary (map)' % dimensions)
コード例 #7
0
ファイル: helpers.py プロジェクト: chaconpiza/monasca-api
def get_logs(request_body):
    """Get the logs in the HTTP request body."""
    if 'logs' not in request_body:
        raise exceptions.HTTPUnprocessableEntity(
            'Unprocessable Entity Logs not found')
    return request_body['logs']
コード例 #8
0
 def validate_match():
     if (not APPLICATION_TYPE_CONSTRAINTS['PATTERN'].match(application_type)
         ):
         raise exceptions.HTTPUnprocessableEntity(
             'Application type %s may only contain: "a-z A-Z 0-9 _ - ."' %
             application_type)