commit/galaxy-central: 2 new changesets
2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/17bb0bc8b488/ Changeset: 17bb0bc8b488 User: dannon Date: 2015-02-13 14:39:49+00:00 Summary: Cleanup in util. Affected #: 1 file diff -r 63def64e9ed027e48b9ff257d384b8907bc661d5 -r 17bb0bc8b488c7b8bbe9d3c03e72a1fe0abfe6c6 lib/galaxy/util/__init__.py --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -12,7 +12,6 @@ import grp import logging import os -import pickle import random import re import shutil @@ -340,7 +339,7 @@ return value -def pretty_print_time_interval( time = False, precise = False ): +def pretty_print_time_interval( time=False, precise=False ): """ Get a datetime object or a int() Epoch timestamp and return a pretty string like 'an hour ago', 'Yesterday', '3 months ago', @@ -441,6 +440,7 @@ text = smart_str( text ) return _sanitize_text_helper( text, valid_characters=valid_characters, character_map=character_map ) + def _sanitize_text_helper( text, valid_characters=valid_chars, character_map=mapped_chars, invalid_character='X' ): """Restricts the characters that are allowed in a string""" @@ -459,7 +459,10 @@ if isinstance( values, list ): rval = [] for value in values: - rval.append( sanitize_lists_to_string( value, valid_characters=valid_characters, character_map=character_map, invalid_character=invalid_character ) ) + rval.append( sanitize_lists_to_string( value, + valid_characters=valid_characters, + character_map=character_map, + invalid_character=invalid_character ) ) values = ",".join( rval ) else: values = sanitize_text( values, valid_characters=valid_characters, character_map=character_map, invalid_character=invalid_character ) @@ -614,7 +617,12 @@ def __init__( self, params, sanitize=True ): if sanitize: for key, value in params.items(): - if key not in self.NEVER_SANITIZE and True not in [ key.endswith( "|%s" % nonsanitize_parameter ) for nonsanitize_parameter in self.NEVER_SANITIZE ]: # sanitize check both ungrouped and grouped parameters by name. Anything relying on NEVER_SANITIZE should be changed to not require this and NEVER_SANITIZE should be removed. + # sanitize check both ungrouped and grouped parameters by + # name. Anything relying on NEVER_SANITIZE should be + # changed to not require this and NEVER_SANITIZE should be + # removed. + if key not in self.NEVER_SANITIZE and True not in [ key.endswith( "|%s" % nonsanitize_parameter ) for + nonsanitize_parameter in self.NEVER_SANITIZE ]: self.__dict__[ key ] = sanitize_param( value ) else: self.__dict__[ key ] = value @@ -664,7 +672,9 @@ log.warn( str ) return unicodify( docutils.core.publish_string( s, writer=docutils.writers.html4css1.Writer(), - settings_overrides={ "embed_stylesheet": False, "template": os.path.join(os.path.dirname(__file__), "docutils_template.txt"), "warning_stream": FakeStream() } ) ) + settings_overrides={ "embed_stylesheet": False, + "template": os.path.join(os.path.dirname(__file__), "docutils_template.txt"), + "warning_stream": FakeStream() } ) ) def xml_text(root, name=None): @@ -761,7 +771,7 @@ if len(amount) <= sfs: return amount else: - return amount[0:sfs] + '0'*(len(amount) - sfs) + return amount[0:sfs] + '0' * (len(amount) - sfs) def unicodify( value, encoding=DEFAULT_ENCODING, error='replace', default=None ): @@ -912,7 +922,7 @@ except Exception, e: print "ERROR: Unable to read builds file:", e if len(db_names) < 1: - db_names = DBNames( [( db_names.default_value, db_names.default_name )] ) + db_names = DBNames( [( db_names.default_value, db_names.default_name )] ) return db_names @@ -1109,11 +1119,11 @@ size = float( size_match.group(1) ) multiple = size_match.group(2) if multiple.startswith( 't' ): - return int( size * 1024**4 ) + return int( size * 1024 ** 4 ) elif multiple.startswith( 'g' ): - return int( size * 1024**3 ) + return int( size * 1024 ** 3 ) elif multiple.startswith( 'm' ): - return int( size * 1024**2 ) + return int( size * 1024 ** 2 ) elif multiple.startswith( 'k' ): return int( size * 1024 ) elif multiple.startswith( 'b' ): https://bitbucket.org/galaxy/galaxy-central/commits/0f69ba9bccae/ Changeset: 0f69ba9bccae User: dannon Date: 2015-02-13 18:05:24+00:00 Summary: Add utility method for masking passwords from urls. Affected #: 1 file diff -r 17bb0bc8b488c7b8bbe9d3c03e72a1fe0abfe6c6 -r 0f69ba9bccae59f5a8f204573bdd8a4a9749231c lib/galaxy/util/__init__.py --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -21,6 +21,7 @@ import sys import tempfile import threading +import urlparse from galaxy.util import json from datetime import datetime @@ -31,8 +32,6 @@ from hashlib import md5 from itertools import izip -from urlparse import urlparse - from galaxy import eggs eggs.require( 'docutils' ) @@ -501,6 +500,30 @@ return out +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 + + def ready_name_for_url( raw_name ): """ General method to convert a string (i.e. object name) to a URL-ready slug. @@ -856,8 +879,8 @@ def compare_urls( url1, url2, compare_scheme=True, compare_hostname=True, compare_path=True ): - url1 = urlparse( url1 ) - url2 = urlparse( url2 ) + url1 = urlparse.urlparse( url1 ) + url2 = urlparse.urlparse( url2 ) if compare_scheme and url1.scheme and url2.scheme and url1.scheme != url2.scheme: return False if compare_hostname and url1.hostname and url2.hostname and url1.hostname != url2.hostname: Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org