Skip to content

Commit 0943574

Browse files
committed
Implement AuthenticatedClient integration in FileClient, MaterializationClient, and TableClient
This commit introduces the use of the AuthenticatedClient across the FileClient, MaterializationClient, and TableClient classes. It ensures that an API key is provided before making requests, enhancing security and error handling. The client is now instantiated with the necessary parameters, improving the overall architecture and maintainability of the codebase.
1 parent ad25db3 commit 0943574

3 files changed

Lines changed: 113 additions & 9 deletions

File tree

‎robosystems_client/extensions/file_client.py‎

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,22 @@ def upload(
134134
table_name=table_name,
135135
)
136136

137+
from ..client import AuthenticatedClient
138+
139+
if not self.token:
140+
raise Exception("No API key provided. Set X-API-Key in headers.")
141+
142+
client = AuthenticatedClient(
143+
base_url=self.base_url,
144+
token=self.token,
145+
prefix="",
146+
auth_header_name="X-API-Key",
147+
headers=self.headers,
148+
)
149+
137150
kwargs = {
138151
"graph_id": graph_id,
139-
"client": self.config.get("client"),
152+
"client": client,
140153
"body": upload_request,
141154
}
142155

@@ -195,7 +208,7 @@ def upload(
195208
update_kwargs = {
196209
"graph_id": graph_id,
197210
"file_id": file_id,
198-
"client": self.config.get("client"),
211+
"client": client,
199212
"body": status_update,
200213
}
201214

@@ -261,9 +274,22 @@ def list(
261274
List of FileInfo objects
262275
"""
263276
try:
277+
from ..client import AuthenticatedClient
278+
279+
if not self.token:
280+
raise Exception("No API key provided. Set X-API-Key in headers.")
281+
282+
client = AuthenticatedClient(
283+
base_url=self.base_url,
284+
token=self.token,
285+
prefix="",
286+
auth_header_name="X-API-Key",
287+
headers=self.headers,
288+
)
289+
264290
kwargs = {
265291
"graph_id": graph_id,
266-
"client": self.config.get("client"),
292+
"client": client,
267293
}
268294

269295
if table_name:
@@ -311,10 +337,23 @@ def get(self, graph_id: str, file_id: str) -> Optional[FileInfo]:
311337
FileInfo with multi-layer status tracking, or None if not found
312338
"""
313339
try:
340+
from ..client import AuthenticatedClient
341+
342+
if not self.token:
343+
raise Exception("No API key provided. Set X-API-Key in headers.")
344+
345+
client = AuthenticatedClient(
346+
base_url=self.base_url,
347+
token=self.token,
348+
prefix="",
349+
auth_header_name="X-API-Key",
350+
headers=self.headers,
351+
)
352+
314353
kwargs = {
315354
"graph_id": graph_id,
316355
"file_id": file_id,
317-
"client": self.config.get("client"),
356+
"client": client,
318357
}
319358

320359
response = get_file(**kwargs)
@@ -355,10 +394,23 @@ def delete(self, graph_id: str, file_id: str, cascade: bool = False) -> bool:
355394
True if deletion succeeded, False otherwise
356395
"""
357396
try:
397+
from ..client import AuthenticatedClient
398+
399+
if not self.token:
400+
raise Exception("No API key provided. Set X-API-Key in headers.")
401+
402+
client = AuthenticatedClient(
403+
base_url=self.base_url,
404+
token=self.token,
405+
prefix="",
406+
auth_header_name="X-API-Key",
407+
headers=self.headers,
408+
)
409+
358410
kwargs = {
359411
"graph_id": graph_id,
360412
"file_id": file_id,
361-
"client": self.config.get("client"),
413+
"client": client,
362414
"cascade": cascade,
363415
}
364416

‎robosystems_client/extensions/materialization_client.py‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,22 @@ def materialize(
104104
force=options.force,
105105
)
106106

107+
from ..client import AuthenticatedClient
108+
109+
if not self.token:
110+
raise Exception("No API key provided. Set X-API-Key in headers.")
111+
112+
client = AuthenticatedClient(
113+
base_url=self.base_url,
114+
token=self.token,
115+
prefix="",
116+
auth_header_name="X-API-Key",
117+
headers=self.headers,
118+
)
119+
107120
kwargs = {
108121
"graph_id": graph_id,
109-
"client": self.config.get("client"),
122+
"client": client,
110123
"body": request,
111124
}
112125

@@ -182,9 +195,22 @@ def status(self, graph_id: str) -> Optional[MaterializationStatus]:
182195
MaterializationStatus with staleness and timing information
183196
"""
184197
try:
198+
from ..client import AuthenticatedClient
199+
200+
if not self.token:
201+
raise Exception("No API key provided. Set X-API-Key in headers.")
202+
203+
client = AuthenticatedClient(
204+
base_url=self.base_url,
205+
token=self.token,
206+
prefix="",
207+
auth_header_name="X-API-Key",
208+
headers=self.headers,
209+
)
210+
185211
kwargs = {
186212
"graph_id": graph_id,
187-
"client": self.config.get("client"),
213+
"client": client,
188214
}
189215

190216
response = get_materialization_status(**kwargs)

‎robosystems_client/extensions/table_client.py‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,22 @@ def list(self, graph_id: str) -> list[TableInfo]:
6262
List of TableInfo objects with metadata
6363
"""
6464
try:
65+
from ..client import AuthenticatedClient
66+
67+
if not self.token:
68+
raise Exception("No API key provided. Set X-API-Key in headers.")
69+
70+
client = AuthenticatedClient(
71+
base_url=self.base_url,
72+
token=self.token,
73+
prefix="",
74+
auth_header_name="X-API-Key",
75+
headers=self.headers,
76+
)
77+
6578
kwargs = {
6679
"graph_id": graph_id,
67-
"client": self.config.get("client"),
80+
"client": client,
6881
}
6982

7083
response = list_tables(**kwargs)
@@ -120,9 +133,22 @@ def query(
120133

121134
request = TableQueryRequest(sql=final_query)
122135

136+
from ..client import AuthenticatedClient
137+
138+
if not self.token:
139+
raise Exception("No API key provided. Set X-API-Key in headers.")
140+
141+
client = AuthenticatedClient(
142+
base_url=self.base_url,
143+
token=self.token,
144+
prefix="",
145+
auth_header_name="X-API-Key",
146+
headers=self.headers,
147+
)
148+
123149
kwargs = {
124150
"graph_id": graph_id,
125-
"client": self.config.get("client"),
151+
"client": client,
126152
"body": request,
127153
}
128154

0 commit comments

Comments
 (0)