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

Config: Add the read_only setting #65

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented May 8, 2023

Fixes #63

This setting, which is set to True by default, will determine whether
the instance is to be read-only. The protected_methods_middleware
function is added as middleware to the application. If the read_only
setting is True and the request method is DELETE, PATCH, POST or
PUT, a 405 Method Not Allowed response is returned.

This is the recommended way as per the documentation of `fastapi` as it
can be easily made available to routes.
This setting, which is set to `True` by default, will determine whether
the instance is to be read-only. The `protected_methods_middleware`
function is added as middleware to the application. If the `read_only`
setting is `True` and the request method is `DELETE`, `PATCH`, `POST` or
`PUT`, a `405 Method Not Allowed` response is returned.
@sphuber sphuber force-pushed the feature/065/config-read-only branch from c5a324e to c7aed7c Compare May 8, 2023 13:56
@codecov-commenter
Copy link

Codecov Report

Patch coverage: 97.14% and project coverage change: +0.05 🎉

Comparison is base (3f14ea2) 93.39% compared to head (c7aed7c) 93.44%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #65      +/-   ##
==========================================
+ Coverage   93.39%   93.44%   +0.05%     
==========================================
  Files          28       29       +1     
  Lines         999     1022      +23     
==========================================
+ Hits          933      955      +22     
- Misses         66       67       +1     
Flag Coverage Δ
pytests 93.44% <97.14%> (+0.05%) ⬆️

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

Impacted Files Coverage Δ
aiida_restapi/middleware.py 90.00% <90.00%> (ø)
aiida_restapi/config.py 100.00% <100.00%> (ø)
aiida_restapi/main.py 100.00% <100.00%> (ø)
aiida_restapi/routers/auth.py 85.13% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@sphuber
Copy link
Contributor Author

sphuber commented May 8, 2023

@giovannipizzi @eimrek This would be a possible implementation to allow easily making an instance of the API fully read-only.

@chrisjsewell
Copy link
Member

Heya, how do other fastapi packages achieve this? Is there any documentation links?

@sphuber
Copy link
Contributor Author

sphuber commented May 9, 2023

Heya, how do other fastapi packages achieve this? Is there any documentation links?

I tried googling, but nothing concrete showed up. Might be that I have missed it of course.

@eimrek eimrek self-assigned this May 28, 2024
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.

Add concept of read-only endpoints and add configuration to block anything but read-only endpoints
4 participants