Skip to content

Commit

Permalink
Draft layer propose/unpropose/publish/unpublish
Browse files Browse the repository at this point in the history
  • Loading branch information
bkis committed Nov 22, 2023
1 parent 1b1aa53 commit a6aa66c
Show file tree
Hide file tree
Showing 13 changed files with 792 additions and 105 deletions.
188 changes: 188 additions & 0 deletions Tekst-API/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,194 @@
}
}
},
"/layers/{id}/propose": {
"post": {
"tags": [
"layers"
],
"summary": "Propose layer",
"operationId": "proposeLayer",
"security": [
{
"APIKeyCookie": []
},
{
"OAuth2PasswordBearer": []
}
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"example": "5eb7cf5a86d9755df3a6c593",
"title": "Id"
}
}
],
"responses": {
"204": {
"description": "Successful Response"
},
"404": {
"description": "Not found"
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/layers/{id}/unpropose": {
"post": {
"tags": [
"layers"
],
"summary": "Unpropose layer",
"operationId": "unproposeLayer",
"security": [
{
"APIKeyCookie": []
},
{
"OAuth2PasswordBearer": []
}
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"example": "5eb7cf5a86d9755df3a6c593",
"title": "Id"
}
}
],
"responses": {
"204": {
"description": "Successful Response"
},
"404": {
"description": "Not found"
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/layers/{id}/publish": {
"post": {
"tags": [
"layers"
],
"summary": "Publish layer",
"operationId": "publishLayer",
"security": [
{
"APIKeyCookie": []
},
{
"OAuth2PasswordBearer": []
}
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"example": "5eb7cf5a86d9755df3a6c593",
"title": "Id"
}
}
],
"responses": {
"204": {
"description": "Successful Response"
},
"404": {
"description": "Not found"
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/layers/{id}/unpublish": {
"post": {
"tags": [
"layers"
],
"summary": "Unpublish layer",
"operationId": "unpublishLayer",
"security": [
{
"APIKeyCookie": []
},
{
"OAuth2PasswordBearer": []
}
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"example": "5eb7cf5a86d9755df3a6c593",
"title": "Id"
}
}
],
"responses": {
"204": {
"description": "Successful Response"
},
"404": {
"description": "Not found"
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/nodes": {
"post": {
"tags": [
Expand Down
21 changes: 8 additions & 13 deletions Tekst-API/tekst/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Annotated
from urllib.parse import quote

from pydantic import EmailStr, Field, StringConstraints, field_validator
from pydantic import EmailStr, Field, StringConstraints, computed_field, field_validator
from pydantic_settings import BaseSettings, SettingsConfigDict

from tekst import pkg_meta
Expand Down Expand Up @@ -155,23 +155,18 @@ class TekstConfig(BaseSettings):
tekst_license: str = pkg_meta["license"]
tekst_license_url: CustomHttpUrl = pkg_meta["license_url"]

@field_validator("db_host", "db_password", mode="after")
@classmethod
def url_quote(cls, v: str) -> str:
return quote(str(v).encode("utf8"), safe="")

@field_validator("db_name", mode="after")
@classmethod
def generate_db_name(cls, v: str) -> str:
return safe_name(v)

def db_get_uri(self) -> str:
creds = (
f"{self.db_user}:{self.db_password}@"
if self.db_user and self.db_password
else ""
)
return f"{self.db_protocol}://{creds}{self.db_host}:{str(self.db_port)}"
@computed_field
@property
def db_uri(self) -> str:
db_host = quote(str(self.db_host).encode("utf8"), safe="")
db_password = quote(str(self.db_password).encode("utf8"), safe="")
creds = f"{self.db_user}:{db_password}@" if self.db_user and db_password else ""
return f"{self.db_protocol}://{creds}{db_host}:{str(self.db_port)}"

@field_validator(
"cors_allow_origins", "cors_allow_methods", "cors_allow_headers", mode="before"
Expand Down
4 changes: 2 additions & 2 deletions Tekst-API/tekst/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _init_client(db_uri: str = None) -> None:
global _db_client
if _db_client is None:
log.info("Initializing database client...")
_db_client = DatabaseClient(db_uri or _cfg.db_get_uri())
_db_client = DatabaseClient(db_uri or _cfg.db_uri)


def get_client(db_uri: str) -> DatabaseClient:
Expand All @@ -35,7 +35,7 @@ def get_client(db_uri: str) -> DatabaseClient:

async def reset_db():
"""Drops the database"""
await get_client(_cfg.db_get_uri()).drop_database(_cfg.db_name)
await get_client(_cfg.db_uri).drop_database(_cfg.db_name)


async def init_odm(db: Database) -> None:
Expand Down
2 changes: 1 addition & 1 deletion Tekst-API/tekst/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_cfg() -> TekstConfig:


def get_db_client(cfg: TekstConfig = get_config()) -> DatabaseClient:
return get_client(cfg.db_get_uri())
return get_client(cfg.db_uri)


def get_db(
Expand Down
Loading

0 comments on commit a6aa66c

Please sign in to comment.