diff options
author | Munyoki Kilyungi | 2024-03-06 15:37:57 +0300 |
---|---|---|
committer | Munyoki Kilyungi | 2024-03-08 15:03:52 +0300 |
commit | 82f76b879be1baafeddc80bc361744e59e47e42b (patch) | |
tree | 622ce1385f840c3a9a10062a091d3ed08af15917 /gn_auth/auth/authentication/oauth2/models/authorization_code.py | |
parent | cce9a772d6fe55c62368f6895492a8683e7b82ca (diff) | |
download | gn-auth-82f76b879be1baafeddc80bc361744e59e47e42b.tar.gz |
Replace "if" branching with "monad_from_none_or_value".
* gn_auth/auth/authentication/oauth2/models/authorization_code.py:
Import "monad_from_none_or_value".
(authorisation_code): Replace if branching for Nothing/Just check with "monad_from_none_or_value".
* gn_auth/auth/authentication/oauth2/models/oauth2token.py: Import
"monad_from_none_or_value".
(__token_from_resultset__): Replace if branching for Nothing/Just
check with "monad_from_none_or_value".
(token_by_access_token): Ditto.
(token_by_refresh_token): Ditto.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn_auth/auth/authentication/oauth2/models/authorization_code.py')
-rw-r--r-- | gn_auth/auth/authentication/oauth2/models/authorization_code.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/gn_auth/auth/authentication/oauth2/models/authorization_code.py b/gn_auth/auth/authentication/oauth2/models/authorization_code.py index faffca1..7bce0ca 100644 --- a/gn_auth/auth/authentication/oauth2/models/authorization_code.py +++ b/gn_auth/auth/authentication/oauth2/models/authorization_code.py @@ -3,6 +3,7 @@ from uuid import UUID from datetime import datetime from typing import NamedTuple +from pymonad.tools import monad_from_none_or_value from pymonad.maybe import Just, Maybe, Nothing from gn_auth.auth.db import sqlite3 as db @@ -67,9 +68,11 @@ def authorisation_code(conn: db.DbConnection , "WHERE code=:code AND client_id=:client_id") cursor.execute( query, {"code": code, "client_id": str(client.client_id)}) - result = cursor.fetchone() - if result: - return Just(AuthorisationCode( + + return monad_from_none_or_value( + Nothing, Just, cursor.fetchone() + ).then( + lambda result: AuthorisationCode( code_id=UUID(result["code_id"]), code=result["code"], client=client, @@ -80,7 +83,6 @@ def authorisation_code(conn: db.DbConnection , code_challenge=result["code_challenge"], code_challenge_method=result["code_challenge_method"], user=user_by_id(conn, UUID(result["user_id"])))) - return Nothing def save_authorisation_code(conn: db.DbConnection, auth_code: AuthorisationCode) -> AuthorisationCode: |