Checks for refresh token properly - #17
Conversation
a3ee017 to
4ee6c6e
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 96 110 +14
=========================================
+ Hits 96 110 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
d978175 to
e9c087a
Compare
cafb7d9 to
b429881
Compare
1cdb2a1 to
30821fd
Compare
30821fd to
8755a47
Compare
8755a47 to
dc82761
Compare
|
commit feat(tests) has a conventional commit test(): |
| ) | ||
| case False: | ||
| token: dict[str, str] = keycloak_openid.refresh_token( # pyright: ignore | ||
| str(os.environ.get("REFRESHTOKEN")) # pyright: ignore |
There was a problem hiding this comment.
pyright ignore brings in a lot of checking. recommend you use a class for the TokenResponse
from typing import Any, TypedDict, cast
class TokenResponse(TypedDict):
access_token: str
refresh_token: str
refresh_expires_in: int
token = cast(TokenResponse, keycloak_openid.token(...),)| redirect_uri=f"http://localhost:{port}/", | ||
| code_verifier=code_verifier, | ||
| ) | ||
| match open_auth_url(auth_url, port): |
There was a problem hiding this comment.
match on a bool can be replaced by if-else
| try: | ||
| httpd.handle_request() | ||
| os.environ["AUTH"] = httpd.auth_code | ||
| dotenv.set_key("src/.env", "AUTH", httpd.auth_code) |
There was a problem hiding this comment.
somewhere in a script or test it is worth making sure the key has appropriate permissions - chmod 600
| finally: | ||
| httpd.socket.shutdown(socket.SHUT_RDWR) | ||
| httpd.server_close() | ||
| def open_auth_url(auth_url: str, port: int) -> bool: |
There was a problem hiding this comment.
can break the function up to have *check if it is valid" seprately - this explains the open_auht_url function and makes the subsequent testing much easier.
| ) | ||
| case False: | ||
| token: dict[str, str] = keycloak_openid.refresh_token( # pyright: ignore | ||
| str(os.environ.get("REFRESHTOKEN")) # pyright: ignore |
There was a problem hiding this comment.
Error handling when REFRESHTOKEN equals none / empty string etc.
Hi, please look at this second
Currently adds a checker to see if we have a refresh token, then uses this as opposed to opening a browser every time.
Further, updates the copier template and pre-commit copier template, as despite it working before, I realise now that given the updates to the workflow, that jinja formatting and yaml formatting do not mix - {{inputs.parameters.extension}} is now being interpreted as raw text, while {{repo_name}} is interpreted as a variable copier can use.