Skip to content

Commit

Permalink
db_connect_method -> exports_from (Breaking) (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceatbluelabs authored May 11, 2020
1 parent 03acb63 commit 95fea68
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
db_facts-3.8.1
db_facts-3.8.2
24 changes: 12 additions & 12 deletions db_facts/db_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def db(db_name: DBName, dbcli_config: DBCLIConfig = None) -> DBFacts:
if config is None:
fail_on_invalid_db_name(db_name)

db_connect_method = config.get('db_connect_method')
exports_from = config.get('exports_from')
db_info: DBConfig = {
'exports': {
'connection_type': 'direct',
}
}
if db_connect_method is not None:
db_info['db_connect_method'] = db_connect_method
if exports_from is not None:
db_info['exports_from'] = exports_from

jinja_context = pull_jinja_context(db_name, config, dbcli_config)
for k in config.keys():
Expand All @@ -41,32 +41,32 @@ def db(db_name: DBName, dbcli_config: DBCLIConfig = None) -> DBFacts:
else:
db_info[k] = template(config[k], jinja_context)

if 'db_connect_method' in db_info:
method = db_info.get('db_connect_method')
if 'exports_from' in db_info:
method = db_info.get('exports_from')
if method is None:
# nothing to do here - all the info we need is already in
# dbcli.yml, either fixed or interpolated through the
# jinja context
pass
if 'json_script' in dbcli_config['db_connect_method'][method]:
if 'json_script' in dbcli_config['exports_from'][method]:
json_call_args = \
dbcli_config['db_connect_method'][method]['json_script']
dbcli_config['exports_from'][method]['json_script']
json_call =\
[template(s, (db_info, {})) for s in json_call_args]
json_str = subprocess.check_output(json_call).decode('utf-8')
additional_attributes = json.loads(json_str)
db_info['exports'].update(additional_attributes)
elif 'pull_lastpass_from' in dbcli_config['db_connect_method'][method]:
elif 'pull_lastpass_from' in dbcli_config['exports_from'][method]:
template_for_lastpass_entry_name =\
dbcli_config['db_connect_method'][method]['pull_lastpass_from']
dbcli_config['exports_from'][method]['pull_lastpass_from']
lastpass_entry_name = template(template_for_lastpass_entry_name,
(db_info, {}))
additional_attributes = \
db_info_from_lpass(lastpass_entry_name)
db_info['exports'].update(additional_attributes)
elif 'pull_lastpass_username_password_from' in \
dbcli_config['db_connect_method'][method]:
method = dbcli_config['db_connect_method'][method]
dbcli_config['exports_from'][method]:
method = dbcli_config['exports_from'][method]
template_for_lastpass_entry_name =\
method['pull_lastpass_username_password_from']
lastpass_entry_name = template(template_for_lastpass_entry_name,
Expand All @@ -75,6 +75,6 @@ def db(db_name: DBName, dbcli_config: DBCLIConfig = None) -> DBFacts:
pull_lastpass_username_password(lastpass_entry_name)
db_info['exports'].update(additional_attributes)
else:
raise SyntaxError(f'Did not understand db_connect_method {method}')
raise SyntaxError(f'Did not understand exports_from {method}')

return db_info['exports']
2 changes: 1 addition & 1 deletion deps.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e

python_version=3.8.1
python_version=3.8.2
# zipimport.ZipImportError: can't decompress data; zlib not available:
# You may need `xcode-select --install` on OS X
# https://github.com/pyenv/pyenv/issues/451#issuecomment-151336786
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys


VERSION = '3.0.2'
VERSION = '4.0.0'


# From https://circleci.com/blog/continuously-deploying-python-packages-to-pypi-with-circleci/
Expand Down
14 changes: 7 additions & 7 deletions tests/mock_dbcli_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mock_dbcli_config = {
'db_connect_method': {
'exports_from': {
'lpass': {
'pull_lastpass_from': "{{ lastpass_entry }}",
},
Expand All @@ -16,25 +16,25 @@
},
'dbs': {
'baz': {
'db_connect_method': 'my-json-script',
'exports_from': 'my-json-script',
},
'bing': {
'db_connect_method': 'invalid-method',
'exports_from': 'invalid-method',
},
'bazzle': {
'db_connect_method': 'lpass',
'exports_from': 'lpass',
'lastpass_entry': 'lpass entry name'
},
'bazzle-bing': {
'db_connect_method': 'lpass',
'exports_from': 'lpass',
'lastpass_entry': 'different lpass entry name'
},
'frazzle': {
'db_connect_method': 'lpass',
'exports_from': 'lpass',
'lastpass_entry': 'lpass entry name'
},
'frink': {
'db_connect_method': 'lpass_user_and_pass_only',
'exports_from': 'lpass_user_and_pass_only',
'lastpass_entry': 'lpass entry name',
'jinja_context_name': 'standard',
'exports': {
Expand Down
6 changes: 3 additions & 3 deletions tests/test_db_info_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def test_db_info_bad_db(self,
with self.assertRaises(UserErrorException):
db(['not-there'], dbcli_config=mock_dbcli_config)

def test_db_info_invalid_db_connect_method(self,
mock_subprocess,
mock_pull_jinja_context):
def test_db_info_invalid_exports_from(self,
mock_subprocess,
mock_pull_jinja_context):
mock_pull_jinja_context.return_value = ({}, {})
with self.assertRaises(SyntaxError):
db(['bing'], dbcli_config=mock_dbcli_config)

0 comments on commit 95fea68

Please sign in to comment.