Skip to content

Commit

Permalink
Merge pull request #1114 from rjmello/compute-client-misc-methods
Browse files Browse the repository at this point in the history
Add ComputeClientV2 version and AMQP info methods
  • Loading branch information
kurtmckee authored Dec 1, 2024
2 parents b6f304d + 73945b1 commit 10ba34b
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Added
~~~~~

- Added the ``ComputeClientV2.get_version()`` and ``ComputeClientV2.get_result_amqp_url()``
methods. (:pr:`NUMBER`)
15 changes: 15 additions & 0 deletions src/globus_sdk/_testing/data/compute/v2/get_result_amqp_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from globus_sdk._testing.models import RegisteredResponse, ResponseSet

DEFAULT_RESPONSE_DOC = {
"queue_prefix": "some_prefix",
"connection_url": "amqps://user:[email protected]",
}

RESPONSES = ResponseSet(
default=RegisteredResponse(
service="compute",
path="/v2/get_amqp_result_connection_url",
method="GET",
json=DEFAULT_RESPONSE_DOC,
),
)
28 changes: 28 additions & 0 deletions src/globus_sdk/_testing/data/compute/v2/get_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from responses.matchers import query_param_matcher

from globus_sdk._testing.models import RegisteredResponse, ResponseSet

API_VERSION = "1.23.0"
ALL_RESPONSE_DOC = {
"api": API_VERSION,
"min_sdk_version": "1.0.0a6",
"min_endpoint_version": "1.0.0a0",
"git_sha": "80b2ef87bc546b3b386cf2e1d372f4be50f10bc4",
}

RESPONSES = ResponseSet(
metadata={"api_version": API_VERSION},
default=RegisteredResponse(
service="compute",
path="/v2/version",
method="GET",
json=API_VERSION, # type: ignore[arg-type]
),
all=RegisteredResponse(
service="compute",
path="/v2/version",
method="GET",
json=ALL_RESPONSE_DOC,
match=[query_param_matcher(params={"service": "all"})],
),
)
30 changes: 30 additions & 0 deletions src/globus_sdk/services/compute/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,36 @@ class ComputeClientV2(client.BaseClient):
scopes = ComputeScopes
default_scope_requirements = [Scope(ComputeScopes.all)]

def get_version(self, service: str | None = None) -> GlobusHTTPResponse:
"""Get the current version of the API and other services.
:param service: Service for which to get version information.
.. tab-set::
.. tab-item:: API Info
.. extdoclink:: Get Version
:service: compute
:ref: Root/operation/get_version_v2_version_get
"""
query_params = {"service": service} if service else None
return self.get("/v2/version", query_params=query_params)

def get_result_amqp_url(self) -> GlobusHTTPResponse:
"""Generate new credentials (in the form of a connection URL) for
connecting to the AMQP service.
.. tab-set::
.. tab-item:: API Info
.. extdoclink:: Get Result AMQP URL
:service: compute
:ref: Root/operation/get_user_specific_result_amqp_url_v2_get_amqp_result_connection_url_get
""" # noqa: E501
return self.get("/v2/get_amqp_result_connection_url")

def register_endpoint(self, data: dict[str, t.Any]) -> GlobusHTTPResponse:
"""Register a new endpoint.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import globus_sdk
from globus_sdk._testing import load_response


def test_get_result_amqp_url(compute_client_v2: globus_sdk.ComputeClientV2):
load_response(compute_client_v2.get_result_amqp_url)
res = compute_client_v2.get_result_amqp_url()
assert res.http_status == 200
assert "connection_url" in res.data
16 changes: 16 additions & 0 deletions tests/functional/services/compute/v2/test_get_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import globus_sdk
from globus_sdk._testing import load_response


def test_get_version(compute_client_v2: globus_sdk.ComputeClientV2):
meta = load_response(compute_client_v2.get_version).metadata
res = compute_client_v2.get_version()
assert res.http_status == 200
assert res.data == meta["api_version"]


def test_get_version_all(compute_client_v2: globus_sdk.ComputeClientV2):
meta = load_response(compute_client_v2.get_version, case="all").metadata
res = compute_client_v2.get_version(service="all")
assert res.http_status == 200
assert res.data["api"] == meta["api_version"]

0 comments on commit 10ba34b

Please sign in to comment.