Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openhexa/graphql/graphql_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ def workspace(self, slug: str, **kwargs: Any) -> Optional[WorkspaceWorkspace]:
name
description
dockerImage
configuration
countries {
code
flag
Expand Down
3 changes: 2 additions & 1 deletion openhexa/graphql/graphql_client/workspace.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by ariadne-codegen
# Source: openhexa/graphql/queries.graphql

from typing import List, Optional
from typing import Any, List, Optional

from pydantic import Field

Expand All @@ -17,6 +17,7 @@ class WorkspaceWorkspace(BaseModel):
name: str
description: Optional[str]
docker_image: Optional[str] = Field(alias="dockerImage")
configuration: Optional[Any]
countries: List["WorkspaceWorkspaceCountries"]
permissions: "WorkspaceWorkspacePermissions"

Expand Down
1 change: 1 addition & 0 deletions openhexa/graphql/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ query Workspace($slug: String!) {
name
description
dockerImage
configuration
countries {
code
flag
Expand Down
2 changes: 2 additions & 0 deletions openhexa/graphql/schema.generated.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4090,6 +4090,8 @@ Represents a workspace. A workspace is a shared environment where users can coll
type Workspace {
"""File storage of the workspace represented as a bucket"""
bucket: Bucket!
"""JSON field containing workspace configuration as key-value pairs"""
configuration: JSON
connections: [Connection!]!
countries: [Country!]!
createdAt: DateTime!
Expand Down
12 changes: 12 additions & 0 deletions openhexa/sdk/workspaces/current_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ def countries(self) -> list[WorkspaceWorkspaceCountries]:
except KeyError:
raise WorkspaceConfigError("The workspace countries are not available in this environment.")

@property
def configuration(self) -> dict[str, str | dict] | None:
"""The workspace configuration as a dictionary.

Returns a dictionary containing workspace configuration as key-value pairs,
where keys are strings and values can be either strings or JSON objects.
Returns None if no configuration is available or if not connected to the API.
"""
if not self._connected:
return None
return OpenHexaClient().workspace(slug=self.slug).configuration

@property
def database_host(self) -> str:
"""The workspace database host."""
Expand Down
14 changes: 14 additions & 0 deletions tests/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,17 @@ def test_connection_various_case(self, workspace):
assert workspace.dhis2_connection("polio-123").url == url
assert workspace.dhis2_connection("Polio-123").url == url
assert workspace.dhis2_connection("POLIO-123").url == url

def test_workspace_configuration(self, workspace):
mock_config = {
"api_url": "https://api.example.com",
"debug_mode": "true",
"database_config": {"host": "localhost", "port": 5432},
}

mock_workspace_data = mock.Mock()
mock_workspace_data.configuration = mock_config

with mock.patch("openhexa.sdk.workspaces.current_workspace.OpenHexaClient") as mock_client:
mock_client.return_value.workspace.return_value = mock_workspace_data
assert workspace.configuration == mock_config