Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mki-c2c committed Jan 27, 2025
1 parent d5d89c5 commit c0a1ade
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 19 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ Refer to documentation in [frontend/README.md](frontend/README.md)
## Backend

The folder [backend](backend) contains the API written with FastAPI.

### Configuration

The configuration is based on a YAML file containing connection information about the source and destination servers. You can find an example of this file in <backend/tests/test_config.yaml>

The file has 2 categories:
- sources
- destinations

Sources contains 2 list of servers: `geonetwork_instances` and `geoserver_instances`. Each instance is described bu its url (api_url for geonetwork), and their credentials.

Destinations is a dict of geonetwork / geoserver combinations, each with their url and credentials.

The logics for credentials is by increasing order of importance:
- credentials defined at a higher level are applied to a lower level (e.g. common credentials can be defined for both geonetwork and geoserver in a destination item)
- credentials in the geoserver/geonetwork level are read from the keys "login", "password"
- if the keys "login_env_var" and/or "password_env_var" are found, the corrensponding environment variable is read, and if defined, overrides the credential

### Access

Expand Down
3 changes: 2 additions & 1 deletion backend/maelstro/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .config import Config as Config
from .config import ConfigError as ConfigError

__all__ = ["Config"]
__all__ = ["Config", "ConfigError"]
43 changes: 31 additions & 12 deletions backend/maelstro/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
from maelstro.common.types import Credentials


class ConfigError(Exception):
pass


class Config:
def __init__(
self, config_file: str = f"{os.path.dirname(__file__)}/../../config.yaml"
):
def __init__(self, config_file: str):
with open(config_file, encoding="utf8") as cf:
self.config = yaml.load(cf, yaml.Loader)

Expand Down Expand Up @@ -36,7 +38,7 @@ def get_access_info(
info = None
if is_src:
if is_geonetwork:
info = next(
infos = (
{
"auth": (gn.get("login"), gn.get("password")),
"url": gn["api_url"],
Expand All @@ -45,19 +47,34 @@ def get_access_info(
if gn["name"] == instance_id
)
else:
info = next(
infos = (
{"auth": (gs.get("login"), gs.get("password")), "url": gs["url"]}
for gs in self.config["sources"]["geoserver_instances"]
if gs["url"] == instance_id
)
try:
info = next(infos)
except StopIteration:
raise ConfigError(
f"Key {instance_id} could not be found among "
f"configured {'geonetwork' if is_geonetwork else 'geoserver'} "
"source servers."
)
else:
inst_type = "geonetwork" if is_geonetwork else "geoserver"
url_key = "api_url" if is_geonetwork else "url"
instance = next(
inst
for name, inst in self.config["destinations"].items()
if name == instance_id
)[inst_type]
try:
instance = next(
inst
for name, inst in self.config["destinations"].items()
if name == instance_id
)[inst_type]
except StopIteration:
raise ConfigError(
f"Key {instance_id} could not be found among "
f"configured {'geonetwork' if is_geonetwork else 'geoserver'} "
"destination servers."
)
info = {
"auth": (instance.get("login"), instance.get("password")),
"url": instance[url_key],
Expand All @@ -75,9 +92,11 @@ def substitute_single_credentials_from_env(
common_login, common_password = common_credentials

if common_login is not None:
server_instance["login"] = common_login
if server_instance.get("login") is None:
server_instance["login"] = common_login
if common_password is not None:
server_instance["password"] = common_password
if server_instance.get("password") is None:
server_instance["password"] = common_password

read_value_from_env(server_instance, "login")
read_value_from_env(server_instance, "password")
Expand Down
9 changes: 5 additions & 4 deletions backend/config.yaml → backend/tests/test_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ sources:
password_env_var: DEMO_LOGIN
geoserver_instances:
- url: "https://mastergs.rennesmetropole.fr/geoserver/"
login: admin
password: admin
login: test
password: 1234
- url: "https://mastergs.rennesmetropole.fr/geoserver-geofence/"
login: "toto6"
password: "Str0ng_passW0rd"
Expand All @@ -28,14 +28,15 @@ destinations:
password_env_var: LOCAL_LOGIN
geoserver:
url: https://georchestra-127-0-0-1.nip.io/geoserver
"Plateforme professionnelle":
"PlateformeProfessionnelle":
login: "toto"
password: "passW0rd" # si login et password sont précisés au niveau de l'IDG, ils sont communs aux instances geoserver et geonetwork
geoserver:
password: "overridePW" # si login ou password sont redéfinis à un niveau plus bas, ils prennent la priorité
url: https://portail.sig.rennesmetropole.fr/geoserver
geonetwork:
api_url: https://portail.sig.rennesmetropole.fr/geonetwork/srv/api
"Plateforme publique":
"PlateformePublique":
geoserver:
url: https://public.sig.rennesmetropole.fr/geoserver
# si login et password sont précisés au niveau de geoserver ou geonetwork, ils prennent la main
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ services:
volumes:
- ./backend:/app
- georchestra_datadir:/etc/georchestra
environment:
- LOCAL_LOGIN=admin
healthcheck:
test: "health_check"
interval: 10s
Expand Down

0 comments on commit c0a1ade

Please sign in to comment.