219 lines
7.9 KiB
Python
219 lines
7.9 KiB
Python
# pip install "fastapi[standard]"
|
|
# fastapi dev routes.py
|
|
from fastapi import FastAPI
|
|
from pydantic import BaseModel
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class TypeItem(BaseModel):
|
|
type: int # {0=undefined, 1=S/MIME, 2=PGP}
|
|
published: bool # {0=no, 1=yes}
|
|
automatic: bool # {0=no, 1=yes}
|
|
identifier: str
|
|
|
|
|
|
class StringItem(BaseModel):
|
|
data: str
|
|
|
|
|
|
@app.get("/user/{user_id}/entries")
|
|
def get_count_user_entires(user_id: str) -> dict:
|
|
"""Get the number of entries for the user user_id from the IdM"""
|
|
count = 3
|
|
return {"status": 200, "user_id": user_id, "count": count}
|
|
|
|
|
|
@app.get("/user/{user_id}/entry/{entry_id}")
|
|
def check_if_user_entry_existis(user_id: str, entry_id: int) -> dict:
|
|
"""Does the entry number entry_id for the user user_id from the IdM"""
|
|
if entry_id < 0:
|
|
status: int = 404
|
|
else:
|
|
status = 200
|
|
|
|
return {"status": status, "user_id": user_id, "entry_id": entry_id}
|
|
|
|
|
|
@app.post("/user/{user_id}")
|
|
def create_new_entry_for_user(user_id: str, entry_id: int) -> dict:
|
|
"""Create a new entry for the user {user_id} in IdM
|
|
and update 'change date' in IdM
|
|
and return entry_id for new entry
|
|
"""
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id}
|
|
|
|
|
|
@app.delete("/user/{user_id}/entry/{entry_id}")
|
|
def remove_entry_for_user(user_id: str, entry_id: int) -> dict:
|
|
"""Delete a entry for the user {user_id} in IdM"""
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id}
|
|
|
|
|
|
@app.get("/user/{user_id}/entry/{entry_id}/public_info")
|
|
def get_public_from_entry_for_user(user_id: str, entry_id: int) -> dict:
|
|
"""Get Public PGP Key / public S/MIME certificate for user user_id
|
|
and entry entry_id."""
|
|
data = "..."
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id, "data": data}
|
|
|
|
|
|
@app.post("/user/{user_id}/entry/{entry_id}/public_info")
|
|
def change_public_from_entry_for_user(
|
|
user_id: str, entry_id: int, item: StringItem
|
|
) -> dict:
|
|
"""Change public PGP Key / private S/MIME certificate for user user_id
|
|
and entry entry_id,
|
|
and update 'change date' in IdM.
|
|
and update 'end of life date' in IdM.
|
|
"""
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id, "data": item.data}
|
|
|
|
|
|
@app.get("/user/{user_id}/entry/{entry_id}/private_info")
|
|
def get_private_from_entry_for_user(user_id: str, entry_id: int) -> dict:
|
|
"""Get Private PGP Key / private S/MIME certificate for user user_id
|
|
and entry entry_id."""
|
|
data = "..."
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id, "data": data}
|
|
|
|
|
|
@app.post("/user/{user_id}/entry/{entry_id}/private_info")
|
|
def change_private_from_entry_for_user(
|
|
user_id: str, entry_id: int, item: StringItem
|
|
) -> dict:
|
|
"""Change private PGP Key / private S/MIME certificate for user user_id
|
|
and entry entry_id,
|
|
and update 'change date' in IdM.
|
|
"""
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id, "data": item.data}
|
|
|
|
|
|
@app.delete("/user/{user_id}/entry/{entry_id}/private_info")
|
|
def delete_private_from_entry_for_user(user_id: str, entry_id: int) -> dict:
|
|
"""Delete / unpublish private PGP Key / private S/MIME certificate for user user_id
|
|
and entry entry_id,
|
|
and update 'change date' in IdM.
|
|
"""
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id}
|
|
|
|
|
|
@app.get("/user/{user_id}/entry/{entry_id}/end_of_life")
|
|
def get_end_of_life_from_entry_for_user(user_id: str, entry_id: int) -> dict:
|
|
"""Get expire date for user user_id and entry entry_id."""
|
|
data = "..."
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id, "data": data}
|
|
|
|
|
|
@app.get("/user/{user_id}/entry/{entry_id}/type")
|
|
def get_type_from_entry_for_user(user_id: str, entry_id: int) -> dict:
|
|
"""Get type for user user_id and entry entry_id.
|
|
This data is stored as serialized dict
|
|
type: int \\in {0=undefined, 1=S/MIME, 2=PGP}
|
|
published: int \\in {0=no, 1=yes}from
|
|
"""
|
|
data = {"type": 0, "published": 0, "automatic": 0, "identifier": "Some ID"}
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id, "data": data}
|
|
|
|
|
|
@app.post("/user/{user_id}/entry/{entry_id}/type")
|
|
def change_for_entry_for_user(user_id: str, entry_id: int, item: TypeItem) -> dict:
|
|
"""Change type data for user user_id and entry entry_id.
|
|
This data is stored as serialized dict
|
|
type: int \\in {0=undefined, 1=S/MIME, 2=PGP}
|
|
published: int \\in {0=no, 1=yes}
|
|
automatic:int \\in {0=no, 1=yes}
|
|
identifier:str
|
|
"""
|
|
data = {
|
|
"type": item.type,
|
|
"published": item.published,
|
|
"automatic": item.automatic,
|
|
"identifier": item.identifier,
|
|
}
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id, "data": data}
|
|
|
|
|
|
@app.get("/user/{user_id}/entry/{entry_id}/given_name")
|
|
def get_given_name_from_entry_for_user(user_id: str, entry_id: int) -> dict:
|
|
"""Get given name for user user_id and entry entry_id."""
|
|
data = "..."
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id, "data": data}
|
|
|
|
|
|
@app.post("/user/{user_id}/entry/{entry_id}/given_name")
|
|
def change_given_name_from_entry_for_user(
|
|
user_id: str, entry_id: int, item: StringItem
|
|
) -> dict:
|
|
"""Change given name for user user_id
|
|
and entry entry_id,
|
|
and update 'change date' in IdM.
|
|
"""
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id, "data": item.data}
|
|
|
|
|
|
@app.get("/user/{user_id}/entry/{entry_id}/surname")
|
|
def get_surname_from_entry_for_user(user_id: str, entry_id: int) -> dict:
|
|
"""Get surname for user user_id and entry entry_id."""
|
|
data = "..."
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id, "data": data}
|
|
|
|
|
|
@app.post("/user/{user_id}/entry/{entry_id}/surname")
|
|
def change_surname_from_entry_for_user(
|
|
user_id: str, entry_id: int, item: StringItem
|
|
) -> dict:
|
|
"""Change surname for user user_id
|
|
and entry entry_id,
|
|
and update 'change date' in IdM.
|
|
"""
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id, "data": item.data}
|
|
|
|
|
|
@app.post("/user/{user_id}/entry/{entry_id}/server")
|
|
def update_entry_for_user_on_server(user_id: str, entry_id: int) -> dict:
|
|
"""Create / update entry for user user_id and entry entry_id on LDAP / Keyserver."""
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id}
|
|
|
|
|
|
@app.delete("/user/{user_id}/entry/{entry_id}/server")
|
|
def remove_entry_for_user_from_server(user_id: str, entry_id: int) -> dict:
|
|
"""Remove / unpublish entry for user user_id and entry entry_id from LDAP / Keyserver."""
|
|
return {"status": 200, "user_id": user_id, "entry_id": entry_id}
|
|
|
|
|
|
@app.post("/user/{user_id}/server")
|
|
def update_all_entries_for_user_on_server(user_id: str) -> dict:
|
|
"""Create / update all entries for user user_id on LDAP / Keyserver."""
|
|
return {"status": 200, "user_id": user_id}
|
|
|
|
|
|
@app.delete("/user/{user_id}/server")
|
|
def remove_all_entries_for_user_from_server(user_id: str) -> dict:
|
|
"""Remove / unpublish all entries for user user_id from LDAP / Keyserver."""
|
|
return {"status": 200, "user_id": user_id}
|
|
|
|
|
|
@app.post("/user/{user_id}/cert/{cert_id}/convert")
|
|
def import_public_cert_from_cert_server(user_id: str) -> dict:
|
|
"""Gets a public cert with cert_id for user user_id from the cert server
|
|
and creates a IdM entry for it."""
|
|
return {"status": 200, "user_id": user_id}
|
|
|
|
|
|
@app.post("/server")
|
|
def remove_all_entries_for_all_user_on_server() -> dict:
|
|
"""Update all entries for all user on LDAP / keyserver."""
|
|
return {"status": 200}
|
|
|
|
|
|
@app.post("/user/{user_id}/email/{email_address}/make_mime")
|
|
def create_smime_certificate_for_user(user_id: str, email_address: str) -> dict:
|
|
"""Creates a s/mime certificate set for automatic processing"""
|
|
return {"status": 200, "user_id": user_id, "email_address": {email_address}}
|
|
|
|
|
|
@app.post("/user/{user_id}/email/{email_address}/make_pgp")
|
|
def create_pgp_certificate_for_user(user_id: str, email_address: str) -> dict:
|
|
"""Creates a PGP key set for automatic processing"""
|
|
return {"status": 200, "user_id": user_id, "email_address": {email_address}}
|