Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vuilleumierc committed Oct 15, 2024
1 parent 421ae04 commit b8bd7fa
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 308 deletions.
51 changes: 13 additions & 38 deletions geoservercloud/geoservercloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@
DataStores,
FeatureType,
FeatureTypes,
KeyDollarListDict,
PostGisDataStore,
Style,
Styles,
Workspace,
Workspaces,
)
from geoservercloud.services import (
AclEndpoints,
GwcEndpoints,
OwsEndpoints,
RestEndpoints,
RestService,
)
from geoservercloud.services import RestService
from geoservercloud.templates import Templates


Expand All @@ -44,10 +37,6 @@ def __init__(
self.password: str = password
self.auth: tuple[str, str] = (user, password)
self.rest_service: RestService = RestService(url, self.auth)
self.acl_endpoints: AclEndpoints = AclEndpoints()
self.gwc_endpoints: GwcEndpoints = GwcEndpoints()
self.ows_endpoints: OwsEndpoints = OwsEndpoints()
self.rest_endpoints: RestEndpoints = RestEndpoints()
self.wms: WebMapService_1_3_0 | None = None
self.wmts: WebMapTileService | None = None
self.default_workspace: str | None = None
Expand Down Expand Up @@ -84,50 +73,39 @@ def create_wmts(self) -> None:
password=self.password,
)

def get_workspaces(self) -> Workspaces:
response: Response = self.get_request(self.rest_endpoints.workspaces())
workspaces = Workspaces.from_dict(response.json())
return workspaces
def get_workspaces(self) -> list[str]:
return self.rest_service.get_workspaces().workspaces

def create_workspace(
self,
workspace_name: str,
isolated: bool = False,
set_default_workspace: bool = False,
) -> Response:
) -> dict[str, Any]:
"""
Create a workspace in GeoServer, if it does not already exist.
It if exists, update it
"""
response: Response = self.post_request(
self.rest_endpoints.workspaces(),
json=Workspace(workspace_name, isolated).post_payload(),
)
if response.status_code == 409:
response = self.put_request(
self.rest_endpoints.workspace(workspace_name),
json=Workspace(workspace_name, isolated).put_payload(),
)
workspace = self.rest_service.create_workspace(
workspace_name, isolated
).asdict()
if set_default_workspace:
self.default_workspace = workspace_name
return response
return workspace

def delete_workspace(self, workspace_name: str) -> Response:
def delete_workspace(self, workspace_name: str) -> None:
"""
Delete a GeoServer workspace (recursively)
"""
response: Response = self.delete_request(
self.rest_endpoints.workspace(workspace_name), params={"recurse": "true"}
)
self.rest_service.delete_workspace(workspace_name)
if self.default_workspace == workspace_name:
self.default_workspace = None
self.wms = None
self.wmts = None
return response

def recreate_workspace(
self, workspace_name: str, set_default_workspace: bool = False
) -> Response:
) -> dict[str, Any]:
"""
Create a workspace in GeoServer, and first delete it if it already exists.
"""
Expand All @@ -136,14 +114,11 @@ def recreate_workspace(
workspace_name, set_default_workspace=set_default_workspace
)

def publish_workspace(self, workspace_name) -> Response:
def publish_workspace(self, workspace_name) -> None:
"""
Publish the WMS service for a given workspace
"""
data: dict[str, dict[str, Any]] = Templates.workspace_wms(workspace_name)
return self.put_request(
self.rest_endpoints.workspace_wms_settings(workspace_name), json=data
)
self.rest_service.publish_workspace(workspace_name)

def set_default_locale_for_service(
self, workspace_name: str, locale: str | None
Expand Down
6 changes: 6 additions & 0 deletions geoservercloud/models/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@ def from_dict(cls, content: dict):
content.get("workspace", {}).get("isolated", False),
)

def asdict(self):
return {
"name": self.name,
"isolated": self.isolated,
}

def __repr__(self):
return json.dumps(self.put_payload(), indent=4)
5 changes: 0 additions & 5 deletions geoservercloud/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from .endpoints import AclEndpoints, GwcEndpoints, OwsEndpoints, RestEndpoints
from .restservice import RestService

__all__ = [
"RestService",
"AclEndpoints",
"OwsEndpoints",
"GwcEndpoints",
"RestEndpoints",
]
174 changes: 0 additions & 174 deletions geoservercloud/services/endpoints.py

This file was deleted.

Loading

0 comments on commit b8bd7fa

Please sign in to comment.