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

Auth services #421

Merged
merged 6 commits into from
Mar 20, 2018
Merged

Auth services #421

merged 6 commits into from
Mar 20, 2018

Conversation

justanr
Copy link
Collaborator

@justanr justanr commented Mar 18, 2018

Two major changes here:

  1. Some auth logic has been extracted out to standalone services. I only extracted reset password, registration and most of the tokening logic. I want feedback on this direction before pushing further.

There are some concessions made in the APIs of these services, mostly in the view layer to cope with information that might not be available during install, tests, etc -- namely configuration settings coming from flaskbb_config. I figured doing a song and dance in the view layer will be easier to correct in the future than in the service layers.

Not all the logic has been extracted from the views and not all of it should be, but there are a few stray db.commits() that I'd like to move into the services but I haven't thought of a good way of handling this -- probably just doing it and paying the cost of another dependency on the services.

Some of it feels odd and a touch over engineered to me -- TokenVerificationError/StopTokenVerification and the mirrored UserRegistrationError/StopUserRegistrationError. We could probably merge these together into a single pair of ValidationError/StopValidation exceptions that could be reused across all areas.

There's also a newly added UserRepository, which I really like the idea of but I'm not sure how much it'll buy us and I might just chuck it honestly.

  1. Direct calls to py.test have been replaced with tox, including travis. This allows local testing to be more accurate against multiple interpreters, code coverage locally has been changed as well to reflect -- namely pytest-cov is gone and replaced with a direct call to coverage instead. The .coveragerc file is slightly more complicated to cope with it.

Other minor changes:

  • setup.cfg is mostly empty, tox, flake and py.test deprecated their usages of it apparently. Most of these have been moved into tox.ini
  • FlaskBBError is now a child of BaseFlaskBBError
  • FlaskForm in the FlaskBB code has been replaced with FlaskBBForm which has a helper method to populate error messages
  • attrs, hurrah

* Implements reset password and registration into stand alone services
* Moves tokening into its own services
* Adds basic user repository interface (this is provisional)
* Adds support for tox
@sh4nks
Copy link
Member

sh4nks commented Mar 19, 2018

Some auth logic has been extracted out to standalone services. I only extracted reset password, registration and most of the tokening logic. I want feedback on this direction before pushing further.

While I like these changes I am not sure what the ultimate goal of extracting these things into services is? Is this a step to make flaskbb integrate better with other flask apps?

Some of it feels odd and a touch over engineered to me -- TokenVerificationError/StopTokenVerification and the mirrored UserRegistrationError/StopUserRegistrationError. We could probably merge these together into a single pair of ValidationError/StopValidation exceptions that could be reused across all areas.

I prefer to just have a single pair of those exceptions as we might end up with a lot more if we decide to migrate more things to this architecture.

setup.cfg is mostly empty, tox, flake and py.test deprecated their usages of it apparently. Most of these have been moved into tox.ini

I have recently moved everything to the setup.cfg file as I thought having everything in one place is better but I didn't know those tools deprecated the usage of the setup.cfg.

from . import services
from ..core.auth.password import ResetPasswordService
from ..core.auth.registration import (RegistrationService, StopRegistration,
UserRegistrationInfo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argh. I updated my formatter to use the pep8 style guide, I think I'll just go back to my old style setup and limit it to 79 chars.

:license: BSD, see LICENSE for more details
"""

from ..tokens import (StopTokenVerification, Token, TokenActions, TokenError,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Token is not used

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious that flake8 didn't yell about that.

from sqlalchemy import func

from ...core.auth.registration import UserRegistrationError, UserValidator
from ...core.tokens import TokenVerifier, TokenVerificationError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused imports

@sh4nks
Copy link
Member

sh4nks commented Mar 19, 2018

I get the following error when trying to register:

127.0.0.1 - - [19/Mar/2018 14:42:55] "GET /auth/register HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/home/peter/.virtualenvs/flaskbb/lib/python3.6/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/peter/.virtualenvs/flaskbb/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/home/peter/.virtualenvs/flaskbb/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/peter/.virtualenvs/flaskbb/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/peter/.virtualenvs/flaskbb/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/peter/.virtualenvs/flaskbb/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/peter/.virtualenvs/flaskbb/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/peter/.virtualenvs/flaskbb/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/peter/.virtualenvs/flaskbb/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/peter/.virtualenvs/flaskbb/lib/python3.6/site-packages/flask_debugtoolbar/__init__.py", line 125, in dispatch_request
    return view_func(**req.view_args)
  File "/home/peter/Development/flaskbb/flaskbb/utils/helpers.py", line 746, in wrapper
    return f(*a, **k)
  File "/home/peter/Development/flaskbb/flaskbb/utils/helpers.py", line 724, in wrapper
    return f(*a, **k)
  File "/home/peter/.virtualenvs/flaskbb/lib/python3.6/site-packages/flask/views.py", line 83, in view
    self = view.view_class(*class_args, **class_kwargs)
TypeError: __init__() got an unexpected keyword argument 'registration_service'

@justanr
Copy link
Collaborator Author

justanr commented Mar 20, 2018

While I like these changes I am not sure what the ultimate goal of extracting these things into services is? Is this a step to make flaskbb integrate better with other flask apps?

That might be an effect, but it's to make building plugins easier and hopefully cut down on bugs as things will be focused down into small units. I'd like to build a JSON API plugin but in the current state of things, a lot of code would need to be duplicated over into it.

I prefer to just have a single pair of those exceptions as we might end up with a lot more if we decide to migrate more things to this architecture.

Will do. I felt silly doing it twice.

I have recently moved everything to the setup.cfg file as I thought having everything in one place is better but I didn't know those tools deprecated the usage of the setup.cfg.

I found these issues:

Looks Flake8 still officially supports setup.cfg as a configuration source, but there is this issue filed against that tool that may or may not be happening:

I agree cutting down on config files is a good thing, but using tox.ini for testing tools is probably the better one to standardize on since it seems like using setup.cfg can cause unintended side affects. We could probably move back into setup.cfg without many issues.

@sh4nks
Copy link
Member

sh4nks commented Mar 20, 2018

That might be an effect,

I think we should keep this in mind when extracting these things into little services. This might make FlaskBB an interesting choice for small projects that want to have some kind of discussion forum.

but it's to make building plugins easier and hopefully cut down on bugs as things will be focused down into small units. I'd like to build a JSON API plugin but in the current state of things, a lot of code would need to be duplicated over into it.

I like this. The JSON API plugin would then serve as an example as well :)

Thanks for the cleanups. /auth/register works now. Is there anything else you want to add to this PR before merging it?

@justanr
Copy link
Collaborator Author

justanr commented Mar 20, 2018

Nope, this PR is already pretty big. I'd like to focus in on one or two services at a time lest this becomes a "I changed everything all at once" PR that no one will actually want to review in depth.

@sh4nks sh4nks merged commit 07ef7c4 into flaskbb:master Mar 20, 2018
@sh4nks
Copy link
Member

sh4nks commented Mar 20, 2018

While going through all the changes I wished that python 2 would support the typings module 🙈

@justanr justanr deleted the auth-services branch March 20, 2018 17:21
@justanr
Copy link
Collaborator Author

justanr commented Mar 20, 2018

Me too, me too.

@sh4nks sh4nks added this to Done in 2.0 Getting Hooked Up Mar 20, 2018
@sh4nks sh4nks mentioned this pull request Mar 26, 2018
24 tasks
@justanr justanr mentioned this pull request Apr 7, 2018
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants