Skip to content
This repository was archived by the owner on Jul 15, 2025. It is now read-only.

feat: add global kv-storage prototype#74

Merged
backwardspy merged 1 commit intomasterfrom
feat/kv-storage
Oct 6, 2023
Merged

feat: add global kv-storage prototype#74
backwardspy merged 1 commit intomasterfrom
feat/kv-storage

Conversation

@backwardspy
Copy link
Copy Markdown
Owner

this change implements the beginnings of a generic kv-storage mechanism that allows us to simulate things like authentication flows.

#61 prototypes this from an auth perspective, and i have taken inspiration from that PR to create this implementation. in recognition of this i have co-authored this commit.

some of the differences from #61:

  • i have not chosen a storage technology and instead opted for a simple global dict. this works fine for single node (and therefore local dev) setups, and lays the groundwork for what we need. i would like to make it easy to swap in any storage technology in future.
  • i've gone with string:string k:v pairs to make as few assumptions about the use of this storage as possible. ideally it can be used in any case where performing one request changes the behaviour of a subsequent one.
  • keys are not related to endpoints in any way, allowing any endpoint to affect any other. this could be dangerous in a larger multi-user setup, and i think it would be important to institute some kind of key naming conventions to ensure uniqueness. the advantage of removing this association is again flexibility.

example mocked auth setup

we have two endpoints, POST /auth and GET /secret
image

the POST /auth endpoint is configured with an action that sets authenticated=1 in storage
image

the GET /secret endpoint has two responses; a 401 default response and a 200 response with a rule of authenticated == 1
image

this enables the following series of requests:

GET /secret: <Response [401]>
POST /auth: <Response [200]>
GET /secret: <Response [200]>

running the same requests again within the 15 second expiry window gives a slightly different result where the first GET /secret succeeds:

GET /secret: <Response [200]>
POST /auth: <Response [200]>
GET /secret: <Response [200]>

waiting 15 seconds causes the authenticated key to expire and the result goes back to the first example again.


resolves #53

@backwardspy backwardspy added the enhancement New feature or request label Oct 6, 2023
@backwardspy backwardspy self-assigned this Oct 6, 2023
@backwardspy backwardspy force-pushed the feat/kv-storage branch 2 times, most recently from 3201173 to d48b1a1 Compare October 6, 2023 12:50
Co-authored-by: Haffi Mazhar <haffimazhar96@gmail.com>
@backwardspy backwardspy merged commit 80b28ef into master Oct 6, 2023
@backwardspy backwardspy deleted the feat/kv-storage branch October 6, 2023 13:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

key-value storage for rules and templating

1 participant