freva-client 2408.0.0.dev2__tar.gz → 2410.0.0__tar.gz

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.

Potentially problematic release.


This version of freva-client might be problematic. Click here for more details.

Files changed (19) hide show
  1. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/PKG-INFO +2 -1
  2. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/pyproject.toml +1 -0
  3. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/__init__.py +1 -1
  4. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/auth.py +22 -17
  5. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/cli/cli_app.py +4 -0
  6. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/MANIFEST.in +0 -0
  7. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/README.md +0 -0
  8. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/assets/share/freva/freva.toml +0 -0
  9. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/__main__.py +0 -0
  10. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/cli/__init__.py +0 -0
  11. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/cli/auth_cli.py +0 -0
  12. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/cli/cli_parser.py +0 -0
  13. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/cli/cli_utils.py +0 -0
  14. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/cli/databrowser_cli.py +0 -0
  15. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/py.typed +0 -0
  16. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/query.py +0 -0
  17. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/utils/__init__.py +0 -0
  18. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/utils/databrowser_utils.py +0 -0
  19. {freva_client-2408.0.0.dev2 → freva_client-2410.0.0}/src/freva_client/utils/logger.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: freva-client
3
- Version: 2408.0.0.dev2
3
+ Version: 2410.0.0
4
4
  Summary: Search for climate data based on key-value pairs
5
5
  Author-email: "DKRZ, Clint" <freva@dkrz.de>
6
6
  Requires-Python: >=3.8
@@ -22,6 +22,7 @@ Requires-Dist: authlib
22
22
  Requires-Dist: requests
23
23
  Requires-Dist: intake_esm
24
24
  Requires-Dist: rich
25
+ Requires-Dist: setuptools
25
26
  Requires-Dist: tomli
26
27
  Requires-Dist: typer
27
28
  Requires-Dist: tox ; extra == "dev"
@@ -28,6 +28,7 @@ dependencies = [
28
28
  "requests",
29
29
  "intake_esm",
30
30
  "rich",
31
+ "setuptools",
31
32
  "tomli",
32
33
  "typer",
33
34
  ]
@@ -17,5 +17,5 @@ need to apply data analysis plugins, please visit the
17
17
  from .auth import authenticate
18
18
  from .query import databrowser
19
19
 
20
- __version__ = "2408.0.0.dev2"
20
+ __version__ = "2410.0.0"
21
21
  __all__ = ["authenticate", "databrowser", "__version__"]
@@ -1,8 +1,8 @@
1
1
  """Module that handles the authentication at the rest service."""
2
2
 
3
- from datetime import datetime
3
+ import datetime
4
4
  from getpass import getpass, getuser
5
- from typing import Optional, TypedDict
5
+ from typing import Optional, TypedDict, Union
6
6
 
7
7
  from authlib.integrations.requests_client import OAuth2Session
8
8
 
@@ -14,9 +14,10 @@ Token = TypedDict(
14
14
  {
15
15
  "access_token": str,
16
16
  "token_type": str,
17
- "expires": float,
17
+ "expires": int,
18
18
  "refresh_token": str,
19
- "refresh_expires": float,
19
+ "refresh_expires": int,
20
+ "scope": str,
20
21
  },
21
22
  )
22
23
 
@@ -36,13 +37,13 @@ class Auth:
36
37
  self._auth_cls = OAuth2Session()
37
38
 
38
39
  @property
39
- def token_expiration_time(self) -> datetime:
40
+ def token_expiration_time(self) -> datetime.datetime:
40
41
  """Get the expiration time of an access token."""
41
42
  if self._auth_token is None:
42
43
  exp = 0.0
43
44
  else:
44
45
  exp = self._auth_token["expires"]
45
- return datetime.fromtimestamp(exp)
46
+ return datetime.datetime.fromtimestamp(exp, datetime.timezone.utc)
46
47
 
47
48
  def set_token(
48
49
  self,
@@ -50,19 +51,21 @@ class Auth:
50
51
  refresh_token: Optional[str] = None,
51
52
  expires_in: int = 10,
52
53
  refresh_expires_in: int = 10,
53
- expires: Optional[float] = None,
54
- refresh_expires: Optional[float] = None,
54
+ expires: Optional[Union[float, int]] = None,
55
+ refresh_expires: Optional[Union[float, int]] = None,
55
56
  token_type: str = "Bearer",
57
+ scope: str = "profile email address",
56
58
  ) -> Token:
57
59
  """Override the existing auth token."""
58
- now = datetime.now().timestamp()
60
+ now = datetime.datetime.now(datetime.timezone.utc).timestamp()
59
61
 
60
62
  self._auth_token = Token(
61
63
  access_token=access_token or "",
62
64
  refresh_token=refresh_token or "",
63
65
  token_type=token_type,
64
- expires=expires or now + expires_in,
65
- refresh_expires=refresh_expires or now + refresh_expires_in,
66
+ expires=int(expires or now + expires_in),
67
+ refresh_expires=int(refresh_expires or now + refresh_expires_in),
68
+ scope=scope,
66
69
  )
67
70
  return self._auth_token
68
71
 
@@ -75,9 +78,10 @@ class Auth:
75
78
  return self.set_token(
76
79
  access_token=auth["access_token"],
77
80
  token_type=auth["token_type"],
78
- expires_in=auth["expires_in"],
81
+ expires=auth["expires"],
79
82
  refresh_token=auth["refresh_token"],
80
- refresh_expires_in=auth["refresh_expires_in"],
83
+ refresh_expires=auth["refresh_expires"],
84
+ scope=auth["scope"],
81
85
  )
82
86
  except KeyError:
83
87
  logger.warning("Failed to refresh token: %s", auth.get("detail", ""))
@@ -94,7 +98,7 @@ class Auth:
94
98
  """
95
99
  if not self._auth_token:
96
100
  raise ValueError("You must authenticate first.")
97
- now = datetime.now().timestamp()
101
+ now = datetime.datetime.now(datetime.timezone.utc).timestamp()
98
102
  if now > self._auth_token["refresh_expires"]:
99
103
  raise ValueError("Refresh token has expired.")
100
104
  if now > self._auth_token["expires"] and auth_url:
@@ -111,9 +115,10 @@ class Auth:
111
115
  return self.set_token(
112
116
  access_token=auth["access_token"],
113
117
  token_type=auth["token_type"],
114
- expires_in=auth["expires_in"],
118
+ expires=auth["expires"],
115
119
  refresh_token=auth["refresh_token"],
116
- refresh_expires_in=auth["refresh_expires_in"],
120
+ refresh_expires=auth["refresh_expires"],
121
+ scope=auth["scope"],
117
122
  )
118
123
  except KeyError:
119
124
  logger.error("Failed to authenticate: %s", auth.get("detail", ""))
@@ -141,7 +146,7 @@ class Auth:
141
146
  username = username or getuser()
142
147
  if self._auth_token is None or force:
143
148
  return self._login_with_password(cfg.auth_url, username)
144
- if self.token_expiration_time < datetime.now():
149
+ if self.token_expiration_time < datetime.datetime.now(datetime.timezone.utc):
145
150
  self._refresh(cfg.auth_url, self._auth_token["refresh_token"], username)
146
151
  return self._auth_token
147
152
 
@@ -1,5 +1,6 @@
1
1
  """Freva the Free Evaluation System command line interface."""
2
2
 
3
+ import os
3
4
  from typing import Optional
4
5
 
5
6
  import typer
@@ -9,6 +10,9 @@ from .auth_cli import authenticate_cli
9
10
  from .cli_utils import APP_NAME, version_callback
10
11
  from .databrowser_cli import databrowser_app
11
12
 
13
+ if os.getenv("FREVA_NO_RICH_PANELS", "0") == "1":
14
+ typer.core.rich = None # type: ignore
15
+
12
16
  app = typer.Typer(
13
17
  name=APP_NAME,
14
18
  help=__doc__,