예제 #1
0
def check_parameter():
    """Get all techniques from ncf folder passed as parameter, or default ncf folder if not defined"""
    try:
        if not "value" in request.json:
            return format_error(
                ncf.NcfError(
                    "No value metadata provided in the request body."), "",
                400)
        else:
            parameter_value = request.json['value']

        if not "constraints" in request.json:
            return format_error(
                ncf.NcfError(
                    "No constraints metadata provided in the request body."),
                "", 400)
        else:
            parameter_constraints = request.json['constraints']

        # We need to get path from url params, if not present put "" as default value
        check = ncf_constraints.check_parameter(parameter_value,
                                                parameter_constraints)
        resp = jsonify(check)
        return resp
    except Exception as e:
        return format_error(e, "checking parameter", 500)
예제 #2
0
def format_error(exception, when, code):
    if not isinstance(exception, ncf.NcfError):
        exception = ncf.NcfError(
            "Unknown internal error during " + when,
            "Cause: " + str(exception) + "\n" + traceback.format_exc())
    error = jsonify({"error": ncf.format_errors([exception])})
    error.status_code = code
    return error
예제 #3
0
def create_technique():
  """ Get data in JSON """
  try:
    # technique is a mandatory parameter, abort if not present
    if not "technique" in request.json:
      return format_error(ncf.NcfError("No Technique metadata provided in the request body."), "", 400)
    else:
      technique = request.json['technique']
  
    if "path" in request.json and request.json['path'] != "":
      path = request.json['path']
    else:
      path = default_path
  
    result = ncf.write_technique(technique,path)

    return jsonify(result), 201

  except Exception as e:
    return format_error(e, "technique writing", 500)