Skip to content

Commit 3c38fe0

Browse files
authored
feat(workspace): PATHWAYS-634 update worksapce settings (#304)
1 parent 9134079 commit 3c38fe0

File tree

7 files changed

+68
-1
lines changed

7 files changed

+68
-1
lines changed

openhexa/graphql/graphql_client/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ def update_workspace(
677677
slug
678678
name
679679
description
680+
configuration
680681
countries {
681682
code
682683
alpha3

openhexa/graphql/graphql_client/input_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ class UpdateWebappInput(BaseModel):
609609

610610

611611
class UpdateWorkspaceInput(BaseModel):
612+
configuration: Optional[Any] = None
612613
countries: Optional[List["CountryInput"]] = None
613614
description: Optional[str] = None
614615
docker_image: Optional[str] = Field(alias="dockerImage", default=None)

openhexa/graphql/graphql_client/update_workspace.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Generated by ariadne-codegen
22
# Source: openhexa/graphql/queries.graphql
33

4-
from typing import List, Optional
4+
from typing import Any, List, Optional
55

66
from pydantic import Field
77

@@ -23,6 +23,7 @@ class UpdateWorkspaceUpdateWorkspaceWorkspace(BaseModel):
2323
slug: str
2424
name: str
2525
description: Optional[str]
26+
configuration: Optional[Any]
2627
countries: List["UpdateWorkspaceUpdateWorkspaceWorkspaceCountries"]
2728

2829

openhexa/graphql/queries.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ mutation UpdateWorkspace($input: UpdateWorkspaceInput!) {
262262
slug
263263
name
264264
description
265+
configuration
265266
countries {
266267
code
267268
alpha3

openhexa/graphql/schema.generated.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3903,6 +3903,7 @@ enum UpdateWorkspaceError {
39033903

39043904
"""Represents the input for updating a workspace."""
39053905
input UpdateWorkspaceInput {
3906+
configuration: JSON
39063907
countries: [CountryInput!]
39073908
description: String
39083909
dockerImage: String

openhexa/sdk/workspaces/current_workspace.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from warnings import warn
99

1010
from openhexa.graphql.graphql_client import WorkspaceWorkspaceCountries
11+
from openhexa.graphql.graphql_client.input_types import UpdateWorkspaceInput
1112
from openhexa.utils import stringcase
1213

1314
from ..datasets import Dataset
@@ -80,6 +81,46 @@ def configuration(self) -> dict[str, str | dict] | None:
8081
return None
8182
return OpenHexaClient().workspace(slug=self.slug).configuration
8283

84+
@configuration.setter
85+
def configuration(self, value: dict[str, str | dict]) -> None:
86+
"""Set the workspace configuration.
87+
88+
Parameters
89+
----------
90+
value : dict[str, str | dict]
91+
The configuration dictionary to set for the workspace.
92+
Keys must be strings and values can be strings or JSON objects.
93+
94+
Raises
95+
------
96+
WorkspaceConfigError
97+
If not connected to the API or if the update fails.
98+
99+
Examples
100+
--------
101+
>>> workspace.configuration = {
102+
... "api_url": "https://api.example.com",
103+
... "debug_mode": "true",
104+
... "SNT_CONFIG": "VERY_GOOD_CONFIG"
105+
... }
106+
"""
107+
if not self._connected:
108+
raise WorkspaceConfigError("Cannot update configuration: not connected to the API.")
109+
110+
try:
111+
client = OpenHexaClient()
112+
113+
input_data = UpdateWorkspaceInput(slug=self.slug, configuration=value)
114+
result = client.update_workspace(input=input_data)
115+
116+
if not result.success:
117+
raise WorkspaceConfigError("Failed to update workspace configuration.")
118+
119+
except Exception as e:
120+
if isinstance(e, WorkspaceConfigError):
121+
raise
122+
raise WorkspaceConfigError(f"Failed to update workspace configuration: {str(e)}")
123+
83124
@property
84125
def database_host(self) -> str:
85126
"""The workspace database host."""

tests/test_workspace.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,24 @@ def test_workspace_configuration(self, workspace):
557557
with mock.patch("openhexa.sdk.workspaces.current_workspace.OpenHexaClient") as mock_client:
558558
mock_client.return_value.workspace.return_value = mock_workspace_data
559559
assert workspace.configuration == mock_config
560+
561+
def test_workspace_configuration_setter(self, workspace):
562+
"""Test setting workspace configuration through property setter."""
563+
new_config = {
564+
"api_url": "https://new-api.example.com",
565+
"environment": "development",
566+
"features": {"feature1": True, "feature2": False},
567+
}
568+
569+
mock_result = mock.Mock()
570+
mock_result.success = True
571+
572+
with mock.patch("openhexa.sdk.workspaces.current_workspace.OpenHexaClient") as mock_client:
573+
mock_client.return_value.update_workspace.return_value = mock_result
574+
575+
workspace.configuration = new_config
576+
577+
mock_client.return_value.update_workspace.assert_called_once()
578+
call_args = mock_client.return_value.update_workspace.call_args[1]["input"]
579+
assert call_args.slug == workspace.slug
580+
assert call_args.configuration == new_config

0 commit comments

Comments
 (0)