# Path: cfg.py
# API_VERSION = 1
# SKIER_VERSION = 1.5
# 
# Path: skier/pgp.py
# def add_pgp_key(armored: str) -> tuple:
# def get_pgp_armor_key(keyid: str) -> str:
# def get_pgp_keyinfo(keyid: str) -> keyinfo.KeyInfo:
# def search_through_keys(search_str: str, page: int=1, count: int=10) -> Pagination:
# 
# Path: skier/pgpactions.py
# def import_key(keyserver: str, keyid: str):
# def synch_keys():
# def _broadcast_add(key: db.Key):
# def broadcast_add(key: db.Key):


import json
import datetime
import db
from flask import Blueprint, request
from cfg import cfg
from skier import pgp, pgpactions
    if key[0]:
        pgpactions.broadcast_add(key[2])
        return json.dumps({"error": 0, "msg": key[1]}), 200, {"Content-Type": "application/json"}
    else:
        return json.dumps({"error": key[1], "msg": "invalid-key-data"}), 401, {"Content-Type": "application/json"}


@pgpapi.route("/import/<keyserver>/<keyid>", methods=["POST"])
def importkey(keyserver, keyid):
    if not keyserver in cfg.config.sks_imports:
        if not keyserver in cfg.config.skier_imports:
            return json.dumps({"code": 2, "err": "Invalid keyserver"}), 400, {"Content-Type": "application/json"}
    key = pgpactions.import_key(keyserver=keyserver, keyid=keyid)
    if key == -2:
        return json.dumps({"code": 3, "err": "Could not connect"}), 400, {"Content-Type": "application/json"}
    elif key == -1:
        return json.dumps({"code": 1, "err": "Key not found"}), 404, {"Content-Type": "application/json"}
    elif key == -3:
        return json.dumps({"code": 4, "err": "Key invalid"}), 400, {"Content-Type": "application/json"}
    elif key == -4:
        return json.dumps({"code": 5, "err": "Key exists and unchanged"}), 400, {"Content-Type": "application/json"}
    elif key == 0:
        return json.dumps({"code": 0, "err": ""}), 200, {"Content-Type": "application/json"}
    else:
        return ""

@pgpapi.route("/importers")
def importers():
    return json.dumps(cfg.config.skier_imports + cfg.config.sks_imports)


# Path: cfg.py
# API_VERSION = 1
# SKIER_VERSION = 1.5
# 
# Path: skier/pgp.py
# def add_pgp_key(armored: str) -> tuple:
# def get_pgp_armor_key(keyid: str) -> str:
# def get_pgp_keyinfo(keyid: str) -> keyinfo.KeyInfo:
# def search_through_keys(search_str: str, page: int=1, count: int=10) -> Pagination:
# 
# Path: skier/pgpactions.py
# def import_key(keyserver: str, keyid: str):
# def synch_keys():
# def _broadcast_add(key: db.Key):
# def broadcast_add(key: db.Key):


# Path: skier/pgpapi.py
import json
import datetime
import db
from flask import Blueprint, request
from cfg import cfg
from skier import pgp, pgpactions

    if key[0]:
        pgpactions.broadcast_add(key[2])
        return json.dumps({"error": 0, "msg": key[1]}), 200, {"Content-Type": "application/json"}
    else:
        return json.dumps({"error": key[1], "msg": "invalid-key-data"}), 401, {"Content-Type": "application/json"}


@pgpapi.route("/import/<keyserver>/<keyid>", methods=["POST"])
def importkey(keyserver, keyid):
    if not keyserver in cfg.config.sks_imports:
        if not keyserver in cfg.config.skier_imports:
            return json.dumps({"code": 2, "err": "Invalid keyserver"}), 400, {"Content-Type": "application/json"}
    key = pgpactions.import_key(keyserver=keyserver, keyid=keyid)
    if key == -2:
        return json.dumps({"code": 3, "err": "Could not connect"}), 400, {"Content-Type": "application/json"}
    elif key == -1:
        return json.dumps({"code": 1, "err": "Key not found"}), 404, {"Content-Type": "application/json"}
    elif key == -3:
        return json.dumps({"code": 4, "err": "Key invalid"}), 400, {"Content-Type": "application/json"}
    elif key == -4:
        return json.dumps({"code": 5, "err": "Key exists and unchanged"}), 400, {"Content-Type": "application/json"}
    elif key == 0:
        return json.dumps({"code": 0, "err": ""}), 200, {"Content-Type": "application/json"}
    else:
        return ""

@pgpapi.route("/importers")
def importers():
    return json.dumps(cfg.config.skier_imports + cfg.config.sks_imports)


if cfg.config.pool_enabled.syncactions: