From 30d3e29cb807fc22734b670248d119d15e694c05 Mon Sep 17 00:00:00 2001 From: Zach Giordano <32624672+zachgiordano@users.noreply.github.com> Date: Thu, 25 Apr 2024 17:00:53 -0400 Subject: [PATCH] Rename GT Cloud run ID env var (#758) --- .../griptape_cloud_event_listener_driver.py | 14 +++++++------- .../test_griptape_cloud_event_listener_driver.py | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/griptape/drivers/event_listener/griptape_cloud_event_listener_driver.py b/griptape/drivers/event_listener/griptape_cloud_event_listener_driver.py index 7f52b3519..90b94c313 100644 --- a/griptape/drivers/event_listener/griptape_cloud_event_listener_driver.py +++ b/griptape/drivers/event_listener/griptape_cloud_event_listener_driver.py @@ -18,7 +18,7 @@ class GriptapeCloudEventListenerDriver(BaseEventListenerDriver): base_url: The base URL of Griptape Cloud. Defaults to the GT_CLOUD_BASE_URL environment variable. api_key: The API key to authenticate with Griptape Cloud. headers: The headers to use when making requests to Griptape Cloud. Defaults to include the Authorization header. - run_id: The ID of the Structure Run to publish events to. Defaults to the GT_CLOUD_RUN_ID environment variable. + structure_run_id: The ID of the Structure Run to publish events to. Defaults to the GT_CLOUD_STRUCTURE_RUN_ID environment variable. """ base_url: str = field( @@ -28,16 +28,16 @@ class GriptapeCloudEventListenerDriver(BaseEventListenerDriver): headers: dict = field( default=Factory(lambda self: {"Authorization": f"Bearer {self.api_key}"}, takes_self=True), kw_only=True ) - run_id: str = field(default=Factory(lambda: os.getenv("GT_CLOUD_RUN_ID")), kw_only=True) + structure_run_id: str = field(default=Factory(lambda: os.getenv("GT_CLOUD_STRUCTURE_RUN_ID")), kw_only=True) - @run_id.validator # pyright: ignore - def validate_run_id(self, _, run_id: str): - if run_id is None: + @structure_run_id.validator # pyright: ignore + def validate_run_id(self, _, structure_run_id: str): + if structure_run_id is None: raise ValueError( - "run_id must be set either in the constructor or as an environment variable (GT_CLOUD_RUN_ID)." + "structure_run_id must be set either in the constructor or as an environment variable (GT_CLOUD_STRUCTURE_RUN_ID)." ) def try_publish_event(self, event: BaseEvent) -> None: - url = urljoin(self.base_url.strip("/"), f"/api/structure-runs/{self.run_id}/events") + url = urljoin(self.base_url.strip("/"), f"/api/structure-runs/{self.structure_run_id}/events") requests.post(url=url, json=event.to_dict(), headers=self.headers) diff --git a/tests/unit/drivers/event_listener/test_griptape_cloud_event_listener_driver.py b/tests/unit/drivers/event_listener/test_griptape_cloud_event_listener_driver.py index bbffa1059..8d2a261ba 100644 --- a/tests/unit/drivers/event_listener/test_griptape_cloud_event_listener_driver.py +++ b/tests/unit/drivers/event_listener/test_griptape_cloud_event_listener_driver.py @@ -22,12 +22,12 @@ def mock_post(self, mocker): def driver(self): os.environ["GT_CLOUD_BASE_URL"] = "https://cloud123.griptape.ai" - return GriptapeCloudEventListenerDriver(api_key="foo bar", run_id="bar baz") + return GriptapeCloudEventListenerDriver(api_key="foo bar", structure_run_id="bar baz") def test_init(self, driver): assert driver assert driver.api_key == "foo bar" - assert driver.run_id == "bar baz" + assert driver.structure_run_id == "bar baz" def test_try_publish_event(self, mock_post, driver): event = MockEvent() @@ -39,6 +39,6 @@ def test_try_publish_event(self, mock_post, driver): headers={"Authorization": "Bearer foo bar"}, ) - def test_no_run_id(self): + def test_no_structure_run_id(self): with pytest.raises(ValueError): GriptapeCloudEventListenerDriver(api_key="foo bar")