Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add draft OpenFGA client #10504

Draft
wants to merge 22 commits into
base: lva/roles-openfga-edition
Choose a base branch
from
Draft

Conversation

leovalais
Copy link
Contributor

@leovalais leovalais commented Jan 23, 2025

Important

Not to be merged into dev directly

Note

This is a lengthy PR which also requires some amount of OpenFGA knowledge to be understood. It's probably better to peer review it.

Draft OpenFGA client.

  • Will be moved into editoast's workspace when ready (it's currently outside for dev comfort)
  • Only a few operations have been implemented
  • Meant to remain a new sub-crate which will be included in editoast_authz (in which we'll map the authorization model, define our objects, their conversion, relations, etc.)
  • The fga binary is necessary to run unit tests for now: https://github.com/openfga/cli

TODO:

  • Implement all the operations we'll need
    • Operations needed for the roles reimplementation
    • POST /stores/{}/list-users
    • POST /stores/{}/stream-list-objects
    • POST /stores/{}/expand
    • POST /stores/{}/read
    • POST /stores/{}/batch-check
    • Other operations currently not needed, but since there's so few of them, we may want to implement them for completeness?
  • Keep an authorization_model_id in the client to forward it to requests—as advised by OpenFGA
  • Improve tests utils
  • Documentation (for real this time 👀)
    • mod client
    • mod model
  • INSTRUMENT EVERYTHING
  • Setup OpenFGA in docker compose

About macros

Important

Expecting feedback on this point

This crates introduces a few macro_rules, which are only used for tests currently.

  • relations! allows defining typed relations concisely to allow quick comparisons with the OpenFGA schema. I think we should keep this one, that'll help the review process and reduce straightforward boilerplate.
  • fga_type! declares the newtype structs representing the types of OpenFGA and generates a few implementations. I think this one should remain a #[cfg(test)] definition. However I think derive macros derive(fga::User, fga::Object) would help us and cost nothing as they are trivial to implement.
  • fga! allows manipulating and instantiating types and relations with the same syntax as OpenFGA, but in a type-safe way. This is particularly useful for the conciseness of unit tests. I think it should be exported.

Signed-off-by: Leo Valais <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 0% with 255 lines in your changes missing coverage. Please review.

Project coverage is 81.41%. Comparing base (fd288d3) to head (ac0adfd).

Files with missing lines Patch % Lines
fga/src/client.rs 0.00% 255 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@                      Coverage Diff                      @@
##           lva/roles-openfga-edition   #10504      +/-   ##
=============================================================
- Coverage                      81.80%   81.41%   -0.39%     
=============================================================
  Files                           1073     1074       +1     
  Lines                         106716   107105     +389     
  Branches                         730      730              
=============================================================
- Hits                           87300    87201      -99     
- Misses                         19377    19865     +488     
  Partials                          39       39              
Flag Coverage Δ
editoast 74.25% <ø> (-0.03%) ⬇️
front 89.34% <ø> (ø)
gateway 2.18% <ø> (ø)
osrdyne 2.98% <0.00%> (-0.31%) ⬇️
railjson_generator 87.50% <ø> (ø)
tests 87.05% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leovalais leovalais force-pushed the lva/openfga-client branch 2 times, most recently from 86c5e06 to 863f612 Compare February 5, 2025 21:23
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants