codemie-sdk-python 0.1.151__py3-none-any.whl → 0.1.153__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.
Potentially problematic release.
This version of codemie-sdk-python might be problematic. Click here for more details.
- codemie_sdk/auth/credentials.py +1 -7
- codemie_sdk/client/client.py +16 -5
- codemie_sdk/utils/http.py +13 -4
- {codemie_sdk_python-0.1.151.dist-info → codemie_sdk_python-0.1.153.dist-info}/METADATA +1 -1
- {codemie_sdk_python-0.1.151.dist-info → codemie_sdk_python-0.1.153.dist-info}/RECORD +6 -6
- {codemie_sdk_python-0.1.151.dist-info → codemie_sdk_python-0.1.153.dist-info}/WHEEL +0 -0
codemie_sdk/auth/credentials.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"""Authentication credentials module for CodeMie SDK."""
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
|
-
|
|
5
3
|
import requests
|
|
6
4
|
from typing import Optional
|
|
7
5
|
|
|
@@ -38,17 +36,13 @@ class KeycloakCredentials:
|
|
|
38
36
|
self.password = password
|
|
39
37
|
self.verify_ssl = verify_ssl
|
|
40
38
|
|
|
41
|
-
if
|
|
42
|
-
(client_id and client_secret) or (username and password)
|
|
43
|
-
):
|
|
39
|
+
if not ((client_id and client_secret) or (username and password)):
|
|
44
40
|
raise ValueError(
|
|
45
41
|
"Either client credentials (client_id, client_secret) or "
|
|
46
42
|
"user credentials (username, password) must be provided"
|
|
47
43
|
)
|
|
48
44
|
|
|
49
45
|
def get_token(self) -> str:
|
|
50
|
-
if os.getenv("ENV", "").lower() == "local":
|
|
51
|
-
return ""
|
|
52
46
|
"""Get access token using either client credentials or password grant."""
|
|
53
47
|
url = (
|
|
54
48
|
f"{self.server_url}/realms/{self.realm_name}/protocol/openid-connect/token"
|
codemie_sdk/client/client.py
CHANGED
|
@@ -51,6 +51,7 @@ class CodeMieClient:
|
|
|
51
51
|
|
|
52
52
|
self._token: Optional[str] = None
|
|
53
53
|
self._api_domain = codemie_api_domain.rstrip("/")
|
|
54
|
+
self._is_localhost = self._is_localhost_domain(self._api_domain)
|
|
54
55
|
self._verify_ssl = verify_ssl
|
|
55
56
|
if not verify_ssl:
|
|
56
57
|
import requests
|
|
@@ -58,8 +59,8 @@ class CodeMieClient:
|
|
|
58
59
|
|
|
59
60
|
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
|
60
61
|
|
|
61
|
-
# Initialize token
|
|
62
|
-
self._token = self.auth.get_token()
|
|
62
|
+
# Initialize token
|
|
63
|
+
self._token = "" if self._is_localhost else self.auth.get_token()
|
|
63
64
|
|
|
64
65
|
# Initialize services with verify_ssl parameter and token
|
|
65
66
|
self.assistants = AssistantService(
|
|
@@ -84,13 +85,23 @@ class CodeMieClient:
|
|
|
84
85
|
@property
|
|
85
86
|
def token(self) -> str:
|
|
86
87
|
"""Get current token or fetch new one if not available."""
|
|
87
|
-
if
|
|
88
|
-
self._token = self.auth.get_token()
|
|
88
|
+
self._token = "" if self._is_localhost else self.auth.get_token()
|
|
89
89
|
return self._token
|
|
90
90
|
|
|
91
|
+
@staticmethod
|
|
92
|
+
def _is_localhost_domain(domain: str) -> bool:
|
|
93
|
+
"""Check if the domain is a localhost variant."""
|
|
94
|
+
domain_lower = domain.lower()
|
|
95
|
+
localhost_patterns = [
|
|
96
|
+
"localhost",
|
|
97
|
+
"127.0.0.1",
|
|
98
|
+
"0.0.0.0",
|
|
99
|
+
]
|
|
100
|
+
return any(pattern in domain_lower for pattern in localhost_patterns)
|
|
101
|
+
|
|
91
102
|
def refresh_token(self) -> str:
|
|
92
103
|
"""Force token refresh."""
|
|
93
|
-
self._token = self.auth.get_token()
|
|
104
|
+
self._token = "" if self._is_localhost else self.auth.get_token()
|
|
94
105
|
# Update token in services
|
|
95
106
|
self.assistants = AssistantService(
|
|
96
107
|
self._api_domain, self._token, verify_ssl=self._verify_ssl
|
codemie_sdk/utils/http.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"""HTTP utilities for CodeMie SDK."""
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
3
|
from typing import TypeVar, Type, Optional, Any, Union, Dict, List, get_origin, get_args
|
|
5
4
|
from pydantic import BaseModel
|
|
6
5
|
import requests
|
|
@@ -46,6 +45,18 @@ class ApiRequestHandler:
|
|
|
46
45
|
self._base_url = base_url.rstrip("/")
|
|
47
46
|
self._token = token
|
|
48
47
|
self._verify_ssl = verify_ssl
|
|
48
|
+
self._is_localhost = self._is_localhost_domain(base_url)
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def _is_localhost_domain(domain: str) -> bool:
|
|
52
|
+
"""Check if the domain is a localhost variant."""
|
|
53
|
+
domain_lower = domain.lower()
|
|
54
|
+
localhost_patterns = [
|
|
55
|
+
"localhost",
|
|
56
|
+
"127.0.0.1",
|
|
57
|
+
"0.0.0.0",
|
|
58
|
+
]
|
|
59
|
+
return any(pattern in domain_lower for pattern in localhost_patterns)
|
|
49
60
|
|
|
50
61
|
def _get_headers(self, exclude_content_type: bool = False) -> dict:
|
|
51
62
|
"""Gets request headers with auth token.
|
|
@@ -58,9 +69,7 @@ class ApiRequestHandler:
|
|
|
58
69
|
headers["Content-Type"] = "application/json"
|
|
59
70
|
|
|
60
71
|
headers["Authorization"] = (
|
|
61
|
-
f"Bearer {self._token}"
|
|
62
|
-
if os.getenv("ENV", "").lower() != "local"
|
|
63
|
-
else "dev-codemie-user"
|
|
72
|
+
f"Bearer {self._token}" if not self._is_localhost else "dev-codemie-user"
|
|
64
73
|
)
|
|
65
74
|
return headers
|
|
66
75
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
codemie_sdk/__init__.py,sha256=leeACpTc2113BsY_IgO-ceFHPrQKC2WhuOfuuyyIqDE,567
|
|
2
2
|
codemie_sdk/auth/__init__.py,sha256=IksEj223xEZtJ-cQ0AT9L0Bs9psIJ8QNzDXrPTUQ3xQ,126
|
|
3
|
-
codemie_sdk/auth/credentials.py,sha256=
|
|
3
|
+
codemie_sdk/auth/credentials.py,sha256=u2eLNsD8fELTgreQghVb0g0kk82zchUkux0M5lzq-u8,4320
|
|
4
4
|
codemie_sdk/client/__init__.py,sha256=yf6C39MmrJ6gK9ZHMhBeynKwUUYVSUTQbKxU8-4qpKg,101
|
|
5
|
-
codemie_sdk/client/client.py,sha256=
|
|
5
|
+
codemie_sdk/client/client.py,sha256=6yXXNYF4m1vh_0UMPENaxL39hmt_wdPF_b5NtsKMJQQ,5174
|
|
6
6
|
codemie_sdk/exceptions.py,sha256=XoVPyognx-JmyVxLHkZPAcX1CMi1OoT1diBFJLU54so,1183
|
|
7
7
|
codemie_sdk/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
8
|
codemie_sdk/models/assistant.py,sha256=w0Oc4ArB-Rf6KiBjhVMVJgbmXpd48Tdt-dGLJJ7qJHw,10369
|
|
@@ -26,7 +26,7 @@ codemie_sdk/services/workflow.py,sha256=0d5grAsBIH2NZY66UbVhlDqEFYxEYSBByj3GNgcz
|
|
|
26
26
|
codemie_sdk/services/workflow_execution.py,sha256=aGoT3rdTmh5-doAsrmBBjLEuOfvL5aqeo3g9th1_aAw,3647
|
|
27
27
|
codemie_sdk/services/workflow_execution_state.py,sha256=tXoaa8yT09xgYEUNiHhVULe76TwGwVgZupMIUyyLxdo,2070
|
|
28
28
|
codemie_sdk/utils/__init__.py,sha256=BXAJJfAzO89-kMYvWWo9wSNhSbGgF3vB1In9sePFhMM,109
|
|
29
|
-
codemie_sdk/utils/http.py,sha256=
|
|
30
|
-
codemie_sdk_python-0.1.
|
|
31
|
-
codemie_sdk_python-0.1.
|
|
32
|
-
codemie_sdk_python-0.1.
|
|
29
|
+
codemie_sdk/utils/http.py,sha256=ZtXb-hlwqXmjSTKRncgO-9MYoXnmHt2Dljno0kPy7mA,9506
|
|
30
|
+
codemie_sdk_python-0.1.153.dist-info/METADATA,sha256=WHSCKoioxXq4KHOvgYmihq8LtPVKo64DiK0KKNsakL4,24494
|
|
31
|
+
codemie_sdk_python-0.1.153.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
32
|
+
codemie_sdk_python-0.1.153.dist-info/RECORD,,
|
|
File without changes
|