Skip to content

Commit 356afee

Browse files
committed
Adding refresh command, upgrading to 0.2.1
1 parent f412163 commit 356afee

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ requires = [
44
"certifi>=14.05.14",
55
"typer>=0.16",
66
"inquirer>=3.4.0",
7-
"recodex-pylib>=0.2.0"
7+
"recodex-pylib>=0.2.1"
88
]
99
build-backend = "setuptools.build_meta"
1010

1111
[project]
1212
name = "recodex-cli"
13-
version = "0.2.0"
13+
version = "0.2.1"
1414
authors = [
1515
{ name="Vojtech Kloda", email="[email protected]" },
1616
{ name="Martin Kruliš", email="[email protected]"},
@@ -28,7 +28,7 @@ dependencies = [
2828
"certifi>=14.05.14",
2929
"typer>=0.16",
3030
"inquirer>=3.4.0",
31-
"recodex-pylib>=0.2.0"
31+
"recodex-pylib>=0.2.1"
3232
]
3333

3434
[project.scripts]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ typer >= 0.16
22
inquirer >= 3.4.0
33
twine >= 6.1.0
44
build >= 1.2.2
5-
recodex-pylib==0.2.0
5+
recodex-pylib==0.2.1
66
flask >= 3.1.1
77
flake8 >= 7.3.0

src/recodex_cli/console.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,22 @@ def status(
177177
bool, typer.Option(help="Execution Verbosity")
178178
] = False,
179179
):
180-
"""Prints the current login status.
180+
"""Prints the current session status.
181181
"""
182182

183183
session = client_factory.load_session_with_verbosity(verbose)
184184
if session:
185-
typer.echo(f"Session active for URL: {session.api_url}")
186-
typer.echo(f"Token expiration time: {session.token_expiration_time}")
187-
typer.echo(f"User ID: {session.user_id}")
185+
typer.echo(f"Session active for URL: {session.get_api_url()}")
186+
typer.echo(f"Token expiration time: {session.get_token_expiration_time()}")
187+
typer.echo(f"User ID: {session.get_user_id()}")
188188

189189
def load_and_print_user():
190190
if verbose:
191191
typer.echo(typer.style("Loading user details...", fg=typer.colors.BRIGHT_BLACK))
192192

193193
client = client_factory.get_client_with_verbosity(verbose)
194194
user = client.send_request_by_callback(
195-
DefaultApi.users_presenter_action_detail, path_params={"id": session.user_id}
195+
DefaultApi.users_presenter_action_detail, path_params={"id": session.get_user_id()}
196196
).get_payload()
197197
if user is None:
198198
typer.echo("User not found.", err=True)
@@ -210,5 +210,19 @@ def load_and_print_user():
210210
cmd_utils.execute_with_verbosity(load_and_print_user, verbose)
211211

212212

213+
@app.command()
214+
def refresh(
215+
verbose: Annotated[
216+
bool, typer.Option(help="Execution Verbosity")
217+
] = False,
218+
):
219+
"""Refreshes the current session by obtaining a new token.
220+
221+
The session must have a valid token.
222+
"""
223+
224+
cmd_utils.execute_with_verbosity(client_factory.refresh_session, verbose)
225+
226+
213227
if __name__ == "__main__":
214228
app()

src/recodex_cli/utils/client_factory.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,18 @@ def load_session_with_verbosity(verbose: bool):
111111
typer.echo(f"Session file path: {client_factory.session_path}")
112112
return None
113113

114-
if session.is_token_expired:
114+
if session.is_token_expired():
115115
typer.echo("Session token has expired.")
116116
if verbose:
117-
typer.echo(f"Token expired at {session.token_expiration_time}.")
117+
typer.echo(f"Token expired at {session.get_token_expiration_time()}.")
118118
typer.echo(f"Expired API URL: {session.api_url}")
119-
typer.echo(f"Expired user ID: {session.user_id}")
119+
typer.echo(f"Expired user ID: {session.get_user_id()}")
120120

121121
return None
122122

123123
return session
124+
125+
126+
def refresh_session():
127+
"""Refresh the session token even if it is not close to expiration."""
128+
client_factory.refresh_session()

0 commit comments

Comments
 (0)