codemie-sdk-python 0.1.150__py3-none-any.whl → 0.1.152__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.

@@ -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 os.getenv("ENV", "").lower() != "local" and not (
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"
@@ -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 first
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 not self._token:
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: codemie-sdk-python
3
- Version: 0.1.150
3
+ Version: 0.1.152
4
4
  Summary: CodeMie SDK for Python
5
5
  Author: Vadym Vlasenko
6
6
  Author-email: vadym_vlasenko@epam.com
@@ -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=vcvt2nvb4_tSCdR7On498wNW4D-DRIuEJU6l3QG8QN0,4471
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=8XlFsa2OEKdawipbUcX3L7umVHXKh9nzQ5-CXsXpMXI,4691
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=sdUdMYtexkYz0dQ7ysdwJlyYaE-QHdTZekQNDJpX48s,9134
30
- codemie_sdk_python-0.1.150.dist-info/METADATA,sha256=BJvuYsxOxDmvFjDTXsEf06M6LeuP8KVT1Ah38_Lj0Hs,24494
31
- codemie_sdk_python-0.1.150.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
32
- codemie_sdk_python-0.1.150.dist-info/RECORD,,
29
+ codemie_sdk/utils/http.py,sha256=ZtXb-hlwqXmjSTKRncgO-9MYoXnmHt2Dljno0kPy7mA,9506
30
+ codemie_sdk_python-0.1.152.dist-info/METADATA,sha256=v_XHbDe_rIZkhrsXeWuDxpeqJaDCiTRhbCUAvdmT6iM,24494
31
+ codemie_sdk_python-0.1.152.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
32
+ codemie_sdk_python-0.1.152.dist-info/RECORD,,