| 1 |
Transfer Endpoint Type Enum |
| 2 |
--------------------------- |
| 3 |
|
| 4 |
If your application needs to support Globus Connect Server version 4 and |
| 5 |
version 5, Globus Connect Personal, and Shared Endpoints, you may need to |
| 6 |
determine what type of endpoint or collection you are handling. |
| 7 |
|
| 8 |
The `Globus documentation site <https://docs.globus.org>`_ offers several references on |
| 9 |
this subject, including `a section on this exact subject matter |
| 10 |
<https://docs.globus.org/globus-connect-server/migrating-to-v5.4/application-migration/#determining_endpoint_or_collection_type>`_ |
| 11 |
and Transfer API documentation `describing the different types of endpoints |
| 12 |
<https://docs.globus.org/api/transfer/endpoint/#types_of_endpoints>`_. |
| 13 |
|
| 14 |
In python, the logic for doing this is easily expressed in the form of an enum |
| 15 |
class for the different endpoint types, and a function which takes an Endpoint |
| 16 |
Document (from the Transfer service) and returns the matching enum member. |
| 17 |
The helper can be made a classmethod of the enum, encapsulating the logic in |
| 18 |
one class, all as follows: |
| 19 |
|
| 20 |
.. code-block:: python |
| 21 |
|
| 22 |
|
| 23 |
from enum import Enum, auto |
| 24 |
|
| 25 |
|
| 26 |
class TransferEndpointType(Enum): |
| 27 |
# Globus Connect Personal |
| 28 |
GCP = auto() |
| 29 |
# Globus Connect Server version 5 Endpoint |
| 30 |
GCSV5_ENDPOINT = auto() |
| 31 |
# GCSv5 collections |
| 32 |
GUEST_COLLECTION = auto() |
| 33 |
MAPPED_COLLECTION = auto() |
| 34 |
# a Shared Endpoint (also sometimes referred to as a Guest Collection |
| 35 |
# on Globus Connect Personal) |
| 36 |
SHARE = auto() |
| 37 |
# any other endpoint document is most likely GCSv4, but not necessarily |
| 38 |
# this technically includes legacy types of endpoints which are not GCSv4 |
| 39 |
# most applications can treat this case as meaning "GCSv4" |
| 40 |
# in fact, the "nice_name" method below does so! |
| 41 |
NON_GCSV5_ENDPOINT = auto() |
| 42 |
|
| 43 |
@classmethod |
| 44 |
def nice_name(cls, eptype: TransferEndpointType) -> str: |
| 45 |
return { |
| 46 |
cls.GCP: "Globus Connect Personal", |
| 47 |
cls.GCSV5_ENDPOINT: "Globus Connect Server v5 Endpoint", |
| 48 |
cls.GUEST_COLLECTION: "Guest Collection", |
| 49 |
cls.MAPPED_COLLECTION: "Mapped Collection", |
| 50 |
cls.SHARE: "Shared Endpoint", |
| 51 |
cls.NON_GCSV5_ENDPOINT: "GCSv4 Endpoint", |
| 52 |
}.get(eptype, "UNKNOWN") |
| 53 |
|
| 54 |
@classmethod |
| 55 |
def determine_endpoint_type(cls, ep_doc: dict) -> TransferEndpointType: |
| 56 |
""" |
| 57 |
Given an endpoint document from Transfer, determine what type of |
| 58 |
endpoint or collection it is |
| 59 |
""" |
| 60 |
if ep_doc.get("is_globus_connect") is True: |
| 61 |
return cls.GCP |
| 62 |
|
| 63 |
if ep_doc.get("non_functional") is True: |
| 64 |
return cls.GCSV5_ENDPOINT |
| 65 |
|
| 66 |
has_host = ep_doc.get("host_endpoint_id") is not None |
| 67 |
|
| 68 |
if ep_doc.get("gcs_version"): |
| 69 |
try: |
| 70 |
major, _minor, _patch = ep_doc["gcs_version"].split(".") |
| 71 |
except ValueError: # split -> unpack didn't give 3 values |
| 72 |
major = None |
| 73 |
|
| 74 |
gcsv5 = major == "5" |
| 75 |
else: |
| 76 |
gcsv5 = False |
| 77 |
|
| 78 |
if gcsv5: |
| 79 |
if has_host: |
| 80 |
return cls.GUEST_COLLECTION |
| 81 |
else: |
| 82 |
return cls.MAPPED_COLLECTION |
| 83 |
|
| 84 |
elif has_host: |
| 85 |
return cls.SHARE |
| 86 |
|
| 87 |
return cls.NON_GCSV5_ENDPOINT |