Exemplo n.º 1
0
def prune_db():
    keymaster.application.logger.info('Pruning expired keys from database.')
    conn = config.DB_CONNECTION()
    cur = conn.cursor()
    update_query = ("UPDATE uploaded_key SET public_key='' "
                    "WHERE expire_time<current_timestamp")
    cur.execute(update_query)
    conn.commit()
    cur.close()
    conn.close()
Exemplo n.º 2
0
def upload_key(public_key):
    conn = config.DB_CONNECTION()
    cur = conn.cursor()
    insert_query = ("INSERT INTO uploaded_key (public_key) "
                    "VALUES (%s) RETURNING upload_id")
    cur.execute(insert_query, [public_key])
    db_id = cur.fetchone()[0]
    conn.commit()
    cur.close()
    conn.close()
    return hasher.encode(db_id)
Exemplo n.º 3
0
def expire_key(hashid):
    conn = config.DB_CONNECTION()
    cur = conn.cursor()
    db_id = 0
    try:
        db_id = hasher.decode(hashid)[0]
    except IndexError:
        return
    update_query = ("UPDATE uploaded_key SET expire_time=current_timestamp "
                    "WHERE upload_id=%s")
    cur.execute(update_query, [db_id])
    conn.commit()
    cur.close()
    conn.close()
Exemplo n.º 4
0
def fetch_key(hashid):
    conn = config.DB_CONNECTION()
    cur = conn.cursor()
    db_id = 0
    try:
        db_id = hasher.decode(hashid)[0]
    except IndexError:
        return None
    select_query = ("SELECT * FROM uploaded_key WHERE upload_id=%s "
                    "AND expire_time>current_timestamp")
    cur.execute(select_query, [db_id])
    key_obj = cur.fetchone()
    conn.commit()
    cur.close()
    conn.close()
    return key_obj