Commit 1fb09c97 authored by Sebastian Wagner's avatar Sebastian Wagner Committed by Thomas Beermann
Browse files

Use split config like other services

parent 075fd3c7
......@@ -19,5 +19,9 @@ Run tests with `poetry run pytest`. While plony responses are simulated during t
|`PLONY_BASE_URL`|The base URL of the plony instance. Useful for connecting to the test instance.|
|`PLONY_USER`|The username used to authenticate with plony.|
|`PLONY_PASSWORD`|The password used for authenticating with plony.|
|`MONGODB_URL`|Location and credentials for connecting to to the mongodb instance e.g. `mongodb://user:password@hostname:27017/` or `mongodb://mongo` in dev.|
|`MONGODB_DB`|Name of the mongodb database the script should write to e.g. `local`.|
\ No newline at end of file
|`MONGODB_HOST`|The hostname of the mongodb server.|
|`MONGODB_PORT`|The port of the mongodb server.|
|`MONGODB_USER`|The user on the mongodb server.|
|`MONGODB_PASSWORD`|The password of the user on the mongodb server.|
|`MONGODB_AUTH_SOURCE`|The authentication source for the mongodb server connection.|
|`MONGODB_DATABASE`|Name of the mongodb database the script should write to e.g. `local`.|
\ No newline at end of file
......@@ -15,8 +15,24 @@ if __name__ == "__main__":
config["PLONY_USER"], config["PLONY_PASSWORD"], config["PLONY_BASE_URL"]
)
# Build a mongodb connect URL from the config
db_credentials = ""
# In local dev there is no auth so pass an empty string in that case
if config["MONGODB_USER"] is not None and config["MONGODB_PASSWORD"] is not None:
db_credentials = f"{config['MONGODB_USER']}:{config['MONGODB_PASSWORD']}@"
db_auth_source = "?authSource=defaultauthdb"
if config["MONGODB_AUTH_SOURCE"] is not None:
db_auth_source = f"?authSource={config['MONGODB_AUTH_SOURCE']}"
mongodb_url = (
f"mongodb://{db_credentials}{config['MONGODB_HOST']}:{config['MONGODB_PORT']}/{db_auth_source}"
)
db = plony_importer.portal.database.Database(
config["MONGODB_URL"], config["MONGODB_DB"]
mongodb_url, config["MONGODB_DATABASE"]
)
asyncio.run(plony_importer.importer.run_import(plony_client, db))
......@@ -5,12 +5,19 @@ import sys
import typing
# Required configuration variables to be loaded from the environment
CONFIG_VARS = [
REQUIRED_VARS = [
"PLONY_BASE_URL",
"PLONY_USER",
"PLONY_PASSWORD",
"MONGODB_URL",
"MONGODB_DB",
"MONGODB_HOST",
"MONGODB_PORT",
"MONGODB_DATABASE",
]
OPTIONAL_VARS = [
"MONGODB_USER",
"MONGODB_PASSWORD",
"MONGODB_AUTH_SOURCE",
]
......@@ -19,10 +26,10 @@ def load() -> typing.Dict[str, str]:
config = {}
for config_var in CONFIG_VARS:
for config_var in REQUIRED_VARS + OPTIONAL_VARS:
var_from_env = os.getenv(config_var)
if var_from_env is None:
if (var_from_env is None) and (config_var not in OPTIONAL_VARS):
print(
f"FATAL: Required environment variable {config_var} is not set. Stopping import."
)
......
......@@ -7,5 +7,8 @@ PLONY_BASE_URL=https://plony-test.helmholtz-berlin.de
PLONY_USER=dummyuser
PLONY_PASSWORD=dummysecret
MONGODB_URL=mongodb://mongo
MONGODB_DB=local
MONGODB_HOST=mongo
MONGODB_PORT=27017
MONGODB_USER=
MONGODB_PASSWORD=
MONGODB_DATABASE=local
......@@ -3,8 +3,8 @@ services:
image: registry.hzdr.de/hifis/cloud/access-layer/portal/dev:latest
hostname: portal-dev
ports:
- "8080:8080"
- "8090:8090"
- "127.0.0.1:8080:8080"
- "127.0.0.1:8090:8090"
# forward signals so it shuts down faster
init: true
env_file:
......@@ -23,4 +23,4 @@ services:
mongo:
image: registry.hub.docker.com/library/mongo:4.0.25
ports:
- "27017:27017"
- "127.0.0.1:27017:27017"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment