Ejemplo n.º 1
0
def get_json(schema):
    data = request.get_json(force=True, silent=True, cache=False)

    message = schema.validate(data)

    if message:
        raise InvalidArgumentError(message)

    return data
Ejemplo n.º 2
0
def get_json(schema):
    """
    Parse the incoming request's data as JSON.
    Validate it against the specified schema.
    """

    data = request.get_json(force=True, silent=True, cache=False)

    message = schema.validate(data)

    if message:
        raise InvalidArgumentError(message)

    return data
Ejemplo n.º 3
0
def get_json(schema):
    """
    Parse the incoming request's data as JSON.
    Validate it against the specified schema.

    NOTE. This function is just an example of how one can read and check
    anything before passing to an API endpoint, and thus it may be modified in
    any way, replaced by another function, or even removed from the module.
    """

    data = request.get_json(force=True, silent=True, cache=False)

    message = schema.validate(data)

    if message:
        raise InvalidArgumentError(message)

    return data
def respond_trigger():
    add_status('failure')

    params = get_action_form_params()
    credentials = get_jwt()

    client = AkamaiClient(credentials, current_app.config['USER_AGENT'])
    action_map = {
        ADD_ACTION_ID: client.add_to_network_list,
        REMOVE_ACTION_ID: client.remove_from_network_list
    }

    action = action_map.get(params['action-id'])
    if not action:
        raise InvalidArgumentError("Unsupported action.")

    action(params['network_list_id'], params['observable_value'])

    add_status('success')
    return jsonify_result()
Ejemplo n.º 5
0
def respond_trigger():
    add_status('failure')

    params = get_action_form_params()

    client = ReferenceDataClient(get_credentials(), current_app.config)
    action_map = {
        ADD_ACTION_ID: client.add_to_reference_set,
        REMOVE_ACTION_ID: client.remove_from_reference_set,
        ADD_AND_CRETE_ACTION_ID: client.add_and_create_reference_set
    }

    action = action_map.get(params['action-id'])
    if not action:
        raise InvalidArgumentError('Unsupported action.')

    action(params['reference_set_name'], params['observable_value'])

    add_status('success')
    return jsonify_result()