|
8 | 8 | from warnings import warn
|
9 | 9 |
|
10 | 10 | from openhexa.graphql.graphql_client import WorkspaceWorkspaceCountries
|
| 11 | +from openhexa.graphql.graphql_client.input_types import UpdateWorkspaceInput |
11 | 12 | from openhexa.utils import stringcase
|
12 | 13 |
|
13 | 14 | from ..datasets import Dataset
|
@@ -80,6 +81,46 @@ def configuration(self) -> dict[str, str | dict] | None:
|
80 | 81 | return None
|
81 | 82 | return OpenHexaClient().workspace(slug=self.slug).configuration
|
82 | 83 |
|
| 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 | + |
83 | 124 | @property
|
84 | 125 | def database_host(self) -> str:
|
85 | 126 | """The workspace database host."""
|
|
0 commit comments