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

Migrate to Flask-RestX #73

Merged
merged 9 commits into from
Apr 29, 2020
Merged

Migrate to Flask-RestX #73

merged 9 commits into from
Apr 29, 2020

Conversation

abompard
Copy link
Member

@abompard abompard commented Apr 28, 2020

Fixes #25, #55

Also fixes/implements pagination, fixes a security issue related to the reuse of ldap connections, and fixes/implements credentials delegation so that LDAP queries are done as the connecting user and not the HTTP service (#55).

Using Flask-RestX (or Falsk-Restful) will save us code (and tests) for the REST API mechanics.

Related to #31 since Flask-RestX automatically generates and publishes the OpenAPI spec by introspecting the code and comments. I don't consider #31 entirely fixed by this PR because we need to improve the code's documentation to get the spec to a decent documentation level.

Code coverage is not 100% but I'll improve it over time.

Fixes: fedora-infra#25

Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
@StephenCoady
Copy link
Contributor

@abompard I've gone through this now commit-by-commit and I have no comments! This PR is crazy good. The pagination code is the only part I'm not 100% clear on how it is working. It might benefit from some comments maybe for us simpler folk :P

One thing: I noticed when I hit an endpoint and I omit the trailing slash like so /groups vs /groups/ that I get a server error. Is there a way to wildcard this? Or do we care? I would have expected both to work.

@abompard
Copy link
Member Author

Thanks! If you omit the trailing slash you should get a redirect response with a Location header that points the the same endpoint with a trailing slash.

The pagination is... yeah. LDAP makes things pretty complex, because it has an internal model of pagination that we can barely use because it can't be use with different LDAP connections, therefore with different HTTP requests. So I'm using the same technique that IPA uses: I request the whole list of record IDs from LDAP, but just the IDs, not the full data. Then I slice that into pages and keep the requested page, and for those IDs only I get the full data.

I agree this would benefit from some docs, could you be more precise as to which parts you thought weren't clear?

Anyway, thanks, I'll merge it as is so we can build new stuff upon it. Thanks a lot for the review!

@abompard abompard force-pushed the restx branch 2 times, most recently from e5dd183 to 8b64c43 Compare April 29, 2020 13:11
@StephenCoady
Copy link
Contributor

Thanks! If you omit the trailing slash you should get a redirect response with a Location header that points the the same endpoint with a trailing slash.

Ah, I somehow didn't spot the redirect.

I request the whole list of record IDs from LDAP, but just the IDs, not the full data. Then I slice that into pages and keep the requested page, and for those IDs only I get the full data.

Even this description helps make pagination.py more readable, thanks! Maybe add_page_data could just do with some comments as to that reasoning. Might make future maintenance easier is all.

Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
Fixes: fedora-infra#55

Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
Fixes: fedora-infra#29
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
@abompard
Copy link
Member Author

I've added some docsting but it's severely lacking in that area. I'll try to add more later. For now I'll just merge this PR so we can start building upon it (I plan on fixing the CI script next)

@abompard abompard merged commit ec97219 into fedora-infra:master Apr 29, 2020
@abompard abompard deleted the restx branch April 29, 2020 14:39
@abompard abompard mentioned this pull request May 7, 2020
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.

As a developer, I want to use a REST API framework so that I don't re-invent the wheel
2 participants