コード例 #1
0
ファイル: req_validate.py プロジェクト: carvalhomb/ADL_LRS
def statements_post(req_dict):
    if req_dict['params'].keys():
        raise ParamError("The post statements request contained unexpected parameters: %s" % ", ".join(req_dict['params'].keys()))

    try:
        validator = StatementValidator(req_dict['body'])
        validator.validate()
    except Exception, e:
        raise BadRequest(e.message)
コード例 #2
0
ファイル: req_validate.py プロジェクト: frasern/ADL_LRS
def statements_post(req_dict):
    if req_dict['params'].keys() and not ignore_rogue_params:
        raise ParamError("The post statements request contained unexpected parameters: %s" % ", ".join(req_dict['params'].keys()))

    if isinstance(req_dict['body'], basestring):
        req_dict['body'] = convert_to_dict(req_dict['body'])

    try:
        validator = StatementValidator(req_dict['body'])
        validator.validate()
    except Exception, e:
        raise BadRequest(e.message)
コード例 #3
0
def statements_put(req_dict):
    # Find any unexpected parameters
    rogueparams = set(req_dict['params']) - set(["statementId"])
    if rogueparams:
        raise ParamError(
            "The put statements request contained unexpected parameters: %s" % ", ".join(rogueparams))

    # Statement id can must be supplied in query param. If in the body too, it
    # must be the same
    if 'statementId' not in req_dict['params']:
        raise ParamError(
            "Error -- statements - method = %s, but no statementId parameter or ID given in statement" % req_dict['method'])
    else:
        statement_id = req_dict['params']['statementId']

    # Try to get id if in body
    try:
        statement_body_id = req_dict['body']['id']
    except Exception as e:
        statement_body_id = None

    # If ids exist in both places, check if they are equal
    if statement_body_id and statement_id != statement_body_id:
        raise ParamError(
            "Error -- statements - method = %s, param and body ID both given, but do not match" % req_dict['method'])

    # Set id inside of statement with param id
    if not statement_body_id:
        req_dict['body']['id'] = statement_id

    # If there are no other params-raise param error since nothing else is
    # supplied
    if not check_for_no_other_params_supplied(req_dict['body']):
        raise ParamError("No other params are supplied with statementId.")

    # Validate statement in body
    try:
        validator = StatementValidator(req_dict['body'])
        validator.validate()
    except Exception as e:
        raise BadRequest(e.message)
    except ParamError as e:
        raise ParamError(e.message)
    validate_body([req_dict['body']], req_dict['auth'], req_dict.get(
        'payload_sha2s', None), req_dict['headers']['CONTENT_TYPE'])
    return req_dict
コード例 #4
0
ファイル: req_validate.py プロジェクト: adlnet/ADL_LRS
def statements_post(req_dict):
    if req_dict['params'].keys():
        raise ParamError("The post statements request contained unexpected parameters: %s" % ", ".join(
            req_dict['params'].keys()))

    try:
        validator = StatementValidator(req_dict['body'])
        validator.validate()
    except Exception as e:
        raise BadRequest(e.message)
    except ParamError as e:
        raise ParamError(e.message)

    if isinstance(req_dict['body'], dict):
        body = [req_dict['body']]
    else:
        body = req_dict['body']
    validate_body(body, req_dict['auth'], req_dict['headers']['CONTENT_TYPE'])

    return req_dict
コード例 #5
0
def statements_post(req_dict):
    if req_dict['params'].keys():
        raise ParamError("The post statements request contained unexpected parameters: %s" % ", ".join(
            req_dict['params'].keys()))

    try:
        validator = StatementValidator(req_dict['body'])
        validator.validate()
    except Exception as e:
        raise BadRequest(e.message)
    except ParamError as e:
        raise ParamError(e.message)

    if isinstance(req_dict['body'], dict):
        body = [req_dict['body']]
    else:
        body = req_dict['body']
    validate_body(body, req_dict['auth'], req_dict.get(
        'payload_sha2s', None), req_dict['headers']['CONTENT_TYPE'])

    return req_dict
コード例 #6
0
ファイル: req_validate.py プロジェクト: roadlit/lrs
    # If statement with that ID already exists-raise conflict error
    if check_for_existing_statementId(statement_id):
        raise ParamConflict("A statement with ID %s already exists" % statement_id)
    
    # Set id inside of statement with param id
    if not statement_body_id:
        req_dict['body']['id'] = statement_id

    # If there are no other params-raise param error since nothing else is supplied
    if not check_for_no_other_params_supplied(req_dict['body']):
        raise ParamError("No other params are supplied with statementId.")

    # Validate statement in body
    try:
        validator = StatementValidator(req_dict['body'])
        validator.validate()
    except Exception, e:
        raise BadRequest(e.message)
    except ParamError, e:
        raise ParamError(e.message)
    validate_body([req_dict['body']], req_dict['auth'], req_dict.get('payload_sha2s', None))
    return req_dict

def validate_attachments(attachment_data, payload_sha2s):
    # For each attachment that is in the actual statement
    for attachment in attachment_data:
        # If the attachment data has a sha2 field, must validate it against the payload data
        if 'sha2' in attachment:
            sha2 = attachment['sha2']
            # Check if the sha2 field is a key in the payload dict
            if payload_sha2s:
コード例 #7
0
    if check_for_existing_statementId(statement_id):
        raise ParamConflict("A statement with ID %s already exists" %
                            statement_id)

    # Set id inside of statement with param id
    if not statement_body_id:
        req_dict['body']['id'] = statement_id

    # If there are no other params-raise param error since nothing else is supplied
    if not check_for_no_other_params_supplied(req_dict['body']):
        raise ParamError("No other params are supplied with statementId.")

    # Validate statement in body
    try:
        validator = StatementValidator(req_dict['body'])
        validator.validate()
    except Exception, e:
        raise BadRequest(e.message)
    except ParamError, e:
        raise ParamError(e.message)
    server_validation(req_dict['body'], req_dict['auth'],
                      req_dict.get('payload_sha2s', None))
    return req_dict


def validate_attachments(attachment_data, payload_sha2s):
    # For each attachment that is in the actual statement
    for attachment in attachment_data:
        # If the attachment data has a sha2 field, must validate it against the payload data
        if 'sha2' in attachment:
            sha2 = attachment['sha2']