# 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



pgpapi = Blueprint("pgpapi", __name__)

@pgpapi.route("/getkey/<keyid>")
def getkey(keyid):
    # Load the key.
    key = pgp.get_pgp_armor_key(keyid)
    if key:
        return json.dumps({"key": key}), 200, {"Content-Type": "application/json",
                                               "Cache-Control": "no-cache", "Pragma": "no-cache"}
    else:
        return json.dumps({"key": None}), 404, {"Content-Type": "application/json",
                                                "Cache-Control": "no-cache", "Pragma": "no-cache"}

# Disabled for now due to we can't get the key raw.
#@pgpapi.route("/getkey/<keyid>/raw")
#def getkey_raw(keyid):
#    # Load the key.
#    key = pgp.get_pgp_key(keyid)
#    if key:
#        return key, 200, {"Content-Type": "application/octet-stream",
#                          "Content-Disposition": "attachment; filename=gpgkey.asc",
#                          "Cache-Control": "no-cache", "Pragma": "no-cache"}



# 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




pgpapi = Blueprint("pgpapi", __name__)

@pgpapi.route("/getkey/<keyid>")
def getkey(keyid):
    # Load the key.
    key = pgp.get_pgp_armor_key(keyid)
    if key:
        return json.dumps({"key": key}), 200, {"Content-Type": "application/json",
                                               "Cache-Control": "no-cache", "Pragma": "no-cache"}
    else:
        return json.dumps({"key": None}), 404, {"Content-Type": "application/json",
                                                "Cache-Control": "no-cache", "Pragma": "no-cache"}

# Disabled for now due to we can't get the key raw.
#@pgpapi.route("/getkey/<keyid>/raw")
#def getkey_raw(keyid):
#    # Load the key.
#    key = pgp.get_pgp_key(keyid)
#    if key:
#        return key, 200, {"Content-Type": "application/octet-stream",
#                          "Content-Disposition": "attachment; filename=gpgkey.asc",
#                          "Cache-Control": "no-cache", "Pragma": "no-cache"}



@pgpapi.route("/search/<search_str>", methods=["GET", "POST"])