mirror of
https://github.com/clearml/clearml-server
synced 2025-03-03 10:43:10 +00:00
Add easier sub-domains configuration
This commit is contained in:
parent
bed714890d
commit
d24f633a8e
@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
from os import getenv
|
||||
|
||||
from elasticsearch import Elasticsearch, Transport
|
||||
|
||||
@ -6,6 +7,12 @@ from config import config
|
||||
|
||||
log = config.logger(__file__)
|
||||
|
||||
OVERRIDE_HOST_ENV_KEY = "ELASTIC_SERVICE_SERVICE_HOST"
|
||||
|
||||
OVERRIDE_HOST = getenv(OVERRIDE_HOST_ENV_KEY)
|
||||
if OVERRIDE_HOST:
|
||||
log.info(f"Using override elastic host {OVERRIDE_HOST}")
|
||||
|
||||
_instances = {}
|
||||
|
||||
|
||||
@ -33,17 +40,18 @@ def connect(cluster_name):
|
||||
:raises InvalidClusterConfiguration: in case cluster config section misses needed properties
|
||||
"""
|
||||
if cluster_name not in _instances:
|
||||
cluster_config = _get_cluster_config(cluster_name)
|
||||
cluster_config = get_cluster_config(cluster_name)
|
||||
hosts = cluster_config.get('hosts', None)
|
||||
if not hosts:
|
||||
raise InvalidClusterConfiguration(cluster_name)
|
||||
|
||||
args = cluster_config.get('args', {})
|
||||
_instances[cluster_name] = Elasticsearch(hosts=hosts, transport_class=Transport, **args)
|
||||
|
||||
return _instances[cluster_name]
|
||||
|
||||
|
||||
def _get_cluster_config(cluster_name):
|
||||
def get_cluster_config(cluster_name):
|
||||
"""
|
||||
Returns cluster config for the specified cluster path
|
||||
:param cluster_name: Dot separated cluster path in the configuration file
|
||||
@ -55,6 +63,10 @@ def _get_cluster_config(cluster_name):
|
||||
if not cluster_config:
|
||||
raise MissingClusterConfiguration(cluster_name)
|
||||
|
||||
if OVERRIDE_HOST:
|
||||
for host in cluster_config.get('hosts', []):
|
||||
host["host"] = OVERRIDE_HOST
|
||||
|
||||
return cluster_config
|
||||
|
||||
|
||||
|
@ -1,13 +1,15 @@
|
||||
from datetime import datetime
|
||||
|
||||
import attr
|
||||
from furl import furl
|
||||
|
||||
from database.model.user import User
|
||||
from database.model.auth import User as AuthUser, Credentials
|
||||
from config import config
|
||||
from database.model.auth import Role
|
||||
from database.model.auth import User as AuthUser, Credentials
|
||||
from database.model.company import Company
|
||||
from database.model.user import User
|
||||
from elastic.apply_mappings import apply_mappings_to_host
|
||||
from es_factory import get_cluster_config
|
||||
from service_repo.auth.fixed_user import FixedUser
|
||||
|
||||
log = config.logger(__file__)
|
||||
@ -22,10 +24,9 @@ class MissingElasticConfiguration(Exception):
|
||||
|
||||
|
||||
def init_es_data():
|
||||
hosts_key = "hosts.elastic.events.hosts"
|
||||
hosts_config = config.get(hosts_key, None)
|
||||
hosts_config = get_cluster_config("events").get("hosts")
|
||||
if not hosts_config:
|
||||
raise MissingElasticConfiguration(hosts_key)
|
||||
raise MissingElasticConfiguration("for cluster 'events'")
|
||||
|
||||
for conf in hosts_config:
|
||||
host = furl(scheme="http", host=conf["host"], port=conf["port"]).url
|
||||
@ -117,7 +118,11 @@ def init_mongo_data():
|
||||
_ensure_auth_user(user, company_id)
|
||||
|
||||
if FixedUser.enabled():
|
||||
log.info("Fixed users mode is enabled")
|
||||
for user in FixedUser.from_config():
|
||||
try:
|
||||
_ensure_user(user, company_id)
|
||||
except Exception as ex:
|
||||
log.error(f"Failed creating fixed user {user['name']}: {ex}")
|
||||
except Exception as ex:
|
||||
pass
|
||||
|
@ -16,7 +16,7 @@ from utilities import json
|
||||
from init_data import init_es_data, init_mongo_data
|
||||
|
||||
app = Flask(__name__, static_url_path="/static")
|
||||
CORS(app, supports_credentials=True, **config.get("apiserver.cors"))
|
||||
CORS(app, **config.get("apiserver.cors"))
|
||||
Compress(app)
|
||||
|
||||
log = config.logger(__file__)
|
||||
@ -63,6 +63,9 @@ def before_request():
|
||||
|
||||
if call.result.cookies:
|
||||
for key, value in call.result.cookies.items():
|
||||
if value is None:
|
||||
response.set_cookie(key, "", expires=0)
|
||||
else:
|
||||
response.set_cookie(key, value, **config.get("apiserver.auth.cookies"))
|
||||
|
||||
return response
|
||||
|
Loading…
Reference in New Issue
Block a user