示例#1
0
文件: util.py 项目: viraptor/killick
def load_db(dbfilepath):
    requestdb = {}
    line_counter = 0
    try:
        with open(dbfilepath, 'r') as fp:
            for line in fp:
                line_counter += 1
                req = request.request(None, None, None)
                req.fromjson(json.loads(line))
                requestdb[req.request_id] = req
        return requestdb
    except IOError:
        logger.error("Cannot open certdb at %s, assuming no file and attempting to write anyway",dbfilepath)
        return {}
    except Exception:
        logger.error("Error parsing json from: %s at line %d",
                     dbfilepath, line_counter)
示例#2
0
def _parse_csr(pecan_request, auth_result, user):

    # Create requset object for writing to database
    new_request = request.request(pecan_request.POST.get('csr').replace(
        "\n", ""), util.get_next_id(jsonloader.conf.ra_options["certdb_file"]), user)

    # Validate CSR
    try:
        new_request.validator_results = validation.validate_csr(jsonloader.conf.ra_options[
                                                                "ra_name"], auth_result, new_request.get_X509csr(), pecan_request)
    except Exception as e:
        logger.exception("Error running validators: %s", e)
        pecan.abort(500, "Internal Validation Error")

    new_request.Valid = all(list(new_request.validator_results.values()))

    return new_request