| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import logging |
| 4 |
import typing as t |
| 5 |
import uuid |
| 6 |
|
| 7 |
from globus_sdk._missing import MISSING, MissingType |
| 8 |
from globus_sdk._payload import GlobusPayload |
| 9 |
|
| 10 |
log = logging.getLogger(__name__) |
| 11 |
|
| 12 |
|
| 13 |
class CreateTunnelData(GlobusPayload): |
| 14 |
""" |
| 15 |
Convenience class for constructing a tunnel document to use as the |
| 16 |
``data`` parameter to |
| 17 |
:meth:`create_tunnel <globus_sdk.TransferClient.create_tunnel>`. |
| 18 |
""" |
| 19 |
|
| 20 |
def __init__( |
| 21 |
self, |
| 22 |
initiator_stream_access_point: uuid.UUID | str, |
| 23 |
listener_stream_access_point: uuid.UUID | str, |
| 24 |
*, |
| 25 |
label: str | MissingType = MISSING, |
| 26 |
submission_id: uuid.UUID | str | MissingType = MISSING, |
| 27 |
lifetime_mins: int | MissingType = MISSING, |
| 28 |
restartable: bool | MissingType = MISSING, |
| 29 |
additional_fields: dict[str, t.Any] | None = None, |
| 30 |
) -> None: |
| 31 |
super().__init__() |
| 32 |
log.debug("Creating a new CreateTunnelData object") |
| 33 |
|
| 34 |
relationships = { |
| 35 |
"listener": { |
| 36 |
"data": { |
| 37 |
"type": "StreamAccessPoint", |
| 38 |
"id": listener_stream_access_point, |
| 39 |
} |
| 40 |
}, |
| 41 |
"initiator": { |
| 42 |
"data": { |
| 43 |
"type": "StreamAccessPoint", |
| 44 |
"id": initiator_stream_access_point, |
| 45 |
} |
| 46 |
}, |
| 47 |
} |
| 48 |
attributes = { |
| 49 |
"label": label, |
| 50 |
"submission_id": submission_id, |
| 51 |
"restartable": restartable, |
| 52 |
"lifetime_mins": lifetime_mins, |
| 53 |
} |
| 54 |
if additional_fields is not None: |
| 55 |
attributes.update(additional_fields) |
| 56 |
|
| 57 |
self["data"] = { |
| 58 |
"type": "Tunnel", |
| 59 |
"relationships": relationships, |
| 60 |
"attributes": attributes, |
| 61 |
} |