sweatstack-cli 0.17.0__py3-none-any.whl → 0.17.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,24 +4,29 @@ from __future__ import annotations
4
4
 
5
5
  import json
6
6
  import os
7
+ import re
7
8
  import time
8
9
  from dataclasses import dataclass
9
10
  from pathlib import Path
10
11
  from typing import Protocol
12
+ from urllib.parse import urlsplit
11
13
 
12
14
  import platformdirs
13
15
 
16
+ from sweatstack_cli.config import DEFAULT_API_URL, get_settings
14
17
 
15
- def get_tokens_path() -> Path:
18
+
19
+ def get_tokens_path(api_url: str | None = None) -> Path:
16
20
  """
17
- Get the path to the tokens file.
21
+ Get the path to the tokens file of the SweatStack at `api_url` (`SWEATSTACK_URL`'s by default).
18
22
 
19
- Uses platformdirs for OS-appropriate user data directory.
20
- This path is shared with the sweatstack Python library for
21
- seamless interoperability.
23
+ Uses platformdirs for OS-appropriate user data directory. Production's sign-in is
24
+ `tokens.json`, shared with the sweatstack Python library for seamless interoperability.
25
+ Any other SweatStack, such as staging, keeps its own file named after its host, so
26
+ signing in there never replaces the production sign-in.
22
27
 
23
28
  Returns:
24
- Path to tokens.json file.
29
+ Path to tokens.json, or tokens-{host}.json for another SweatStack.
25
30
 
26
31
  Platform-specific paths:
27
32
  - macOS: ~/Library/Application Support/SweatStack/tokens.json
@@ -29,7 +34,11 @@ def get_tokens_path() -> Path:
29
34
  - Windows: %APPDATA%\\SweatStack\\SweatStack\\tokens.json
30
35
  """
31
36
  data_dir = Path(platformdirs.user_data_dir("SweatStack", "SweatStack"))
32
- return data_dir / "tokens.json"
37
+ url = (api_url or get_settings().api_url).rstrip("/")
38
+ if url == DEFAULT_API_URL:
39
+ return data_dir / "tokens.json"
40
+ host = re.sub(r"[^A-Za-z0-9.-]", "-", urlsplit(url).netloc or url)
41
+ return data_dir / f"tokens-{host}.json"
33
42
 
34
43
 
35
44
  @dataclass(frozen=True, slots=True)
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  from datetime import datetime
6
+ from typing import Any
6
7
 
7
8
  import typer
8
9
 
@@ -10,7 +11,7 @@ from sweatstack_cli.api import APIClient
10
11
  from sweatstack_cli.auth import Authenticator
11
12
  from sweatstack_cli.auth.jwt import decode_jwt_payload
12
13
  from sweatstack_cli.console import console
13
- from sweatstack_cli.exceptions import APIError, AuthenticationError
14
+ from sweatstack_cli.exceptions import APIError, AuthenticationError, SecondFactorRequired
14
15
  from sweatstack_cli.version_check import check_for_update
15
16
 
16
17
 
@@ -92,18 +93,26 @@ def status() -> None:
92
93
  auth = Authenticator()
93
94
  tokens = auth.get_valid_tokens()
94
95
 
96
+ user: dict[str, Any] | None = None
97
+ if tokens is not None:
98
+ try:
99
+ user = APIClient(authenticator=auth).get("/api/v1/oauth/userinfo")
100
+ except SecondFactorRequired:
101
+ pass # A step-up is not a refusal of the sign-in.
102
+ except AuthenticationError:
103
+ # Stored tokens SweatStack refuses (revoked, or from another SweatStack) are no sign-in.
104
+ tokens = None
105
+ except APIError:
106
+ pass # SweatStack could not say who this is; the sign-in may still be good.
107
+
95
108
  if tokens is None:
96
109
  console.print("[red]✗[/red] Not authenticated")
97
110
  else:
98
111
  console.print("[green]✓[/green] Authenticated")
99
- try:
100
- client = APIClient(authenticator=auth)
101
- user = client.get("/api/v1/oauth/userinfo")
112
+ if user is not None:
102
113
  console.print(f" Name: {_display_name(user)}")
103
114
  console.print(f" Email: {user.get('email', 'unknown')}")
104
115
  console.print(f" ID: {user.get('sub', 'unknown')}")
105
- except (AuthenticationError, APIError):
106
- pass # Silently skip user info on error
107
116
  console.print(f" Passkey: {_confirmation(tokens.access_token)}")
108
117
 
109
118
  # Check version
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: sweatstack-cli
3
- Version: 0.17.0
3
+ Version: 0.17.1
4
4
  Summary: Command-line interface for SweatStack — the sports data platform for developers
5
5
  Project-URL: Homepage, https://sweatstack.no
6
6
  Project-URL: Documentation, https://docs.sweatstack.no
@@ -13,10 +13,10 @@ sweatstack_cli/auth/__init__.py,sha256=7oGPfkn3KswBM4Ffk6-uK1Ym8uL02h0eFPbZ9I50_
13
13
  sweatstack_cli/auth/callback_server.py,sha256=37aTX7smvmrn1azRzOPPDkuBwcunUt3KnNVZ5SCJRLM,6578
14
14
  sweatstack_cli/auth/jwt.py,sha256=Ja6ccFyRKtX5MPjFdHNavVYf8KTz0MYT86StbnF-cwg,1502
15
15
  sweatstack_cli/auth/pkce.py,sha256=sO_xUeN1UIvXKX0yEIGgMTIIzvfCOCUwlyNAveEd16k,1542
16
- sweatstack_cli/auth/tokens.py,sha256=kc8ytoO9PAyjLD6wUTIagVuP7_ia5ZjW5m_WjXIRIkA,4942
16
+ sweatstack_cli/auth/tokens.py,sha256=cR9xEM8D5XjYLTsDJMr90vz7MrarLbCtNP0AR6uoZ5c,5558
17
17
  sweatstack_cli/commands/__init__.py,sha256=YCO8wYVvdGeoEI0p_oUm8ANLneuET4SHsKDjitMjAgY,35
18
18
  sweatstack_cli/commands/app.py,sha256=90AwUm5RhagE5tZww77Fk9B0vpZFlC59OlylGXTxWC0,9055
19
- sweatstack_cli/commands/auth.py,sha256=vmiYfkvrHIOyF0DTC6JI95dieu9uyaq6xvx9M9_grQE,4754
19
+ sweatstack_cli/commands/auth.py,sha256=-KkZzQI1oTUKfvzzFhLgjoSOvq3x40gT6_7HzFo2dtc,5143
20
20
  sweatstack_cli/commands/page.py,sha256=G58KEsiCeq4hD0Z5ot2g9W6vBH6iZu-lCvdA1kzep-U,24612
21
21
  sweatstack_cli/commands/tool.py,sha256=ZL2XXgAo7G_Fm5K8bGsigMis8Pz22Hs3sAKPM6jAJsE,16864
22
22
  sweatstack_cli/services/__init__.py,sha256=pFrcjumdHNRU8aa3bxplq4jhCivH2YGGqkGG8yIMv20,337
@@ -41,7 +41,7 @@ sweatstack_cli/tools/rewrite.py,sha256=19GkK-aGmjoAPUrY0336g4Pjl_8Uu5IMHmY7d-vHs
41
41
  sweatstack_cli/tools/server.py,sha256=8ek-u1SlrCbi2vk12EjRPn28Mc2nyfrngMUXhVW09WM,8212
42
42
  sweatstack_cli/tools/signin.py,sha256=dZPOaf2WOzZ3D5d3zmdqCnwPvP-OkBaF-wh4_JuUc_s,16915
43
43
  sweatstack_cli/tools/template.py,sha256=RKX6dfnsEY3-CyjbcCxmWobHOyjm7WdxRVXFzWbaYIE,4009
44
- sweatstack_cli-0.17.0.dist-info/METADATA,sha256=EwjgcUbhoA7wvC_hULHwLZcgeJrv6vx_5xuZQ7akQ7k,5678
45
- sweatstack_cli-0.17.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
46
- sweatstack_cli-0.17.0.dist-info/entry_points.txt,sha256=rnH0EV1U9CQlmKQcJ7RmxGpNRTa9J-YdiIJZDYrAXb4,56
47
- sweatstack_cli-0.17.0.dist-info/RECORD,,
44
+ sweatstack_cli-0.17.1.dist-info/METADATA,sha256=1Rc_VqFYdZbr2NyHOpzRTAjNxx9qEe4vWHcLqq4MR8g,5678
45
+ sweatstack_cli-0.17.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
46
+ sweatstack_cli-0.17.1.dist-info/entry_points.txt,sha256=rnH0EV1U9CQlmKQcJ7RmxGpNRTa9J-YdiIJZDYrAXb4,56
47
+ sweatstack_cli-0.17.1.dist-info/RECORD,,