From 6007e8561bfb0623626857a84e43c6dbdeea1dd5 Mon Sep 17 00:00:00 2001 From: Kent Pitman Date: Mon, 17 Jul 2023 17:37:13 -0400 Subject: [PATCH] Add support for creds_utils.SMaHTKeyManager. --- CHANGELOG.rst | 10 +++++++++- dcicutils/creds_utils.py | 5 +++++ pyproject.toml | 2 +- test/test_creds_utils.py | 41 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index be935a7ee..e38c58721 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,10 +6,18 @@ dcicutils Change Log ---------- +7.6.0 +===== + +* In ``creds_utils``: + + * Support for ``SMaHTKeyManager`` + + 7.5.3 ===== -* EnvUtils updates to accommodate `smaht-portal` +* EnvUtils updates to accommodate ``smaht-portal`` 7.5.2 diff --git a/dcicutils/creds_utils.py b/dcicutils/creds_utils.py index de72c200d..28d1cff82 100644 --- a/dcicutils/creds_utils.py +++ b/dcicutils/creds_utils.py @@ -290,3 +290,8 @@ class CGAPKeyManager(KeyManager): @KeyManager.register(name='fourfront') class FourfrontKeyManager(KeyManager): pass + + +@KeyManager.register(name='smaht') +class SMaHTKeyManager(KeyManager): + pass diff --git a/pyproject.toml b/pyproject.toml index 838c2039e..86c3d916e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dcicutils" -version = "7.5.3" +version = "7.6.0" description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources" authors = ["4DN-DCIC Team "] license = "MIT" diff --git a/test/test_creds_utils.py b/test/test_creds_utils.py index feb3e9723..c88e64280 100644 --- a/test/test_creds_utils.py +++ b/test/test_creds_utils.py @@ -3,7 +3,7 @@ import os import pytest -from dcicutils.creds_utils import KeyManager, CGAPKeyManager, FourfrontKeyManager +from dcicutils.creds_utils import KeyManager, CGAPKeyManager, FourfrontKeyManager, SMaHTKeyManager from dcicutils.exceptions import AppEnvKeyMissing, AppServerKeyMissing # , AppKeyMissing from dcicutils.misc_utils import override_environ from dcicutils.qa_utils import MockFileSystem @@ -23,6 +23,13 @@ SAMPLE_FOURFRONT_LOCAL_SERVER = "http://localhost:8002" SAMPLE_FOURFRONT_LOCAL_PSEUDOENV = 'fourfront-local' +SAMPLE_SMAHT_DEFAULT_ENV = 'smaht-sample' +SAMPLE_SMAHT_KEYS_FILE = 'smaht.keys' +SAMPLE_SMAHT_PRODUCTION_ENV = 'smaht-production' +SAMPLE_SMAHT_PRODUCTION_SERVER = 'https://smaht-prod.hms.harvard.edu' +SAMPLE_SMAHT_LOCAL_SERVER = "http://localhost:8001" +SAMPLE_SMAHT_LOCAL_PSEUDOENV = 'smaht-local' + def _make_sample_cgap_key_manager(): return CGAPKeyManager(keys_file=SAMPLE_CGAP_KEYS_FILE) @@ -32,6 +39,10 @@ def _make_sample_fourfront_key_manager(): return FourfrontKeyManager(keys_file=SAMPLE_FOURFRONT_KEYS_FILE) +def _make_sample_smaht_key_manager(): + return CGAPKeyManager(keys_file=SAMPLE_SMAHT_KEYS_FILE) + + def test_cgap_keymanager_creation(): sample_cgap_key_manager_1 = CGAPKeyManager() @@ -88,6 +99,34 @@ class MyFourfrontKeyManager(FourfrontKeyManager): assert sample_ff_key_manager_4.keys_file == other_keys_file +def test_smaht_keymanager_creation(): + + sample_smaht_key_manager_1 = SMaHTKeyManager() + + assert sample_smaht_key_manager_1.keys_file == SMaHTKeyManager._default_keys_file() + + sample_smaht_key_manager_2 = _make_sample_smaht_key_manager() + + assert sample_smaht_key_manager_2.keys_file == SAMPLE_SMAHT_KEYS_FILE + + with override_environ(SMAHT_KEYS_FILE=SAMPLE_SMAHT_KEYS_FILE): + + sample_smaht_key_manager_3 = SMaHTKeyManager() + + assert sample_smaht_key_manager_3.keys_file == SAMPLE_SMAHT_KEYS_FILE + # Make sure class default is different than test value. More of a test-integrity test than an absolute need. + assert sample_smaht_key_manager_3.keys_file != SMaHTKeyManager._default_keys_file() + + other_keys_file = "other-smaht-keys.json" + + class MySMaHTKeyManager(SMaHTKeyManager): + KEYS_FILE = other_keys_file + + sample_smaht_key_manager_4 = MySMaHTKeyManager() # Tests that no error is raised + + assert sample_smaht_key_manager_4.keys_file == other_keys_file + + def test_keymanager_keys_file(): key_manager = _make_sample_cgap_key_manager()