zepben.ewb 1.0.0b10__py3-none-any.whl → 1.1.0b1__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.
@@ -7,12 +7,13 @@
7
7
  __all__ = ["ZepbenTokenFetcher", "create_token_fetcher", "get_token_fetcher", "create_token_fetcher_managed_identity"]
8
8
 
9
9
  import warnings
10
+ from dataclasses import dataclass, Field, field, InitVar
10
11
  from datetime import datetime
11
- from typing import Optional, Union, Callable, Dict
12
+ from typing import Optional, Callable
12
13
 
13
14
  import jwt
14
15
  import requests
15
- from dataclassy import dataclass
16
+ from requests import Response
16
17
  from urllib3.exceptions import InsecureRequestWarning
17
18
 
18
19
  from zepben.ewb.auth.common.auth_exception import AuthException
@@ -21,11 +22,15 @@ from zepben.ewb.auth.common.auth_method import AuthMethod
21
22
  from zepben.ewb.auth.common.auth_provider_config import AuthProviderConfig, create_auth_provider_config, fetch_provider_details
22
23
 
23
24
 
24
- def _fetch_token_generator(is_entraid: bool, use_identity: bool, identity_url: Optional[str] = None) -> Callable[
25
- [Dict, Dict, str, bool, bool], requests.Response]:
25
+ def _fetch_token_generator(
26
+ is_entraid: bool,
27
+ use_identity: bool,
28
+ identity_url: Optional[str] = None
29
+ ) -> Callable[[dict, dict, str, Optional[bool], Optional[bool]], Response]:
30
+
26
31
  def post(
27
- refresh_request_data: Dict,
28
- token_request_data: Dict,
32
+ refresh_request_data: dict,
33
+ token_request_data: dict,
29
34
  token_endpoint: str,
30
35
  refresh: bool,
31
36
  verify: bool
@@ -48,7 +53,14 @@ def _fetch_token_generator(is_entraid: bool, use_identity: bool, identity_url: O
48
53
  verify=verify
49
54
  )
50
55
 
51
- def _get_token_response(refresh_request_data: Dict, token_request_data: Dict, token_endpoint: str, refresh: bool, verify: bool) -> requests.Response:
56
+ def _get_token_response(
57
+ refresh_request_data: dict,
58
+ token_request_data: dict,
59
+ token_endpoint: str,
60
+ refresh: bool,
61
+ verify: bool
62
+ ) -> requests.Response:
63
+
52
64
  refresh = not is_entraid and refresh # At the moment Azure auth doesn't support refresh tokens. So we always force new tokens.
53
65
 
54
66
  return post(
@@ -59,53 +71,59 @@ def _fetch_token_generator(is_entraid: bool, use_identity: bool, identity_url: O
59
71
  verify
60
72
  )
61
73
 
62
- def _get_token_response_from_identity(refresh_request_data: Dict, token_request_data: Dict, token_endpoint: str, refresh: bool = False,
63
- verify: bool = False) -> requests.Response:
74
+ def _get_token_response_from_identity(
75
+ refresh_request_data: dict,
76
+ token_request_data: dict,
77
+ token_endpoint: str,
78
+ refresh: Optional[bool] = False,
79
+ verify: Optional[bool] = False
80
+ ) -> requests.Response:
81
+
64
82
  return requests.get(identity_url, headers={"Metadata": "true"}, verify=verify)
65
83
 
66
84
  if use_identity:
67
85
  if not identity_url:
68
- raise ValueError("Misconfiguration dectected - if use_identity is true, identity_url must also be provided. This is a bug, contact Zepben.")
86
+ raise ValueError("Misconfiguration detected - if use_identity is true, identity_url must also be provided. This is a bug, contact Zepben.")
69
87
  return _get_token_response_from_identity
70
88
  else:
71
89
  return _get_token_response
72
90
 
73
91
 
74
- @dataclass
75
- class ZepbenTokenFetcher(object):
92
+ @dataclass(init=True, repr=True, eq=True)
93
+ class ZepbenTokenFetcher:
76
94
  """
77
95
  Fetches access tokens from an authentication provider using the OAuth 2.0 protocol.
78
- """
79
96
 
80
- auth_method: AuthMethod = AuthMethod.OAUTH
81
- """ Deprecated. Kept for backwards compatibility, but this is now unused. """
97
+ :param audience: Audience to use when requesting tokens
98
+ :param token_endpoint: The domain of the token issuer.
99
+ :param token_request_data: Data to pass in token requests.
100
+ :param refresh_request_data: Data to pass in refresh token requests.
101
+ :param verify: Passed through to requests.post(). When this is a boolean, it determines whether to verify the HTTPS
102
+ certificate of the OAUTH service or not. When this is a string, it is used as the filename of the certificate
103
+ truststore to use when verifying the OAUTH service.
104
+ :param auth_method: Deprecated. Kept for backwards compatibility, but this is now unused.
105
+ """
82
106
 
83
107
  audience: str
84
- """ Audience to use when requesting tokens """
85
-
86
- token_endpoint: str
87
- """ The domain of the token issuer. """
88
-
89
- token_request_data = {}
90
- """ Data to pass in token requests. """
91
-
92
- refresh_request_data = {}
93
- """ Data to pass in refresh token requests. """
108
+ issuer: Optional[str] = None
109
+ token_endpoint: Optional[str] = None
110
+ token_request_data: Optional[dict] = field(default_factory=dict)
111
+ refresh_request_data: Optional[dict] = field(default_factory=dict)
112
+ verify: Optional[bool | str] = None
113
+ auth_method: Optional[AuthMethod] = None
94
114
 
95
- verify: Union[bool, str] = True
96
- """
97
- Passed through to requests.post(). When this is a boolean, it determines whether or not to verify the HTTPS certificate of the OAUTH service.
98
- When this is a string, it is used as the filename of the certificate truststore to use when verifying the OAUTH service.
99
- """
115
+ _request_token: InitVar[Callable[[dict, dict, str, Optional[bool], Optional[bool]], requests.Response]] = None
100
116
 
101
- _request_token: Callable[[Dict, Dict, str, bool, bool], requests.Response] = _fetch_token_generator(False, False)
117
+ _access_token: Optional[str] = None
118
+ _refresh_token: Optional[str] = None
119
+ _token_expiry: Optional[datetime] = datetime.min
120
+ token_type: Optional[str] = None
102
121
 
103
- _access_token = None
104
- _refresh_token = None
105
- _token_expiry = datetime.min
106
- _token_type = None
122
+ def __post_init__(self, _request_token):
123
+ if _request_token is None:
124
+ _request_token = _fetch_token_generator(False, False)
125
+ self._request_token = _request_token
107
126
 
108
- def __init__(self):
109
127
  self.token_request_data["audience"] = self.audience
110
128
  self.refresh_request_data["audience"] = self.audience
111
129
 
@@ -134,7 +152,7 @@ class ZepbenTokenFetcher(object):
134
152
 
135
153
  return f"{self._token_type} {self._access_token}"
136
154
 
137
- def _fetch_token(self, refresh: bool = False):
155
+ def _fetch_token(self, refresh: Optional[bool] = False):
138
156
  if refresh:
139
157
  self.refresh_request_data["refresh_token"] = self._refresh_token
140
158
 
@@ -174,11 +192,11 @@ class ZepbenTokenFetcher(object):
174
192
 
175
193
  def create_token_fetcher(
176
194
  conf_address: str,
177
- verify_conf: Union[bool, str] = True,
178
- verify_auth: Union[bool, str] = True,
179
- auth_type_field: str = "authType",
180
- audience_field: str = "audience",
181
- issuer_field: str = "issuer",
195
+ verify_conf: Optional[bool | str] = True,
196
+ verify_auth: Optional[bool | str] = True,
197
+ auth_type_field: Optional[str] = "authType",
198
+ audience_field: Optional[str] = "audience",
199
+ issuer_field: Optional[str] = "issuer",
182
200
  ) -> Optional[ZepbenTokenFetcher]:
183
201
  """
184
202
  Helper method to fetch auth related configuration from `conf_address` and create a :class:`ZepbenTokenFetcher`
@@ -194,6 +212,7 @@ def create_token_fetcher(
194
212
 
195
213
  :returns: A :class:`ZepbenTokenFetcher` if the server reported authentication was configured, otherwise None.
196
214
  """
215
+
197
216
  with warnings.catch_warnings():
198
217
  if not verify_conf:
199
218
  warnings.filterwarnings("ignore", category=InsecureRequestWarning)
@@ -264,6 +283,7 @@ def create_token_fetcher_managed_identity(identity_url: str, verify_auth: bool)
264
283
  "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=5ffcfee6-34cd-4c5c-bb7e-c5261d739341"
265
284
  :param verify_auth: Whether to verify certificates for the identity_url. Only applies for https URLs.
266
285
  """
286
+
267
287
  return ZepbenTokenFetcher(
268
288
  audience="",
269
289
  issuer="",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zepben.ewb
3
- Version: 1.0.0b10
3
+ Version: 1.1.0b1
4
4
  Summary: Python SDK for interacting with the Energy Workbench platform
5
5
  Author-email: Kurt Greaves <kurt.greaves@zepben.com>, Max Chesterfield <max.chesterfield@zepben.com>
6
6
  License-Expression: MPL-2.0
@@ -19,7 +19,6 @@ Requires-Dist: typing_extensions==4.12.2
19
19
  Requires-Dist: requests<3.0.0,>=2.26.0
20
20
  Requires-Dist: urllib3<1.27.0,>=1.26.6
21
21
  Requires-Dist: PyJWT<2.2.0,>=2.1.0
22
- Requires-Dist: dataclassy==0.6.2
23
22
  Provides-Extra: test
24
23
  Requires-Dist: pytest<9,>=7.4.4; extra == "test"
25
24
  Requires-Dist: pytest-cov==6.1.1; extra == "test"
@@ -41,7 +40,7 @@ The Python Evolve SDK contains everything necessary to communicate with a [Zepbe
41
40
 
42
41
  # Requirements #
43
42
 
44
- - Python 3.9 or later
43
+ - Python 3.10 or later
45
44
 
46
45
  # Installation #
47
46
 
@@ -4,7 +4,7 @@ zepben/ewb/types.py,sha256=067jjQX6eCbgaEtlQPdSBi_w4_16unbP1f_g5NrVj_w,627
4
4
  zepben/ewb/util.py,sha256=lgxqbGEQO8df-Bs88-4bVijB8CY9rY8ox8WjibqZWnM,5728
5
5
  zepben/ewb/auth/__init__.py,sha256=DUsi8JWvKMQt4xEUCHbCVPjGkEfr2MRu2JIvobYTB-M,406
6
6
  zepben/ewb/auth/client/__init__.py,sha256=nFdcikJb3FegBko35m1xxmjMmC3cZCaqr8ohypQJQIQ,245
7
- zepben/ewb/auth/client/zepben_token_fetcher.py,sha256=HdRkKuYadZ3EmxnbfrnBYc8t43zxPF3tA6AHr5yInYw,11548
7
+ zepben/ewb/auth/client/zepben_token_fetcher.py,sha256=q1-co2LSWPwuSzzUZmNLYmjsQaCIrfSu4tOxwS_TMMk,12201
8
8
  zepben/ewb/auth/common/__init__.py,sha256=nFdcikJb3FegBko35m1xxmjMmC3cZCaqr8ohypQJQIQ,245
9
9
  zepben/ewb/auth/common/auth_exception.py,sha256=wcrDQQ7caxA5MrNuSVq2TdrGugisgEwSNenZ4kTgRJI,451
10
10
  zepben/ewb/auth/common/auth_method.py,sha256=_kYJHVv1KU5gxsqJe-6jSIoTpc9DieTGxh4750GwVLM,736
@@ -634,8 +634,8 @@ zepben/ewb/streaming/mutations/update_network_state_client.py,sha256=e0Oma5PRT8m
634
634
  zepben/ewb/streaming/mutations/update_network_state_service.py,sha256=irR-TO67QXRyBmK8PU8SzM31NKSSefZt_nQGHi5IhT8,3260
635
635
  zepben/ewb/testing/__init__.py,sha256=waADXEvfUG9wAN4STx5uIUHOv0UnpZLH2qU1LXgaDBc,243
636
636
  zepben/ewb/testing/test_network_builder.py,sha256=KG0o2ZHUswx3xClu-JnLs_pYIYbQ5jjtvtyZ7LI6IZ8,38092
637
- zepben_ewb-1.0.0b10.dist-info/licenses/LICENSE,sha256=aAHD66h6PQIETpkJDvg5yEObyFvXUED8u7S8dlh6K0Y,16725
638
- zepben_ewb-1.0.0b10.dist-info/METADATA,sha256=MhdTHKQT_hlmP__TvX-s9XGPqrv4gnm6ZySEsCB2lxo,3250
639
- zepben_ewb-1.0.0b10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
640
- zepben_ewb-1.0.0b10.dist-info/top_level.txt,sha256=eVLDJiO6FGjL_Z7KdmFE-R8uf1Q07aaVLGe9Ee4kmBw,7
641
- zepben_ewb-1.0.0b10.dist-info/RECORD,,
637
+ zepben_ewb-1.1.0b1.dist-info/licenses/LICENSE,sha256=aAHD66h6PQIETpkJDvg5yEObyFvXUED8u7S8dlh6K0Y,16725
638
+ zepben_ewb-1.1.0b1.dist-info/METADATA,sha256=1WLoauo-R4sPX5xNFtUdsvVnMO8au9hn2uGEpK-nC4Y,3217
639
+ zepben_ewb-1.1.0b1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
640
+ zepben_ewb-1.1.0b1.dist-info/top_level.txt,sha256=eVLDJiO6FGjL_Z7KdmFE-R8uf1Q07aaVLGe9Ee4kmBw,7
641
+ zepben_ewb-1.1.0b1.dist-info/RECORD,,