terrakio-core 0.2.3__tar.gz → 0.2.4__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 terrakio-core might be problematic. Click here for more details.
- {terrakio_core-0.2.3 → terrakio_core-0.2.4}/PKG-INFO +1 -1
- {terrakio_core-0.2.3 → terrakio_core-0.2.4}/pyproject.toml +1 -1
- terrakio_core-0.2.4/terrakio_core/__init__.py +0 -0
- terrakio_core-0.2.4/terrakio_core/auth.py +238 -0
- terrakio_core-0.2.4/terrakio_core/client.py +1005 -0
- terrakio_core-0.2.4/terrakio_core/config.py +81 -0
- terrakio_core-0.2.4/terrakio_core/dataset_management.py +235 -0
- terrakio_core-0.2.4/terrakio_core/exceptions.py +18 -0
- terrakio_core-0.2.4/terrakio_core/group_access_management.py +232 -0
- terrakio_core-0.2.4/terrakio_core/mass_stats.py +262 -0
- terrakio_core-0.2.4/terrakio_core/space_management.py +101 -0
- terrakio_core-0.2.4/terrakio_core/user_management.py +227 -0
- {terrakio_core-0.2.3 → terrakio_core-0.2.4}/terrakio_core.egg-info/PKG-INFO +1 -1
- terrakio_core-0.2.4/terrakio_core.egg-info/SOURCES.txt +17 -0
- terrakio_core-0.2.4/terrakio_core.egg-info/top_level.txt +1 -0
- terrakio_core-0.2.3/terrakio_core.egg-info/SOURCES.txt +0 -7
- terrakio_core-0.2.3/terrakio_core.egg-info/top_level.txt +0 -1
- {terrakio_core-0.2.3 → terrakio_core-0.2.4}/README.md +0 -0
- {terrakio_core-0.2.3 → terrakio_core-0.2.4}/setup.cfg +0 -0
- {terrakio_core-0.2.3 → terrakio_core-0.2.4}/terrakio_core.egg-info/dependency_links.txt +0 -0
- {terrakio_core-0.2.3 → terrakio_core-0.2.4}/terrakio_core.egg-info/requires.txt +0 -0
|
File without changes
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from typing import Optional, Dict, Any
|
|
3
|
+
from .exceptions import APIError, ConfigurationError
|
|
4
|
+
|
|
5
|
+
class AuthClient:
|
|
6
|
+
def __init__(self, base_url: str = "https://dev-au.terrak.io",
|
|
7
|
+
verify: bool = True, timeout: int = 60):
|
|
8
|
+
"""
|
|
9
|
+
Initialize the Authentication Client for Terrakio API.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
base_url: Authentication API base URL
|
|
13
|
+
verify: Verify SSL certificates
|
|
14
|
+
timeout: Request timeout in seconds
|
|
15
|
+
"""
|
|
16
|
+
self.base_url = base_url.rstrip('/')
|
|
17
|
+
self.verify = verify
|
|
18
|
+
self.timeout = timeout
|
|
19
|
+
self.session = requests.Session()
|
|
20
|
+
self.session.headers.update({
|
|
21
|
+
'Content-Type': 'application/json'
|
|
22
|
+
})
|
|
23
|
+
self.token = None
|
|
24
|
+
self.api_key = None
|
|
25
|
+
|
|
26
|
+
def signup(self, email: str, password: str) -> Dict[str, Any]:
|
|
27
|
+
"""
|
|
28
|
+
Register a new user account.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
email: User email address
|
|
32
|
+
password: User password
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
API response data
|
|
36
|
+
|
|
37
|
+
Raises:
|
|
38
|
+
APIError: If signup fails
|
|
39
|
+
"""
|
|
40
|
+
endpoint = f"{self.base_url}/users/signup"
|
|
41
|
+
|
|
42
|
+
payload = {
|
|
43
|
+
"email": email,
|
|
44
|
+
"password": password
|
|
45
|
+
}
|
|
46
|
+
print("the payload is ", payload)
|
|
47
|
+
print("the endpoint is ", endpoint)
|
|
48
|
+
try:
|
|
49
|
+
response = self.session.post(
|
|
50
|
+
endpoint,
|
|
51
|
+
json=payload,
|
|
52
|
+
verify=self.verify,
|
|
53
|
+
timeout=self.timeout
|
|
54
|
+
)
|
|
55
|
+
print("the response is ", response)
|
|
56
|
+
if not response.ok:
|
|
57
|
+
error_msg = f"Signup failed: {response.status_code} {response.reason}"
|
|
58
|
+
try:
|
|
59
|
+
error_data = response.json()
|
|
60
|
+
if "detail" in error_data:
|
|
61
|
+
error_msg += f" - {error_data['detail']}"
|
|
62
|
+
except:
|
|
63
|
+
pass
|
|
64
|
+
raise APIError(error_msg)
|
|
65
|
+
|
|
66
|
+
return response.json()
|
|
67
|
+
except requests.RequestException as e:
|
|
68
|
+
raise APIError(f"Signup request failed: {str(e)}")
|
|
69
|
+
|
|
70
|
+
def login(self, email: str, password: str) -> str:
|
|
71
|
+
"""
|
|
72
|
+
Log in and obtain authentication token.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
email: User email address
|
|
76
|
+
password: User password
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Authentication token
|
|
80
|
+
|
|
81
|
+
Raises:
|
|
82
|
+
APIError: If login fails
|
|
83
|
+
"""
|
|
84
|
+
endpoint = f"{self.base_url}/users/login"
|
|
85
|
+
|
|
86
|
+
payload = {
|
|
87
|
+
"email": email,
|
|
88
|
+
"password": password
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try:
|
|
92
|
+
response = self.session.post(
|
|
93
|
+
endpoint,
|
|
94
|
+
json=payload,
|
|
95
|
+
verify=self.verify,
|
|
96
|
+
timeout=self.timeout
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
if not response.ok:
|
|
100
|
+
error_msg = f"Login failed: {response.status_code} {response.reason}"
|
|
101
|
+
try:
|
|
102
|
+
error_data = response.json()
|
|
103
|
+
if "detail" in error_data:
|
|
104
|
+
error_msg += f" - {error_data['detail']}"
|
|
105
|
+
except:
|
|
106
|
+
pass
|
|
107
|
+
raise APIError(error_msg)
|
|
108
|
+
|
|
109
|
+
result = response.json()
|
|
110
|
+
self.token = result.get("token")
|
|
111
|
+
|
|
112
|
+
# Update session with authorization header
|
|
113
|
+
if self.token:
|
|
114
|
+
self.session.headers.update({
|
|
115
|
+
"Authorization": self.token
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
return self.token
|
|
119
|
+
except requests.RequestException as e:
|
|
120
|
+
raise APIError(f"Login request failed: {str(e)}")
|
|
121
|
+
|
|
122
|
+
def refresh_api_key(self) -> str:
|
|
123
|
+
"""
|
|
124
|
+
Generate or refresh API key.
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
API key
|
|
128
|
+
|
|
129
|
+
Raises:
|
|
130
|
+
ConfigurationError: If not authenticated
|
|
131
|
+
APIError: If refresh fails
|
|
132
|
+
"""
|
|
133
|
+
if not self.token:
|
|
134
|
+
raise ConfigurationError("Not authenticated. Call login() first.")
|
|
135
|
+
|
|
136
|
+
endpoint = f"{self.base_url}/users/refresh_key"
|
|
137
|
+
|
|
138
|
+
try:
|
|
139
|
+
# Use session with updated headers from login
|
|
140
|
+
response = self.session.post(
|
|
141
|
+
endpoint,
|
|
142
|
+
verify=self.verify,
|
|
143
|
+
timeout=self.timeout
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
if not response.ok:
|
|
147
|
+
error_msg = f"API key generation failed: {response.status_code} {response.reason}"
|
|
148
|
+
try:
|
|
149
|
+
error_data = response.json()
|
|
150
|
+
if "detail" in error_data:
|
|
151
|
+
error_msg += f" - {error_data['detail']}"
|
|
152
|
+
except:
|
|
153
|
+
pass
|
|
154
|
+
raise APIError(error_msg)
|
|
155
|
+
|
|
156
|
+
result = response.json()
|
|
157
|
+
self.api_key = result.get("apiKey")
|
|
158
|
+
return self.api_key
|
|
159
|
+
except requests.RequestException as e:
|
|
160
|
+
raise APIError(f"API key refresh request failed: {str(e)}")
|
|
161
|
+
|
|
162
|
+
def view_api_key(self) -> str:
|
|
163
|
+
"""
|
|
164
|
+
Retrieve current API key.
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
API key
|
|
168
|
+
|
|
169
|
+
Raises:
|
|
170
|
+
ConfigurationError: If not authenticated
|
|
171
|
+
APIError: If retrieval fails
|
|
172
|
+
"""
|
|
173
|
+
if not self.token:
|
|
174
|
+
raise ConfigurationError("Not authenticated. Call login() first.")
|
|
175
|
+
|
|
176
|
+
endpoint = f"{self.base_url}/users/key"
|
|
177
|
+
|
|
178
|
+
try:
|
|
179
|
+
# Use session with updated headers from login
|
|
180
|
+
response = self.session.get(
|
|
181
|
+
endpoint,
|
|
182
|
+
verify=self.verify,
|
|
183
|
+
timeout=self.timeout
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
if not response.ok:
|
|
187
|
+
error_msg = f"Failed to retrieve API key: {response.status_code} {response.reason}"
|
|
188
|
+
try:
|
|
189
|
+
error_data = response.json()
|
|
190
|
+
if "detail" in error_data:
|
|
191
|
+
error_msg += f" - {error_data['detail']}"
|
|
192
|
+
except:
|
|
193
|
+
pass
|
|
194
|
+
raise APIError(error_msg)
|
|
195
|
+
|
|
196
|
+
result = response.json()
|
|
197
|
+
self.api_key = result.get("apiKey")
|
|
198
|
+
return self.api_key
|
|
199
|
+
except requests.RequestException as e:
|
|
200
|
+
raise APIError(f"API key retrieval request failed: {str(e)}")
|
|
201
|
+
|
|
202
|
+
def get_user_info(self) -> Dict[str, Any]:
|
|
203
|
+
"""
|
|
204
|
+
Retrieve the current user's information.
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
User information data
|
|
208
|
+
|
|
209
|
+
Raises:
|
|
210
|
+
ConfigurationError: If not authenticated
|
|
211
|
+
APIError: If retrieval fails
|
|
212
|
+
"""
|
|
213
|
+
if not self.token:
|
|
214
|
+
raise ConfigurationError("Not authenticated. Call login() first.")
|
|
215
|
+
|
|
216
|
+
endpoint = f"{self.base_url}/users/info"
|
|
217
|
+
|
|
218
|
+
try:
|
|
219
|
+
# Use session with updated headers from login
|
|
220
|
+
response = self.session.get(
|
|
221
|
+
endpoint,
|
|
222
|
+
verify=self.verify,
|
|
223
|
+
timeout=self.timeout
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
if not response.ok:
|
|
227
|
+
error_msg = f"Failed to retrieve user info: {response.status_code} {response.reason}"
|
|
228
|
+
try:
|
|
229
|
+
error_data = response.json()
|
|
230
|
+
if "detail" in error_data:
|
|
231
|
+
error_msg += f" - {error_data['detail']}"
|
|
232
|
+
except:
|
|
233
|
+
pass
|
|
234
|
+
raise APIError(error_msg)
|
|
235
|
+
|
|
236
|
+
return response.json()
|
|
237
|
+
except requests.RequestException as e:
|
|
238
|
+
raise APIError(f"User info retrieval request failed: {str(e)}")
|