feat(work): stage authenticated remote approvals with scoped execution fencing
This commit is contained in:
@@ -265,6 +265,8 @@ def create_app(settings=None, redis=None, platform=None):
|
||||
lifecycle = None
|
||||
from .notifications import router as notification_router
|
||||
background = set()
|
||||
approvals = None
|
||||
approval_worker = None
|
||||
|
||||
def spawn(coro):
|
||||
task = asyncio.create_task(coro)
|
||||
@@ -273,9 +275,16 @@ def create_app(settings=None, redis=None, platform=None):
|
||||
# Retrieve errors without displaying possibly sensitive exception text.
|
||||
task.add_done_callback(lambda t: t.exception() if not t.cancelled() else None)
|
||||
|
||||
if s.work_remote_approvals_enabled:
|
||||
from .approval_api import ApprovalAPI
|
||||
from .approval_worker import ApprovalWorker
|
||||
approval_worker=ApprovalWorker(s,credential_store.keyring)
|
||||
approvals=ApprovalAPI(oauth,approval_worker,f,spawn)
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app):
|
||||
await r.ping()
|
||||
if approval_worker:await approval_worker.start()
|
||||
if lifecycle:
|
||||
await lifecycle.maintain()
|
||||
await deliveries.recover_interrupted_sends()
|
||||
@@ -302,6 +311,7 @@ def create_app(settings=None, redis=None, platform=None):
|
||||
await deliveries.recover_interrupted_sends()
|
||||
if broker.files:await broker.files.flush()
|
||||
await deliveries.flush()
|
||||
if approvals:await approvals.maintain()
|
||||
except Exception:
|
||||
# No credentials or raw exception text in background logs.
|
||||
pass
|
||||
@@ -323,14 +333,19 @@ def create_app(settings=None, redis=None, platform=None):
|
||||
await r.delete("hn:task-worker:"+broker.worker_id)
|
||||
await pub.aclose()
|
||||
await f.close()
|
||||
if approval_worker:await approval_worker.close()
|
||||
store.close()
|
||||
if redis is None:
|
||||
await r.aclose()
|
||||
|
||||
app = FastAPI(title="Hainuo B1 connector", lifespan=lifespan, docs_url=None, redoc_url=None)
|
||||
app.add_middleware(BodyLimitMiddleware, max_body=s.max_body,
|
||||
path_limits={'/work/v2/files/upload':s.work_file_max_bytes}if broker.files else {})
|
||||
path_limits={**({'/work/v2/files/upload':s.work_file_max_bytes}if broker.files else {}),
|
||||
**({'/internal/approval-callback':65536,'/work/v2/approvals/create':49152}if approvals else {})})
|
||||
app.include_router(oauth.router)
|
||||
if approvals:
|
||||
app.include_router(approvals.router)
|
||||
app.state.approvals=approvals
|
||||
if lifecycle:
|
||||
app.include_router(deliveries.router)
|
||||
app.state.deliveries=deliveries
|
||||
|
||||
Reference in New Issue
Block a user