-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
220 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = '0.7.0-dev.2' | ||
__version__ = '0.7.0-dev.3' | ||
|
||
__author__ = 'Thordur Matthiasson <[email protected]>' | ||
__license__ = 'MIT License' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
from fidelius.structs.api import * | ||
from fidelius.utils import * | ||
|
||
from fidelius.gateway.paramstore import * | ||
from fidelius.gateway.interface import * | ||
from fidelius.gateway import FideliusFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
__all__ = [ | ||
'FideliusFactory', | ||
] | ||
|
||
from fidelius.structs import * | ||
from .interface import * | ||
from ccptools.tpu import strimp | ||
|
||
import logging | ||
log = logging.getLogger(__name__) | ||
|
||
|
||
class FideliusFactory: | ||
@staticmethod | ||
def get_class(impl: str = 'paramstore') -> Type[IFideliusRepo]: | ||
return strimp.get_class(f'fidelius.gateway.{impl}._std.FideliusRepo', logger=log, reraise=True) | ||
|
||
@staticmethod | ||
def get_admin_class(impl: str = 'paramstore') -> Type[IFideliusAdminRepo]: | ||
return strimp.get_class(f'fidelius.gateway.{impl}._std.FideliusAdmin', logger=log, reraise=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
__all__ = [ | ||
'MockFideliusAdmin', | ||
] | ||
|
||
from fidelius.gateway._abstract import * | ||
from fidelius.structs import * | ||
|
||
import logging | ||
log = logging.getLogger(__name__) | ||
|
||
|
||
class MockFideliusAdmin(_BaseFideliusAdminRepo): | ||
def __init__(self, app_props: FideliusAppProps, tags: Optional[FideliusTags] = None, **kwargs): | ||
"""This mock version of the Fidelius Admin stores created and updated | ||
params in memory only. | ||
Note that it does NOT extend the functionality of its non-Admin sibling, | ||
the MockFideliusRepo and thus does not return a base64 encoded version | ||
of every requested param/secret key name, but instead only uses its own | ||
internal in-memory cache, and thus, `get` will not return anything that | ||
hasn't been created first during that particular runtime. | ||
This is mainly intended for unit testing other packages and apps that | ||
use Fidelius. | ||
""" | ||
log.debug('MockFideliusAdmin.__init__') | ||
super().__init__(app_props, tags, **kwargs) | ||
self._cache = {} | ||
|
||
def get_app_param(self, name: str, env: Optional[str] = None) -> Optional[str]: | ||
return self._cache.get(self.get_full_path(name, env=env), None) | ||
|
||
def get_shared_param(self, name: str, folder: str, env: Optional[str] = None) -> Optional[str]: | ||
return self._cache.get(self.get_full_path(name, folder, env=env), None) | ||
|
||
def _create(self, name: str, value: str, env: Optional[str] = None, folder: Optional[str] = None) -> (str, str): | ||
key = self.get_full_path(name, folder=folder, env=env) | ||
if key in self._cache: | ||
raise FideliusParameterAlreadyExists(f'parameter already exists: {key}') | ||
self._cache[key] = value | ||
return key, self.get_expression_string(name, folder=folder) | ||
|
||
def _update(self, name: str, value: str, env: Optional[str] = None, folder: Optional[str] = None) -> (str, str): | ||
key = self.get_full_path(name, folder=folder, env=env) | ||
if key not in self._cache: | ||
raise FideliusParameterNotFound(f'parameter not found: {key}') | ||
self._cache[key] = value | ||
return key, self.get_expression_string(name, folder=folder) | ||
|
||
def _delete(self, name: str, env: Optional[str] = None, folder: Optional[str] = None): | ||
key = self.get_full_path(name, folder=folder, env=env) | ||
if key not in self._cache: | ||
raise FideliusParameterNotFound(f'parameter not found: {key}') | ||
del self._cache[key] | ||
|
||
def create_param(self, name: str, value: str, | ||
description: Optional[str] = None, env: Optional[str] = None) -> (str, str): | ||
return self._create(name, value=value, env=env) | ||
|
||
def update_param(self, name: str, value: str, | ||
description: Optional[str] = None, env: Optional[str] = None) -> (str, str): | ||
return self._update(name, value=value, env=env) | ||
|
||
def delete_param(self, name: str, env: Optional[str] = None): | ||
self._delete(name, env=env) | ||
|
||
def create_shared_param(self, name: str, folder: str, value: str, | ||
description: Optional[str] = None, | ||
env: Optional[str] = None) -> (str, str): | ||
return self._create(name, value=value, env=env, folder=folder) | ||
|
||
def update_shared_param(self, name: str, folder: str, value: str, | ||
description: Optional[str] = None, | ||
env: Optional[str] = None) -> (str, str): | ||
return self._update(name, value=value, env=env, folder=folder) | ||
|
||
def delete_shared_param(self, name: str, folder: str, env: Optional[str] = None): | ||
self._delete(name, env=env, folder=folder) | ||
|
||
def create_secret(self, name: str, value: str, | ||
description: Optional[str] = None, env: Optional[str] = None) -> (str, str): | ||
return self._create(name, value=value, env=env) | ||
|
||
def update_secret(self, name: str, value: str, | ||
description: Optional[str] = None, env: Optional[str] = None) -> (str, str): | ||
return self._update(name, value=value, env=env) | ||
|
||
def delete_secret(self, name: str, env: Optional[str] = None): | ||
self._delete(name, env=env) | ||
|
||
def create_shared_secret(self, name: str, folder: str, value: str, | ||
description: Optional[str] = None, env: Optional[str] = None) -> (str, str): | ||
return self._create(name, value=value, env=env, folder=folder) | ||
|
||
def update_shared_secret(self, name: str, folder: str, value: str, | ||
description: Optional[str] = None, env: Optional[str] = None) -> (str, str): | ||
return self._update(name, value=value, env=env, folder=folder) | ||
|
||
def delete_shared_secret(self, name: str, folder: str, env: Optional[str] = None): | ||
self._delete(name, env=env, folder=folder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"""Here we import this modules implementation classes with generic names for the | ||
Factory to use""" | ||
from ._mockrepo import MockFideliusRepo as FideliusRepo | ||
from ._mockadmin import MockFideliusAdmin as FideliusAdmin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from ._paramstorerepo import |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
__all__ = [ | ||
'FideliusAppProps', | ||
] | ||
from ccptools.structs import * | ||
import dataclasses | ||
|
||
|
||
@dataclasses.dataclass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
__all__ = [ | ||
'FideliusError', | ||
'FideliusAdminError', | ||
'FideliusParameterNotFound', | ||
'FideliusParameterAlreadyExists', | ||
] | ||
|
||
|
||
class FideliusError(Exception): | ||
pass | ||
|
||
|
||
class FideliusAdminError(FideliusError): | ||
pass | ||
|
||
|
||
class FideliusParameterNotFound(FideliusAdminError, KeyError): | ||
pass | ||
|
||
|
||
class FideliusParameterAlreadyExists(FideliusAdminError, ValueError): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from ._tags import * | ||
from ._appprops import * | ||
from ._errors import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import unittest | ||
|
||
from fidelius.fideliusapi import * | ||
|
||
_app_props = FideliusAppProps(app='mock-app', group='somegroup', env='mock') | ||
|
||
|
||
class TestMock(unittest.TestCase): | ||
def test_mock(self): | ||
fid = FideliusFactory.get_class('mock')(_app_props) | ||
self.assertEqual('L2ZpZGVsaXVzL3NvbWVncm91cC9tb2NrL2FwcHMvbW9jay1hcHAvbW9jay12YWx1ZQ==', fid.get('mock-value')) | ||
self.assertEqual('L2ZpZGVsaXVzL3NvbWVncm91cC9tb2NrL2FwcHMvbW9jay1hcHAvREJfUEFTU1dPUkQ=', fid.get('DB_PASSWORD')) | ||
self.assertEqual('L2ZpZGVsaXVzL3NvbWVncm91cC9tb2NrL3NoYXJlZC9zaGFyZWRwb3N0Z3Jlcy9EQl9IT1NU', fid.get('DB_HOST', 'sharedpostgres')) | ||
|
||
def test_mock_admin(self): | ||
fia = FideliusFactory.get_admin_class('mock')(_app_props) | ||
self.assertIsNone(fia.get('DB_PASSWORD')) | ||
|
||
with self.assertRaises(FideliusParameterNotFound): | ||
fia.delete_param('DB_PASSWORD') | ||
|
||
with self.assertRaises(FideliusParameterNotFound): | ||
fia.update_param('DB_PASSWORD', 'myBADpassword') | ||
|
||
key, expression = fia.create_param('DB_PASSWORD', 'myBADpassword') | ||
|