Skip to content

Commit

Permalink
Mirror changes to planemo's stripped down galaxy.util
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Feb 13, 2015
1 parent 07f4f6c commit 23fb81a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions planemo_ext/galaxy/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
except ImportError:
grp = None
import errno
import urlparse
from tempfile import NamedTemporaryFile
from logging import getLogger
log = getLogger(__name__)
Expand Down Expand Up @@ -168,3 +169,27 @@ def listify( item, do_strip=False ):
return item.split( ',' )
else:
return [ item ]


def mask_password_from_url( url ):
"""
Masks out passwords from connection urls like the database connection in galaxy.ini
>>> mask_password_from_url( 'sqlite+postgresql://user:password@localhost/' )
'sqlite+postgresql://user:********@localhost/'
>>> mask_password_from_url( 'amqp://user:amqp@localhost' )
'amqp://user:********@localhost'
>>> mask_password_from_url( 'amqp://localhost')
'amqp://localhost'
"""
split = urlparse.urlsplit(url)
if split.password:
if url.count(split.password) == 1:
url = url.replace(split.password, "********")
else:
# This can manipulate the input other than just masking password,
# so the previous string replace method is preferred when the
# password doesn't appear twice in the url
split._replace(netloc=split.netloc.replace("%s:%s" % (split.username, split.password), '%s:********' % split.username))
url = urlparse.urlunsplit(split)
return url

0 comments on commit 23fb81a

Please sign in to comment.