Debian Codegraph @

src/globus_sdk/experimental/transfer_v2/client.py

raw
1 from __future__ import annotations
2
3 import logging
4 import typing as t
5 import uuid
6
7 from globus_sdk import client, paging, response
8 from globus_sdk.response import IterableJSONAPIResponse
9 from globus_sdk.scopes import TransferScopes
10 from globus_sdk.services.transfer.errors import TransferAPIError
11 from globus_sdk.transport import RetryConfig
12
13 from .data import (
14 BookmarkCreateDocument,
15 BookmarkUpdateDocument,
16 TunnelCreateDocument,
17 TunnelUpdateDocument,
18 )
19 from .transport import TRANSFER_V2_DEFAULT_RETRY_CHECKS
20
21 log = logging.getLogger(__name__)
22
23
24 class TransferClientV2(client.BaseClient):
25 r"""
26 Client for the `/v2/ routes of the Globus Transfer API
27 <https://docs.globus.org/api/transfer/#v2>`_.
28
29 .. sdk-sphinx-copy-params:: BaseClient
30
31 This class provides helper methods for /v2/ functionality in the Transfer
32 API as it is developed.
33
34 **Paginated Calls**
35
36 Methods which support pagination can be called as paginated or unpaginated methods.
37 If the method name is ``TransferClientV2.foo``, the paginated version is
38 ``TransferClientV2.paginated.foo``.
39 Using ``TransferClientV2.list_stream_access_points`` as an example::
40
41 from globus_sdk.experimental import TransferClientV2
42 tc = TransferClientV2(...)
43
44 # this is the unpaginated version
45 for stream_access_point in tc.list_stream_access_points():
46 print(stream_access_point["attributes"]["display_name"])
47
48 # this is the paginated version
49 for page in tc.paginated.list_stream_access_points():
50 for stream_access_point in page:
51 print(stream_access_point["attributes"]["display_name"])
52
53 .. automethodlist:: globus_sdk.experimental.TransferClientV2
54 """
55
56 service_name = "transfer"
57 error_class = TransferAPIError
58 scopes = TransferScopes
59 default_scope_requirements = [TransferScopes.all]
60
61 def _register_standard_retry_checks(self, retry_config: RetryConfig) -> None:
62 """Override the default retry checks."""
63 retry_config.checks.register_many_checks(TRANSFER_V2_DEFAULT_RETRY_CHECKS)
64
65 # Tunnel methods
66
67 def create_tunnel(
68 self,
69 data: dict[str, t.Any] | TunnelCreateDocument,
70 ) -> response.GlobusHTTPResponse:
71 """
72 :param data: Parameters for the tunnel creation
73
74 .. tab-set::
75
76 .. tab-item:: Example Usage
77
78 .. code-block:: python
79
80 tc = globus_sdk.experimental.TransferClientV2(...)
81 data = globus_sdk.experimental.TunnelCreateDocument(...)
82 result = tc.create_tunnel(data)
83 print(result["data"]["id"])
84
85 .. tab-item:: API Info
86
87 ``POST /v2/tunnels``
88 """
89 log.debug(f"{self.__class__.__name__}.create_tunnel(...)")
90 r = self.post("/v2/tunnels", data=data)
91 return r
92
93 def update_tunnel(
94 self,
95 tunnel_id: str | uuid.UUID,
96 update_doc: dict[str, t.Any] | TunnelUpdateDocument,
97 ) -> response.GlobusHTTPResponse:
98 r"""
99 :param tunnel_id: The ID of the Tunnel.
100 :param update_doc: The document that will be sent to the patch API.
101
102 .. tab-set::
103
104 .. tab-item:: Example Usage
105
106 .. code-block:: python
107
108 tc = globus_sdk.experimental.TransferClientV2(...)
109 data = globus_sdk.experimental.TunnelUpdateDocument(...)
110 result = tc.update_tunnel(tunnel_id, data)
111 print(result["data"])
112
113 .. tab-item:: API Info
114
115 ``PATCH /v2/tunnels/<tunnel_id>``
116 """
117 log.debug(f"{self.__class__.__name__}.update_tunnel({tunnel_id}, {update_doc})")
118 r = self.patch(f"/v2/tunnels/{tunnel_id}", data=update_doc)
119 return r
120
121 def get_tunnel(
122 self,
123 tunnel_id: str | uuid.UUID,
124 *,
125 query_params: dict[str, t.Any] | None = None,
126 ) -> response.GlobusHTTPResponse:
127 """
128 :param tunnel_id: The ID of the Tunnel which we are fetching details about.
129 :param query_params: Any additional parameters will be passed through
130 as query params.
131
132 .. tab-set::
133
134 .. tab-item:: Example Usage
135
136 .. code-block:: python
137
138 tc = globus_sdk.experimental.TransferClientV2(...)
139 result = tc.get_tunnel(tunnel_id)
140 print(result["data"])
141
142 .. tab-item:: API Info
143
144 ``GET /v2/tunnels/<tunnel_id>``
145 """
146 log.debug(f"{self.__class__.__name__}.get_tunnel({tunnel_id}, {query_params})")
147 r = self.get(f"/v2/tunnels/{tunnel_id}", query_params=query_params)
148 return r
149
150 def delete_tunnel(
151 self,
152 tunnel_id: str | uuid.UUID,
153 ) -> response.GlobusHTTPResponse:
154 """
155 :param tunnel_id: The ID of the Tunnel to be deleted.
156
157 This will clean up all data associated with a Tunnel.
158 Note that Tunnels must be stopped before they can be deleted.
159
160 .. tab-set::
161
162 .. tab-item:: Example Usage
163
164 .. code-block:: python
165
166 tc = globus_sdk.experimental.TransferClientV2(...)
167 tc.delete_tunnel(tunnel_id)
168
169 .. tab-item:: API Info
170
171 ``DELETE /v2/tunnels/<tunnel_id>``
172 """
173 log.debug(f"{self.__class__.__name__}.delete_tunnel({tunnel_id})")
174 r = self.delete(f"/v2/tunnels/{tunnel_id}")
175 return r
176
177 def list_tunnels(
178 self,
179 *,
180 query_params: dict[str, t.Any] | None = None,
181 ) -> IterableJSONAPIResponse:
182 """
183 :param query_params: Any additional parameters will be passed through
184 as query params.
185
186 This will list all the Tunnels created by the authorized user.
187
188 .. tab-set::
189
190 .. tab-item:: Example Usage
191
192 .. code-block:: python
193
194 tc = globus_sdk.experimental.TransferClientV2(...)
195 tc.list_tunnels(tunnel_id)
196
197 .. tab-item:: API Info
198
199 ``GET /v2/tunnels/``
200 """
201 log.debug(f"{self.__class__.__name__}.list_tunnels({query_params})")
202 r = self.get("/v2/tunnels", query_params=query_params)
203 return IterableJSONAPIResponse(r)
204
205 def get_tunnel_events(
206 self,
207 tunnel_id: str | uuid.UUID,
208 *,
209 query_params: dict[str, t.Any] | None = None,
210 ) -> IterableJSONAPIResponse:
211 """
212 :param tunnel_id: The ID of the Tunnel which we are fetching events about.
213 :param query_params: Any additional parameters will be passed through
214 as query params.
215
216 .. tab-set::
217
218 .. tab-item:: Example Usage
219
220 .. code-block:: python
221
222 tc = globus_sdk.experimental.TransferClientV2(...)
223 result = tc.get_tunnel_events(tunnel_id)
224 print(result["data"])
225
226 .. tab-item:: API Info
227
228 ``GET /v2/tunnels/<tunnel_id>/events``
229 """
230 log.debug(
231 f"{self.__class__.__name__}.get_tunnel_events({tunnel_id}, {query_params})"
232 )
233 r = self.get(f"/v2/tunnels/{tunnel_id}/events", query_params=query_params)
234 return IterableJSONAPIResponse(r)
235
236 # Stream access point methods
237
238 def get_stream_access_point(
239 self,
240 stream_ap_id: str | uuid.UUID,
241 *,
242 query_params: dict[str, t.Any] | None = None,
243 ) -> response.GlobusHTTPResponse:
244 """
245 :param stream_ap_id: The ID of the steaming access point to lookup.
246 :param query_params: Any additional parameters will be passed through
247 as query params.
248
249 Get a stream access point by id.
250
251 .. tab-set::
252
253 .. tab-item:: Example Usage
254
255 .. code-block:: python
256
257 tc = globus_sdk.experimental.TransferClientV2(...)
258 tc.get_stream_access_point(stream_ap_id)
259
260 .. tab-item:: API Info
261
262 ``GET /v2/stream_access_points/<stream_ap_id>``
263 """
264 log.debug(
265 f"{self.__class__.__name__}."
266 f"get_stream_access_point({stream_ap_id}, {query_params})"
267 )
268 r = self.get(
269 f"/v2/stream_access_points/{stream_ap_id}", query_params=query_params
270 )
271 return r
272
273 @paging.has_paginator(paging.JSONAPIPaginator)
274 def list_stream_access_points(
275 self,
276 *,
277 query_params: dict[str, t.Any] | None = None,
278 ) -> IterableJSONAPIResponse:
279 """
280 :param query_params: Any additional parameters will be passed through
281 as query params.
282
283 List stream access points.
284
285 .. tab-set::
286
287 .. tab-item:: Example Usage
288
289 .. code-block:: python
290
291 tc = globus_sdk.experimental.TransferClientV2(...)
292 tc.list_stream_access_points()
293
294 .. tab-item:: API Info
295
296 ``GET /v2/stream_access_points``
297 """
298 log.debug(
299 f"{self.__class__.__name__}.list_stream_access_points({query_params})"
300 )
301 r = self.get("/v2/stream_access_points", query_params=query_params)
302 return IterableJSONAPIResponse(r)
303
304 def create_bookmark(
305 self, data: dict[str, t.Any] | BookmarkCreateDocument
306 ) -> response.GlobusHTTPResponse:
307 """
308 :param data: Parameters for bookmark creation
309
310 .. tab-set::
311
312 .. tab-item:: Example Usage
313
314 .. code-block:: python
315
316 tc = globus_sdk.experimental.TransferClientV2(...)
317 data = globus_sdk.experimental.BookmarkCreateDocument(...)
318 result = tc.create_bookmark(data)
319 print(result["data"]["id"])
320
321 .. tab-item:: API Info
322
323 ``POST /v2/bookmarks``
324 """
325 log.debug(f"{self.__class__.__name__}.create_bookmark(...)")
326 r = self.post("/v2/bookmarks", data=data)
327 return r
328
329 def update_bookmark(
330 self,
331 bookmark_id: uuid.UUID | str,
332 update_document: dict[str, t.Any] | BookmarkUpdateDocument,
333 ) -> response.GlobusHTTPResponse:
334 r"""
335 :param bookmark_id: The ID of the Bookmark.
336 :param update_document: The document that will be sent to the patch API.
337
338 .. tab-set::
339
340 .. tab-item:: Example Usage
341
342 .. code-block:: python
343
344 tc = globus_sdk.experimental.TransferClientV2(...)
345 data = globus_sdk.experimental.BookmarkUpdateDocument(...)
346 result = tc.update_bookmark(bookmark_id, data)
347 print(result["data"])
348
349 .. tab-item:: API Info
350
351 ``PATCH /v2/bookmarks/<bookmark_id>``
352 """
353 log.debug(
354 f"{self.__class__.__name__}."
355 f"update_bookmark({bookmark_id}, {update_document})"
356 )
357 r = self.patch(f"/v2/bookmarks/{bookmark_id}", data=update_document)
358 return r
359
360 def get_bookmark(
361 self,
362 bookmark_id: uuid.UUID | str,
363 *,
364 query_params: dict[str, t.Any] | None = None,
365 ) -> response.GlobusHTTPResponse:
366 """
367 :param bookmark_id: The ID of the Bookmark for which we are fetching details.
368 :param query_params: Any additional parameters will be passed through
369 as request parameters on the URL.
370
371 .. tab-set::
372
373 .. tab-item:: Example Usage
374
375 .. code-block:: python
376
377 tc = globus_sdk.experimental.TransferClientV2(...)
378 query_params = {"include": "collection"}
379 result = tc.get_bookmark(bookmark_id, query_params)
380 print(result["data"])
381
382 .. tab-item:: API Info
383
384 ``GET /v2/bookmarks/<bookmark_id>``
385 """
386 log.debug(
387 f"{self.__class__.__name__}.get_bookmark({bookmark_id}, {query_params})"
388 )
389 r = self.get(f"/v2/bookmarks/{bookmark_id}", query_params=query_params)
390 return r
391
392 def delete_bookmark(
393 self,
394 bookmark_id: uuid.UUID | str,
395 ) -> response.GlobusHTTPResponse:
396 """
397 :param bookmark_id: The ID of the Bookmark to be deleted.
398
399 .. tab-set::
400
401 .. tab-item:: Example Usage
402
403 .. code-block:: python
404
405 tc = globus_sdk.experimental.TransferClientV2(...)
406 tc.delete_bookmark(bookmark_id)
407
408 .. tab-item:: API Info
409
410 ``DELETE /v2/bookmarks/<bookmark_id>``
411 """
412 log.debug(f"{self.__class__.__name__}.delete_bookmark({bookmark_id})")
413 r = self.delete(f"/v2/bookmarks/{bookmark_id}")
414 return r
415
416 def list_bookmarks(
417 self,
418 *,
419 query_params: dict[str, t.Any] | None = None,
420 ) -> IterableJSONAPIResponse:
421 """
422 :param query_params: Any additional parameters will be passed through
423 as request parameters on the URL.
424
425 This will list all Bookmarks created by the authenticated user's primary
426 and linked identities.
427
428 .. tab-set::
429
430 .. tab-item:: Example Usage
431
432 .. code-block:: python
433
434 tc = globus_sdk.experimental.TransferClientV2(...)
435 query_params = {"include": "collection"}
436 tc.list_bookmarks(query_params)
437
438 .. tab-item:: API Info
439
440 ``GET /v2/bookmarks``
441 """
442 log.debug(f"{self.__class__.__name__}.list_bookmarks({query_params})")
443 r = self.get("/v2/bookmarks", query_params=query_params)
444 return IterableJSONAPIResponse(r)