Skip to content

Commit

Permalink
bugfix: username not handledcorrectly in prometheus app
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianneubauer committed Sep 18, 2017
1 parent 0266bdd commit 6abb8bb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
15 changes: 10 additions & 5 deletions postgraas_server/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ def get_application_config(config):


def get_meta_db_config_path(config):
try:
server = config.get('metadb', 'server')
username = '@'.join([config.get('metadb', 'db_username'), server])
except ConfigParser.NoOptionError:
username = config.get('metadb', 'db_username')
username = get_user(config)

db_path = 'postgresql://{db_username}:{db_pwd}@{host}:{port}/{db_name}'.format(
db_name=config.get('metadb', 'db_name'),
Expand All @@ -71,3 +67,12 @@ def get_meta_db_config_path(config):
port=config.get('metadb', 'port')
)
return db_path


def get_user(config):
try:
server = config.get('metadb', 'server')
username = '@'.join([config.get('metadb', 'db_username'), server])
except ConfigParser.NoOptionError:
username = config.get('metadb', 'db_username')
return username
27 changes: 26 additions & 1 deletion tests/test_unit/test_configuration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

import ConfigParser
import StringIO
from cryptography.fernet import Fernet

import postgraas_server.configuration as cf
Expand All @@ -19,6 +20,30 @@ def test_get_config(self):
expected = 'postgraas'
assert actual.get('metadb', 'db_name') == expected

def test_get_user(self):
config_string = '''
[metadb]
db_username = postgraas_user
'''
config = ConfigParser.ConfigParser()

config.readfp(StringIO.StringIO(config_string))
username = cf.get_user(config)
expected = 'postgraas_user'
assert username == expected

config_string = '''
[metadb]
server = testserver1
db_username = postgraas_user
'''
config = ConfigParser.ConfigParser()

config.readfp(StringIO.StringIO(config_string))
username = cf.get_user(config)
expected = 'postgraas_user@testserver1'
assert username == expected

def test_secrets(self, tmpdir):
secrets_file = tmpdir.join('secrets')
key = Fernet.generate_key()
Expand Down

0 comments on commit 6abb8bb

Please sign in to comment.