Skip to content

Commit

Permalink
Merge branch 'devel' into fix/issue_388
Browse files Browse the repository at this point in the history
  • Loading branch information
mtitov authored Oct 6, 2023
2 parents ad10c7f + e6faf8d commit 09642cc
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 340 deletions.
221 changes: 0 additions & 221 deletions bin/radical-utils-mongodb.py

This file was deleted.

1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ colorama
msgpack
netifaces
ntplib
pymongo<4
pyzmq
regex
setproctitle
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ def run(self):
'packages' : find_namespace_packages('src', include=['radical.*']),
'package_dir' : {'': 'src'},
'scripts' : ['bin/radical-utils-fix-headers.pl',
'bin/radical-utils-mongodb.py',
'bin/radical-utils-version',
'bin/radical-utils-pwatch',
'bin/radical-utils-pylint.sh',
Expand Down
1 change: 1 addition & 0 deletions src/radical/utils/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def get_hostip(req=None, log=None):
req = as_list(req)

white_list = [
'hsn0', # Frontier (HPE Cray EX)
'ipogif0', # Cray's
'br0', # SuperMIC
'eth0', # desktops etc.
Expand Down
117 changes: 0 additions & 117 deletions src/radical/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

from typing import List, Tuple, Union, Any

from urllib.parse import unquote_plus

from . import url as ruu
from .ru_regex import ReString

Expand All @@ -33,121 +31,6 @@
_RU_exit = None


# ------------------------------------------------------------------------------
#
def split_dburl(dburl, default_dburl=None):
'''
we split the url into the base mongodb URL, and the path element, whose
first element is the database name, and the remainder is interpreted as
collection id.
'''

# if the given URL does not contain schema nor host, the default URL is used
# as base, and the given URL string is appended to the path element.

url = ruu.Url(dburl)

if not url.schema and not url.host:
url = ruu.Url(default_dburl)
url.path = dburl

# NOTE: add other data base schemes here...
if 'mongodb' not in url.schema.split('+'):
raise ValueError("expected 'mongodb[+ssl]://' url, not '%s'" % dburl)

host = url.host
port = url.port
path = url.path
user = url.username
pwd = unquote_plus(url.password)

query_options = {'ssl': False}

if 'ssl' in url.schema.split('+'):
query_options['ssl'] = True
url.schema = 'mongodb'

if not host:
host = 'localhost'

if url.query:
from urllib.parse import parse_qsl
# get dict query from url.query (str)
q = dict(parse_qsl(url.query))
# control of which options are transferred
query_options['tlsAllowInvalidCertificates'] = bool(
q.get('tlsAllowInvalidCertificates', '0').lower() in ['true', '1'])

if path.startswith('/'):
path = path[1:]
path_elems = path.split('/')

dbname = None
cname = None
pname = None

if len(path_elems) > 0:
dbname = path_elems[0]

if len(path_elems) > 1:
dbname = path_elems[0]
cname = path_elems[1]

if len(path_elems) > 2:
dbname = path_elems[0]
cname = path_elems[1]
pname = '.'.join(path_elems[2:])

if dbname == '.':
dbname = None

return [host, port, dbname, cname, pname, user, pwd, query_options]


# ------------------------------------------------------------------------------
#
def mongodb_connect(dburl, default_dburl=None):
'''
connect to the given mongodb, perform auth for the database (if a database
was given).
'''

try:
import pymongo

except ImportError as e:
msg = " \n\npymongo is not available -- install RU with: \n\n"
msg += " (1) pip install --upgrade -e '.[pymongo]'\n"
msg += " (2) pip install --upgrade 'radical.utils[pymongo]'\n\n"
msg += "to resolve that dependency (or install pymongo manually).\n"
msg += "The first version will work for local installation, \n"
msg += "the second one for installation from pypi.\n\n"
raise ImportError(msg) from e

[host, port, dbname, cname, pname,
user, pwd, options] = split_dburl(dburl, default_dburl)

mongo = pymongo.MongoClient(host=host, port=port, **options)
db = None

if dbname:
db = mongo[dbname]

if user and pwd:
db.authenticate(user, pwd)

else:

# if no DB is given, we try to auth against all databases.
for dbname in mongo.database_names():
try:
mongo[dbname].authenticate(user, pwd)
except:
pass

return mongo, db, dbname, cname, pname


# ------------------------------------------------------------------------------
#
def parse_file_staging_directives(directives):
Expand Down

0 comments on commit 09642cc

Please sign in to comment.