consumer-reports-innovation-lab / data-rights-protocol

The technical standard for exchanging data rights requests
https://datarightsprotocol.org
Apache License 2.0
56 stars 12 forks source link

python models and status server #36

Closed rrix closed 2 years ago

rrix commented 2 years ago

So I wrote some Pydantic modules to express at least the shape of the DataRightsRequest and DataRightsStatus objects and as much of the logic as I could feasibly express with Pydantic's validators, and the Python 3 type systems. I had done some experiments using these classes to generate test cases using Hypothesis but that was a tarpit I pulled myself out of. There is some weird complexity here, the BaseModel exists so that a serialized DataRightsRequest will contain a JWT-serialized IdentityPayload. It's quite a neat trick but basically useless right now.

They're used here in status_server.py though, a bit! I got it done in less than 100 lines like I threatened to.

it even includes a Swagger instance. I'll figure out how to load the PIP's openapi.yaml in it and kill two birds with one stone by providing a web tool which can submit PIP requests and receive their callbacks.

The callback server is minimum-viable hack-ish. It stores the statuses as json on-disk where DRP_REQUEST_CACHE environment variable is set, or ./drp-request-cache by default.

If you want to test this, I suggest installing Poetry, running poetry install and then running poetry run uvicorn status_server:app, then http://localhost:8000/docs will load the swagger. :smiling_imp: Or you can install Nix package manager :smiling_imp: and run nix-shell then uvicorn status_server:app

rrix commented 2 years ago

I moved most of this to consumer-reports-digital-lab/data-rights-protocol-cert. the rest will go in its own diff.