@planqk/planqk-service-sdk 2.6.0 → 2.6.2

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.
package/.fossa.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  version: 3
2
2
  project:
3
3
  id: "git@gitlab.com:planqk-foss/planqk-service-sdk.git"
4
- name: "Platform-API-SDK"
4
+ name: "Platform-Service-SDK"
5
5
  labels:
6
6
  - "Platform"
7
7
  - "Open Source"
@@ -55,9 +55,15 @@
55
55
  "# Create a new PlanqkServiceClient instance\n",
56
56
  "client = PlanqkServiceClient(\n",
57
57
  " service_endpoint, consumer_key, consumer_secret, token_endpoint\n",
58
- ")\n",
59
- "\n",
60
- "# List all service executions\n",
58
+ ")"
59
+ ]
60
+ },
61
+ {
62
+ "cell_type": "code",
63
+ "execution_count": null,
64
+ "metadata": {},
65
+ "outputs": [],
66
+ "source": [
61
67
  "service_executions = client.get_service_executions()\n",
62
68
  "print(f\"Found {len(service_executions)} service executions\")"
63
69
  ]
@@ -214,7 +220,7 @@
214
220
  "name": "python",
215
221
  "nbconvert_exporter": "python",
216
222
  "pygments_lexer": "ipython3",
217
- "version": "3.11.9"
223
+ "version": "3.11.11"
218
224
  }
219
225
  },
220
226
  "nbformat": 4,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planqk/planqk-service-sdk",
3
- "version": "2.6.0",
3
+ "version": "2.6.2",
4
4
  "description": "SDK to interact with PLANQK Managed Services.",
5
5
  "author": "Kipu Quantum GmbH",
6
6
  "contributors": [
@@ -1 +1 @@
1
- __version__ = "2.6.0"
1
+ __version__ = "2.6.2"
@@ -1,3 +1,4 @@
1
+ import logging
1
2
  import time
2
3
 
3
4
  from authlib.integrations.httpx_client import OAuth2Client
@@ -6,6 +7,8 @@ DEFAULT_TOKEN_ENDPOINT = "https://gateway.platform.planqk.de/token"
6
7
 
7
8
 
8
9
  class PlanqkServiceAuth:
10
+ _logger = logging.getLogger(__name__)
11
+
9
12
  def __init__(self, consumer_key: str, consumer_secret: str, token_endpoint: str = DEFAULT_TOKEN_ENDPOINT):
10
13
  self._consumer_key = consumer_key
11
14
  self._consumer_secret = consumer_secret
@@ -17,12 +20,14 @@ class PlanqkServiceAuth:
17
20
  if self._token is None or self._last_token_fetch is None:
18
21
  self._refresh_token()
19
22
 
20
- if time.time() - self._last_token_fetch > self._token["expires_in"]:
23
+ # Refresh token 120 seconds before expiration to prevent race conditions
24
+ if time.time() - self._last_token_fetch >= (self._token["expires_in"] - 120):
21
25
  self._refresh_token()
22
26
 
23
27
  return self._token["access_token"]
24
28
 
25
29
  def _refresh_token(self):
30
+ self._logger.debug("Creating new token using client credentials flow")
26
31
  with OAuth2Client(self._consumer_key, self._consumer_secret) as client:
27
32
  token = client.fetch_token(self._token_endpoint, grant_type='client_credentials')
28
33
 
@@ -130,9 +130,7 @@ class PlanqkServiceClient:
130
130
  )
131
131
  self._api = PlanqkServiceApi(base_url=self._service_endpoint, token=self._auth.get_token)
132
132
  else:
133
- random_token = "".join(
134
- random.choices(string.ascii_letters + string.digits, k=21)
135
- )
133
+ random_token = "".join(random.choices(string.ascii_letters + string.digits, k=21))
136
134
  self._api = PlanqkServiceApi(base_url=self._service_endpoint, token=random_token)
137
135
 
138
136
  @property
package/pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "planqk-service-sdk"
3
- version = "2.6.0"
3
+ version = "2.6.2"
4
4
  description = "SDK to interact with PLANQK Managed Services."
5
5
  authors = [
6
6
  { name = "Kipu Quantum GmbH", email = "info@kipu-quantum.com" },