mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
added lib to ftrack_server with functios able to handle mongo url parts
This commit is contained in:
parent
3a5525edf6
commit
e7c9a61b2e
2 changed files with 69 additions and 1 deletions
|
|
@ -1,2 +1,2 @@
|
||||||
from .lib import *
|
from .lib import *
|
||||||
from .ftrack_server import *
|
from .ftrack_server import FtrackServer
|
||||||
|
|
|
||||||
68
pype/ftrack/ftrack_server/lib.py
Normal file
68
pype/ftrack/ftrack_server/lib.py
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
import os
|
||||||
|
try:
|
||||||
|
from urllib.parse import urlparse, parse_qs
|
||||||
|
except ImportError:
|
||||||
|
from urlparse import urlparse, parse_qs
|
||||||
|
|
||||||
|
|
||||||
|
def ftrack_events_mongo_settings():
|
||||||
|
host = None
|
||||||
|
port = None
|
||||||
|
username = None
|
||||||
|
password = None
|
||||||
|
collection = None
|
||||||
|
database = None
|
||||||
|
auth_db = ""
|
||||||
|
|
||||||
|
if os.environ.get('FTRACK_EVENTS_MONGO_URL'):
|
||||||
|
result = urlparse(os.environ['FTRACK_EVENTS_MONGO_URL'])
|
||||||
|
|
||||||
|
host = result.hostname
|
||||||
|
try:
|
||||||
|
port = result.port
|
||||||
|
except ValueError:
|
||||||
|
raise RuntimeError("invalid port specified")
|
||||||
|
username = result.username
|
||||||
|
password = result.password
|
||||||
|
try:
|
||||||
|
database = result.path.lstrip("/").split("/")[0]
|
||||||
|
collection = result.path.lstrip("/").split("/")[1]
|
||||||
|
except IndexError:
|
||||||
|
if not database:
|
||||||
|
raise RuntimeError("missing database name for logging")
|
||||||
|
try:
|
||||||
|
auth_db = parse_qs(result.query)['authSource'][0]
|
||||||
|
except KeyError:
|
||||||
|
# no auth db provided, mongo will use the one we are connecting to
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
host = os.environ.get('FTRACK_EVENTS_MONGO_HOST')
|
||||||
|
port = int(os.environ.get('FTRACK_EVENTS_MONGO_PORT', "0"))
|
||||||
|
database = os.environ.get('FTRACK_EVENTS_MONGO_DB')
|
||||||
|
username = os.environ.get('FTRACK_EVENTS_MONGO_USER')
|
||||||
|
password = os.environ.get('FTRACK_EVENTS_MONGO_PASSWORD')
|
||||||
|
collection = os.environ.get('FTRACK_EVENTS_MONGO_COL')
|
||||||
|
auth_db = os.environ.get('FTRACK_EVENTS_MONGO_AUTH_DB', 'avalon')
|
||||||
|
|
||||||
|
return host, port, database, username, password, collection, auth_db
|
||||||
|
|
||||||
|
|
||||||
|
def get_ftrack_event_mongo_info():
|
||||||
|
host, port, database, username, password, collection, auth_db = ftrack_events_mongo_settings()
|
||||||
|
user_pass = ""
|
||||||
|
if username and password:
|
||||||
|
user_pass = "{}:{}@".format(username, password)
|
||||||
|
|
||||||
|
socket_path = "{}:{}".format(host, port)
|
||||||
|
|
||||||
|
dab = ""
|
||||||
|
if database:
|
||||||
|
dab = "/{}".format(database)
|
||||||
|
|
||||||
|
auth = ""
|
||||||
|
if auth_db:
|
||||||
|
auth = "?authSource={}".format(auth_db)
|
||||||
|
|
||||||
|
url = "mongodb://{}{}{}{}".format(user_pass, socket_path, dab, auth)
|
||||||
|
|
||||||
|
return url, database, collection
|
||||||
Loading…
Add table
Add a link
Reference in a new issue