update to get_secrets_key (#1755)

* raise exception when get_secrets fails, get db_uri and set as a default_dataset_config var

* log as info not an error
This commit is contained in:
Madison Dunitz
2020-08-14 18:17:21 -05:00
committed by GitHub
parent 263e893b30
commit b034055c35
4 changed files with 43 additions and 14 deletions
+13 -7
View File
@@ -112,19 +112,25 @@ class AppConfigTest(unittest.TestCase):
def test_get_config_vars_from_aws_secrets(self, mock_get_secret_key):
mock_get_secret_key.return_value = {
"flask_secret_key": "mock_flask_secret",
"oauth_client_secret": "mock_oauth_secret"
"oauth_client_secret": "mock_oauth_secret",
"db_uri": "mock_db_uri"
}
config = AppConfig()
with self.assertLogs(level="ERROR") as logger:
with self.assertLogs(level="INFO") as logger:
from server.common.aws_secret_utils import handle_config_from_secret
# should not throw error
# "AttributeError: 'ServerConfig' object has no attribute 'user_annotations__hosted_tiledb_array__db_uri'"
# "AttributeError: 'XConfig' object has no attribute 'x'"
handle_config_from_secret(config)
# should throw 2 errors (one for each var set from a secret)
self.assertEqual(len(logger.output), 2)
self.assertIn('ERROR:root:set app__flask_secret_key from secret', logger.output[0])
self.assertIn('ERROR:root:set authentication__params_oauth__client_secret from secret', logger.output[1])
# should log 3 lines (one for each var set from a secret)
self.assertEqual(len(logger.output), 3)
self.assertIn('INFO:root:set app__flask_secret_key from secret', logger.output[0])
self.assertIn('INFO:root:set authentication__params_oauth__client_secret from secret', logger.output[1])
self.assertIn('INFO:root:set user_annotations__hosted_tiledb_array__db_uri from secret', logger.output[2])
self.assertEqual(config.server_config.app__flask_secret_key, "mock_flask_secret")
self.assertEqual(config.server_config.authentication__params_oauth__client_secret, "mock_oauth_secret")
self.assertEqual(config.default_dataset_config.user_annotations__hosted_tiledb_array__db_uri, "mock_db_uri")