Source types, connection test, server folders, uploads and OAuth sign-in for the Conectar dialog; sign-in for the web app with fastapi-users, the API left open
This commit is contained in:
+3
-22
@@ -1,10 +1,9 @@
|
||||
"""/conectar: look into a site's sources, draw and save pipelines, run them, inspect nodes."""
|
||||
|
||||
from pathlib import Path as FilePath
|
||||
from typing import Annotated, Any
|
||||
|
||||
from dagster_graphql import DagsterGraphQLClient, DagsterGraphQLClientError
|
||||
from fastapi import APIRouter, Depends, HTTPException, Path, Query, UploadFile
|
||||
from fastapi import APIRouter, Depends, HTTPException, Path, Query
|
||||
from fhir.resources.R4B.conceptmap import ConceptMap
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -12,7 +11,6 @@ from core import concept_map
|
||||
from core.pipeline import ID_PATTERN, ImportPath, Pipeline, Source, redacted, restored
|
||||
from core.schema import ENTITIES
|
||||
from persistance import config_log, nodes
|
||||
from persistance.config import DATA_DIR
|
||||
from webapi.runs import dagster
|
||||
|
||||
router = APIRouter(prefix="/ingest", tags=["ingest"])
|
||||
@@ -21,11 +19,6 @@ NodeId = Annotated[str, Path(pattern=ID_PATTERN, max_length=40)]
|
||||
Rows = list[dict[str, Any]]
|
||||
|
||||
|
||||
def _shown(row: dict) -> dict:
|
||||
"""A row as JSON: file contents shown by size, never sent whole."""
|
||||
return {k: f"<{len(v)} bytes>" if isinstance(v, bytes) else v for k, v in row.items()}
|
||||
|
||||
|
||||
def _from_source(call, *args):
|
||||
try:
|
||||
return call(*args)
|
||||
@@ -56,19 +49,7 @@ def source_resources(ref: SourceRef) -> list[str]:
|
||||
@router.post("/sources/preview")
|
||||
def source_preview(node: Source, limit: Annotated[int, Query(ge=1, le=200)] = 20) -> Rows:
|
||||
"""The first rows a source node would load."""
|
||||
return [_shown(r) for r in _from_source(nodes.preview, node, limit)]
|
||||
|
||||
|
||||
@router.post("/uploads")
|
||||
def upload(file: UploadFile) -> dict[str, str]:
|
||||
"""A CSV, Excel or document file for a `filesystem` source: use `bucket_url`."""
|
||||
name = FilePath(file.filename or "").name
|
||||
if not name:
|
||||
raise HTTPException(422, detail="the file needs a name")
|
||||
folder = DATA_DIR / "uploads"
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
(folder / name).write_bytes(file.file.read())
|
||||
return {"bucket_url": str(folder), "file_name": name}
|
||||
return [nodes.shown(r) for r in _from_source(nodes.preview, node, limit)]
|
||||
|
||||
|
||||
@router.get("/pipelines")
|
||||
@@ -168,7 +149,7 @@ def node_rows(
|
||||
"""What a node produced in the last run (empty if it produced nothing yet)."""
|
||||
out = []
|
||||
for row in nodes.rows(pipeline_id, node_id):
|
||||
out.append(_shown(row))
|
||||
out.append(nodes.shown(row))
|
||||
if len(out) == limit:
|
||||
break
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user