mirror of
https://github.com/clearml/clearml-server
synced 2025-01-31 19:06:55 +00:00
Add connection string functionality for MongoDB access (#102)
This commit is contained in:
parent
1502e02a1a
commit
bc2c2ebbfd
@ -28,6 +28,8 @@ OVERRIDE_PORT_ENV_KEY = (
|
|||||||
"MONGODB_SERVICE_PORT",
|
"MONGODB_SERVICE_PORT",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
OVERRIDE_CONNECTION_STRING_ENV_KEY = "CLEARML_MONGODB_SERVICE_CONNECTION_STRING"
|
||||||
|
|
||||||
|
|
||||||
class DatabaseEntry(models.Base):
|
class DatabaseEntry(models.Base):
|
||||||
host = StringField(required=True)
|
host = StringField(required=True)
|
||||||
@ -47,13 +49,17 @@ class DatabaseFactory:
|
|||||||
missing = []
|
missing = []
|
||||||
log.info("Initializing database connections")
|
log.info("Initializing database connections")
|
||||||
|
|
||||||
|
override_connection_string = getenv(OVERRIDE_CONNECTION_STRING_ENV_KEY)
|
||||||
override_hostname = first(map(getenv, OVERRIDE_HOST_ENV_KEY), None)
|
override_hostname = first(map(getenv, OVERRIDE_HOST_ENV_KEY), None)
|
||||||
if override_hostname:
|
|
||||||
log.info(f"Using override mongodb host {override_hostname}")
|
|
||||||
|
|
||||||
override_port = first(map(getenv, OVERRIDE_PORT_ENV_KEY), None)
|
override_port = first(map(getenv, OVERRIDE_PORT_ENV_KEY), None)
|
||||||
if override_port:
|
|
||||||
log.info(f"Using override mongodb port {override_port}")
|
if override_connection_string:
|
||||||
|
log.info(f"Using override mongodb connection string {override_connection_string}")
|
||||||
|
else:
|
||||||
|
if override_hostname:
|
||||||
|
log.info(f"Using override mongodb host {override_hostname}")
|
||||||
|
if override_port:
|
||||||
|
log.info(f"Using override mongodb port {override_port}")
|
||||||
|
|
||||||
for key, alias in get_items(Database).items():
|
for key, alias in get_items(Database).items():
|
||||||
if key not in db_entries:
|
if key not in db_entries:
|
||||||
@ -62,11 +68,13 @@ class DatabaseFactory:
|
|||||||
|
|
||||||
entry = cls._create_db_entry(alias=alias, settings=db_entries.get(key))
|
entry = cls._create_db_entry(alias=alias, settings=db_entries.get(key))
|
||||||
|
|
||||||
if override_hostname:
|
if override_connection_string:
|
||||||
entry.host = furl(entry.host).set(host=override_hostname).url
|
entry.host = override_connection_string
|
||||||
|
else:
|
||||||
if override_port:
|
if override_hostname:
|
||||||
entry.host = furl(entry.host).set(port=override_port).url
|
entry.host = furl(entry.host).set(host=override_hostname).url
|
||||||
|
if override_port:
|
||||||
|
entry.host = furl(entry.host).set(port=override_port).url
|
||||||
|
|
||||||
try:
|
try:
|
||||||
entry.validate()
|
entry.validate()
|
||||||
|
Loading…
Reference in New Issue
Block a user