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

Free the business code from the token argument. #7

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

Conversation

e-gautier
Copy link
Contributor

Simplify the code in order to introduce new features.

@tduboys
Copy link
Owner

tduboys commented Nov 15, 2022

it will probably breaks moffics.py too

@tduboys
Copy link
Owner

tduboys commented Nov 20, 2022

Seems good, but just to be safe, maybe add a before_request method that resets session token, as it's the same session object in every http query

something like : (i dont know how to add suggested patch on pr… :/ )

diff --git a/moffics.py b/moffics.py
index d373ec6..261c7f9 100755
--- a/moffics.py
+++ b/moffics.py
@@ -136,6 +136,12 @@ def get_with_token(token: str):
 
     return get_ics_from_moffi()
 
+def reset_session():
+    """
+    Reset session token, to be safe
+    """
+    APP.logger.debug("Reset session token")
+    session.TOKEN = None
 
 if __name__ == "__main__":
 
@@ -168,4 +174,5 @@ if __name__ == "__main__":
             sys.exit(1)
         APP.config["secret_key"] = CONF.get("secret").encode("utf-8")
 
+    APP.before_request(reset_session)
     APP.run(host=CONF.get("listen"), port=CONF.get("port"), debug=CONF.get("verbose"))

Copy link
Owner

@tduboys tduboys left a comment

Choose a reason for hiding this comment

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

pylint review


Raise AuthenticationException in case of error
"""
TOKEN: str
Copy link
Owner

Choose a reason for hiding this comment

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

moffi_sdk/auth.py:37:8: C0103: Attribute name "TOKEN" doesn't conform to snake_case naming style (invalid-name)

@e-gautier
Copy link
Contributor Author

The best way would be to authenticate and create the session on server start and actually use the same token right?

@tduboys
Copy link
Owner

tduboys commented Nov 20, 2022

The best way would be to authenticate and create the session on server start and actually use the same token right?

probably not, for 2 reasons

  • I suppose the session token have a time limit
  • One server can handle multiple clients with different accounts, every client have this own login and token

I suggest to re-signing on every request
It takes times, but calendar client will do 1 request every X hours, it's not too frequent

@e-gautier
Copy link
Contributor Author

The signin method will reset the token on each request but I get your point. I will seek for a better solution.

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