Skip to content

Commit

Permalink
Merge pull request #270 from 4dn-dcic/kmp_smaht_creds_utils
Browse files Browse the repository at this point in the history
Add support for creds_utils.SMaHTKeyManager
  • Loading branch information
netsettler authored Jul 18, 2023
2 parents a91957f + 6007e85 commit 711e0a9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions dcicutils/creds_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,8 @@ class CGAPKeyManager(KeyManager):
@KeyManager.register(name='fourfront')
class FourfrontKeyManager(KeyManager):
pass


@KeyManager.register(name='smaht')
class SMaHTKeyManager(KeyManager):
pass
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <support@4dnucleome.org>"]
license = "MIT"
Expand Down
41 changes: 40 additions & 1 deletion test/test_creds_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 711e0a9

Please sign in to comment.