Skip to content

Commit

Permalink
use exception handler from python geonetwork lib
Browse files Browse the repository at this point in the history
  • Loading branch information
mki-c2c committed Feb 3, 2025
1 parent d7f8aaf commit c9e6edd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
12 changes: 7 additions & 5 deletions backend/maelstro/core/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ def __init__(self, err_dict: dict[str, str]):

class ParamError(MaelstroException):
def __init__(self, err_dict: dict[str, str]):
super().__init__({**err_dict, "status_code": "406"})
super().__init__({**err_dict, "status_code": "400"})


# pylint: disable=fixme
# TODO: handle requests.exceptions.ConnectTimeout errorxception
class TimeoutError(MaelstroException):
class RequestTimeoutError(MaelstroException):
def __init__(self, err_dict: dict[str, str]):
super().__init__({**err_dict, "status_code": "406"})
super().__init__({**err_dict, "status_code": "400"})


class CloneDataset:
Expand All @@ -56,6 +57,7 @@ def __init__(self, src_name: str, dst_name: str, uuid: str, dry: bool = False):
self.copy_layers = False
self.copy_styles = False
self.dry = dry
self.meta = None

def set_uuid(self, uuid: str) -> None:
self.uuid = uuid
Expand Down Expand Up @@ -107,7 +109,7 @@ def clone_dataset(
"GnApi",
"clone",
)
raise HTTPException(406, self.op_logger.get_operations()) from err
raise HTTPException(400, self.op_logger.get_operations()) from err
self.op_logger.log_operation(
results["msg"],
results["detail"],
Expand All @@ -133,7 +135,7 @@ def clone_dataset(
"GnApi",
"clone",
)
raise HTTPException(406, self.op_logger.get_operations()) from err
raise HTTPException(400, self.op_logger.get_operations()) from err

if output_format == "text/plain":
return self.op_logger.format_operations()
Expand Down
4 changes: 2 additions & 2 deletions backend/maelstro/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get_layers(src_name: str, uuid: str) -> list[dict[str, str]]:
is_src=True, is_geonetwork=True, instance_id=src_name
)
except ConfigError as err:
raise HTTPException(status_code=406, detail=err.args) from err
raise HTTPException(status_code=400, detail=err.args) from err

gn = GnApi(src_info["url"], src_info["auth"])
zipdata = gn.get_record_zip(uuid).read()
Expand All @@ -121,7 +121,7 @@ def get_layers(src_name: str, uuid: str) -> list[dict[str, str]]:
"/copy",
responses={
200: {"content": {"text/plain": {}, "application/json": {}}},
406: {"description": "should be 404, but 404 is rewritten by the gateway"},
400: {"description": "should be 404, but 404 is rewritten by the gateway"},
},
)
def put_dataset_copy(
Expand Down
2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies = [
"lxml (>=5.3.0,<6.0.0)",
"types-pyyaml (>=6.0.12.20241230,<7.0.0.0)",
"lxml-stubs (>=0.5.1,<0.6.0)",
"geonetwork @ git+https://github.com/camptocamp/python-geonetwork",
"geonetwork @ git+https://github.com/camptocamp/python-geonetwork@56d7317b7874726a251b5f74fd0b9ea0e26cce49",
"geoservercloud @ git+https://github.com/camptocamp/python-geoservercloud",
]

Expand Down
8 changes: 5 additions & 3 deletions georchestra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ docker compose up -d
# add role MAELSTRO + add testadmin into it, + create tmaelstro
python3 georchestra/init-plateform.py
docker compose run --no-deps --rm -v $(pwd)/georchestra:/georchestra maelstro-back python /georchestra/init-plateform.py
# set user tmaelstro password to tmaelstro
docker compose exec -it ldap bash -c "ldapmodify -H ldap://localhost:389 -D cn=admin,dc=georchestra,dc=org -w secret << EOF
dn: uid=tmaelstro,ou=users,dc=georchestra,dc=org
changetype: modify
add: userPassword
userPassword:: e1NTSEF9cXlQT25BQUkzei9lb3JEZ0FDa3JzYy9hcmRjcGpCdVNyTDBya3c9PQ=
=
userPassword: tmaelstro
EOF"
Expand All @@ -39,6 +38,9 @@ docker compose run -v $(pwd)/georchestra/create_maelstro_gs_rsc.py:/scripts/crea
docker compose cp georchestra/psc_antenne.sql postgis:/psc_antenne.sql
docker compose exec -it postgis bash -c "psql -U georchestra -d datafeeder < psc_antenne.sql"
cat georchestra/psc_antenne.sql | docker compose exec -T postgis psql -U georchestra -d datafeeder
```

14 changes: 7 additions & 7 deletions georchestra/create_maelstro_gs_rsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

# https://github.com/camptocamp/python-geoservercloud

cat = GeoServerCloud(url="https://georchestra-127-0-0-1.nip.io/geoserver",
cat = GeoServerCloud(url="http://proxy:8080/geoserver",
user="testadmin",
password="testadmin")

ws='psc'
ds="datafeeder_psc"

try:
cat.create_workspace(workspace=ws)
cat.create_workspace(ws)
except:
print("pb with workspace")
try:
cat.create_jndi_datastore(workspace=ws,
datastore=ds,
jndi_reference="jdbc/datafeeder",
schema="psc",
description="Datafeeder uploaded datasets")
cat.create_jndi_datastore(ws,
ds,
"jdbc/datafeeder",
"psc",
"Datafeeder uploaded datasets")
except:
print("Error creating the datastore")
pass
5 changes: 3 additions & 2 deletions georchestra/init-plateform.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
username = 'testadmin'
password = 'testadmin'

server = "https://georchestra-127-0-0-1.nip.io"
# server = "https://georchestra-127-0-0-1.nip.io"
server = "http://proxy:8080"

geOrchestra_api = geOrchestra(server, username, password)

print(geOrchestra_api.console.createnewroles(cn="MAELSTRO"))
print(geOrchestra_api.console.updaterolesuser(uuid="testadmin",cn="MAELSTRO"))
print(geOrchestra_api.console.createnewuser(org="PSC",sn="MAELSTRO", givenname="Test", mail="[email protected]", description="This user is for development test of maelstro"))
print(geOrchestra_api.console.createnewuser(org="PSC",sn="MAELSTRO", givenname="Test", mail="[email protected]", description="This user is for development test of maelstro"))

0 comments on commit c9e6edd

Please sign in to comment.