Skip to content

Commit

Permalink
Hide username/password in indexer __str__ representation
Browse files Browse the repository at this point in the history
Closes #980

(cherry picked from commit ca28902)
  • Loading branch information
sileht authored and mergify[bot] committed Oct 5, 2018
1 parent 3ae763f commit 17f1d51
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion gnocchi/indexer/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
except ImportError:
pymysql = None
import six
from six.moves.urllib import parse as urlparse
import sqlalchemy
from sqlalchemy.engine import url as sqlalchemy_url
import sqlalchemy.exc
Expand Down Expand Up @@ -291,7 +292,16 @@ def __init__(self, conf):
self.facade = PerInstanceFacade(conf)

def __str__(self):
return "%s: %s" % (self.__class__.__name__, self.conf.indexer.url)
parsed = urlparse.urlparse(self.conf.indexer.url)
url = urlparse.urlunparse((
parsed.scheme,
"***:***@%s%s" % (parsed.hostname,
":%s" % parsed.port if parsed.port else ""),
parsed.path,
parsed.params,
parsed.query,
parsed.fragment))
return "%s: %s" % (self.__class__.__name__, url)

def disconnect(self):
self.facade.dispose()
Expand Down
6 changes: 5 additions & 1 deletion gnocchi/tests/test_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ class TestIndexerDriver(tests_base.TestCase):

def test_str(self):
self.assertEqual("%s: %s" % (self.index.__class__.__name__,
self.conf.indexer.url), str(self.index))
self.conf.indexer.url.replace(
"root@", "").replace(
"localhost", "***:***@localhost"
)),
str(self.index))

def test_create_archive_policy_already_exists(self):
# NOTE(jd) This archive policy
Expand Down

0 comments on commit 17f1d51

Please sign in to comment.