-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
446 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
from .common import KeyDollarListDict | ||
from .dataStore import PostGisDataStore | ||
from .dataStores import DataStores | ||
from .workspace import Workspace | ||
from .workspaces import Workspaces | ||
|
||
__all__ = ["KeyDollarListDict", "Workspaces", "Workspace"] | ||
__all__ = [ | ||
"DataStores", | ||
"KeyDollarListDict", | ||
"PostGisDataStore", | ||
"Workspaces", | ||
"Workspace", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import logging | ||
|
||
from . import KeyDollarListDict | ||
|
||
log = logging.getLogger() | ||
|
||
|
||
class PostGisDataStore: | ||
|
||
def __init__( | ||
self, | ||
workspace_name: str, | ||
data_store_name: str, | ||
connection_parameters: KeyDollarListDict, | ||
data_store_type: str = "PostGIS", | ||
enabled: bool = True, | ||
description: str | None = None, | ||
) -> None: | ||
self.workspace_name = workspace_name | ||
self.data_store_name = data_store_name | ||
self.connection_parameters = connection_parameters | ||
self.data_store_type = data_store_type | ||
self.description = description | ||
self.enabled = enabled | ||
|
||
@property | ||
def name(self): | ||
return self.data_store_name | ||
|
||
def post_payload(self): | ||
payload = { | ||
"dataStore": { | ||
"name": self.data_store_name, | ||
"type": self.data_store_type, | ||
"connectionParameters": { | ||
"entry": self.connection_parameters.serialize() | ||
}, | ||
} | ||
} | ||
if self.description: | ||
payload["dataStore"]["description"] = self.description | ||
if self.enabled: | ||
payload["dataStore"]["enabled"] = self.enabled | ||
return payload | ||
|
||
def put_payload(self): | ||
payload = self.post_payload() | ||
return payload | ||
|
||
@classmethod | ||
def from_response(cls, response): | ||
|
||
json_data = response.json() | ||
connection_parameters = cls.parse_connection_parameters(json_data) | ||
return cls( | ||
json_data.get("dataStore", {}).get("workspace", {}).get("name", None), | ||
json_data.get("dataStore", {}).get("name", None), | ||
connection_parameters, | ||
json_data.get("dataStore", {}).get("type", "PostGIS"), | ||
json_data.get("dataStore", {}).get("enabled", True), | ||
json_data.get("dataStore", {}).get("description", None), | ||
) | ||
|
||
@classmethod | ||
def parse_connection_parameters(cls, json_data): | ||
return KeyDollarListDict( | ||
json_data.get("dataStore", {}) | ||
.get("connectionParameters", {}) | ||
.get("entry", []) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import logging | ||
|
||
import jsonschema | ||
import requests | ||
|
||
log = logging.getLogger() | ||
|
||
|
||
class DataStores: | ||
|
||
def __init__(self, workspace_name: str, datastores: list[str] = []) -> None: | ||
self.workspace_name = workspace_name | ||
self._datastores = datastores | ||
|
||
@property | ||
def datastores(self): | ||
return self._datastores | ||
|
||
@classmethod | ||
def from_response(cls, response): | ||
json_data = response.json() | ||
datastores = [] | ||
workspace_name = ( | ||
json_data.get("dataStores", {}).get("workspace", {}).get("name", None) | ||
) | ||
for store in json_data.get("dataStores", {}).get("dataStore", []): | ||
datastores.append(store["name"]) | ||
for data_store_name in datastores: | ||
log.debug(f"Name: {data_store_name}") | ||
return cls(workspace_name, datastores) | ||
|
||
def __repr__(self): | ||
return str(self.datastores) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.