Skip to content

Commit 96ba36d

Browse files
committed
Version 1.0.0-beta.1 - Almost Stable
### Added - An interface for Fidelius gateway repos and admins to fulfil - A mock implementation of a Fidelius gateway repo and admin that use a simple singleton dict to store (and share) data during runtime - Unittests for the mock implementation - Unittests for the Parameter Store implementation using LocalStack - A Factory class to get different implementation classes - Methods to delete parameters - Config params for the `AwsParamStoreRepo` to use a custom AWS endpoint in order to hook up to stuff like LocalStack for testing and such ### Changed - The API a little bit so we're no longer backwards compatible (hence the major version bump to 1.0.0) - All config params can now be explicitly given to the `AwsParamStoreRepo` in addition to being picked up from environment variables if not supplied
1 parent 4cf941d commit 96ba36d

21 files changed

+829
-204
lines changed

CHANGELOG.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,26 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased] - ?
8+
## [1.0.0-beta.1] - 2024-04-11
99

1010
### Added
1111

1212
- An interface for Fidelius gateway repos and admins to fulfil
13-
- A mock implementation of a Fidelius gateway repo and admin that can read
14-
in mock values from JSON files and mess with them in-memory, for use in
15-
unit-tests of other code that uses Fidelius
13+
- A mock implementation of a Fidelius gateway repo and admin that use a
14+
simple singleton dict to store (and share) data during runtime
15+
- Unittests for the mock implementation
16+
- Unittests for the Parameter Store implementation using LocalStack
17+
- A Factory class to get different implementation classes
18+
- Methods to delete parameters
19+
- Config params for the `AwsParamStoreRepo` to use a custom AWS endpoint in
20+
order to hook up to stuff like LocalStack for testing and such
21+
22+
### Changed
23+
24+
- The API a little bit so we're no longer backwards compatible (hence the
25+
major version bump to 1.0.0)
26+
- All config params can now be explicitly given to the `AwsParamStoreRepo`
27+
in addition to being picked up from environment variables if not supplied
1628

1729

1830
## [0.6.0] - 2024-04-05

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ package in mind but should work for other cases as well.
99
**IMPORTANT:** This has been migrated more-or-less _"as-is"_ from CCP Tool's
1010
internal repo and hasn't yet been given the love it needs to be properly
1111
open-sourced and user friendly for other people _(unless you read though the
12-
code and find it perfectly fits your use case)_.
12+
code and find it perfectly fits your use case)_.
13+
14+
**ALSO IMPORTANT:** This README hasn't been updated to reflect changes in
15+
version 1.0.0 yet. Sowwie! :-/
1316

1417
## What should be stored with Fidelius
1518

fidelius/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '0.7.0-dev.3'
1+
__version__ = '1.0.0-beta.1'
22

33
__author__ = 'Thordur Matthiasson <thordurm@ccpgames.com>'
44
__license__ = 'MIT License'

fidelius/gateway/_abstract.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def make_app_path(self, env: Optional[str] = None) -> str:
4141
"""The full path to application specific parameters/secrets.
4242
"""
4343
return self._APP_PATH_FORMAT.format(group=self.app_props.group,
44-
env=env or self.app_props.env,
45-
app=self.app_props.app,
46-
name='{name}')
44+
env=env or self.app_props.env,
45+
app=self.app_props.app,
46+
name='{name}')
4747

4848
def make_shared_path(self, folder: str, env: Optional[str] = None) -> str:
4949
"""The full path to group shared parameters/secrets.
@@ -117,23 +117,30 @@ def get(self, name: str, folder: Optional[str] = None, no_default: bool = False)
117117
value was found for the current set environment.
118118
:return: The requested parameter/secret or None if it was not found.
119119
"""
120+
log.debug('_BaseFideliusRepo.get(name=%s, folder=%s, no_default=%s))', name, folder, no_default)
120121
if folder:
121122
val = self.get_shared_param(name=name, folder=folder)
123+
log.debug('_BaseFideliusRepo.get->get_shared_param val=%s', val)
122124
if val is not None:
123125
return val
124126

125127
if no_default:
128+
log.debug('_BaseFideliusRepo.get->(shared) no_default STOP!')
126129
return None
127130

131+
log.debug('_BaseFideliusRepo.get->(shared) Lets try the default!!!')
128132
return self.get_shared_param(name=name, folder=folder, env='default')
129133
else:
130134
val = self.get_app_param(name=name)
135+
log.debug('_BaseFideliusRepo.get->get_app_param val=%s', val)
131136
if val is not None:
132137
return val
133138

134139
if no_default:
140+
log.debug('_BaseFideliusRepo.get->(app) no_default STOP!')
135141
return None
136142

143+
log.debug('_BaseFideliusRepo.get->(app) Lets try the default!!!')
137144
return self.get_app_param(name=name, env='default')
138145

139146
def replace(self, string: str, no_default: bool = False) -> str:
@@ -145,25 +152,26 @@ def replace(self, string: str, no_default: bool = False) -> str:
145152
- `${__FID__:PARAM_NAME}` for app params/secrets
146153
- `${__FID__:FOLDER:PARAM_NAME}` for shared params/secrets in the given FOLDER
147154
148-
If the given string does not match a Fidilius expression, then it is
149-
returned unchanged.
155+
An empty string is returned if the parameter was not found and if the
156+
string does not match the expression format, it will be returned
157+
unchanged.
150158
151159
:param string: The expression to replace with an actual parameter/secret
152160
:param no_default: If True, does not try and get the default value if no
153161
value was found for the current set environment.
154-
:return: The requested value
162+
:return: The requested value, an empty string or the original string
155163
"""
156164
m = self._EXPRESSION_PATTERN.match(string)
157165
if m:
158-
return self.get(m.group('name'), m.group('folder'), no_default=no_default)
166+
return self.get(m.group('name'), m.group('folder'), no_default=no_default) or ''
159167
return string
160168

161169

162170
class _BaseFideliusAdminRepo(_BaseFideliusRepo, IFideliusAdminRepo, abc.ABC):
163171
"""Covers a lot of admin basic functionality common across most storage back-ends.
164172
"""
165173
def __init__(self, app_props: FideliusAppProps, tags: Optional[FideliusTags] = None, **kwargs):
166-
log.debug('_BaseFideliusAdminRepo.__init__')
174+
log.debug('_BaseFideliusAdminRepo.__init__ (this should set tags?!?)')
167175
super().__init__(app_props, **kwargs)
168176
self._tags = tags
169177

fidelius/gateway/file/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

fidelius/gateway/file/_filerepo.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

fidelius/gateway/interface.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,14 @@ def replace(self, string: str, no_default: bool = False) -> str:
131131
- `${__FID__:PARAM_NAME}` for app params/secrets
132132
- `${__FID__:FOLDER:PARAM_NAME}` for shared params/secrets in the given FOLDER
133133
134+
An empty string is returned if the parameter was not found and if the
135+
string does not match the expression format, it will be returned
136+
unchanged.
137+
134138
:param string: The expression to replace with an actual parameter/secret
135139
:param no_default: If True, does not try and get the default value if no
136140
value was found for the current set environment.
137-
:return: The requested value
141+
:return: The requested value, an empty string or the original string
138142
"""
139143
pass
140144

@@ -147,7 +151,9 @@ def __init__(self, app_props: FideliusAppProps, tags: Optional[FideliusTags] = N
147151
:param app_props: The application properties to use.
148152
:param tags: An optional set of meta-data tags to use when creating new
149153
parameters (if supported by the underlying
150-
parameter/secret storage).
154+
parameter/secret storage). Note that updating a parameter
155+
does not update/change tags, they are only applied when
156+
creating new parameters!
151157
"""
152158
pass
153159

fidelius/gateway/mock/_inmemcache.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
__all__ = [
2+
'_SingletonDict',
3+
]
4+
5+
from ccptools.structs import *
6+
7+
8+
class _SingletonDict(dict, metaclass=Singleton):
9+
"""Simple Singleton dict :)
10+
11+
It's point is simply to act as a shared centralized store for the mock
12+
stuff, mimicking how multiple instances of Fidelius Repos and/or Admin
13+
Repos would nevertheless fetch data from the same source.
14+
15+
This is just to "mock" the shared parameter/secret stuff.
16+
17+
...sneaky, right?
18+
"""
19+
pass

fidelius/gateway/mock/_mockadmin.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44

55
from fidelius.gateway._abstract import *
66
from fidelius.structs import *
7+
from ._mockrepo import *
78

89
import logging
910
log = logging.getLogger(__name__)
1011

1112

12-
class MockFideliusAdmin(_BaseFideliusAdminRepo):
13+
class MockFideliusAdmin(_BaseFideliusAdminRepo, MockFideliusRepo):
1314
def __init__(self, app_props: FideliusAppProps, tags: Optional[FideliusTags] = None, **kwargs):
1415
"""This mock version of the Fidelius Admin stores created and updated
15-
params in memory only.
16+
params in memory only (although the cache is a singleton so multiple
17+
instances of both admin and repo will be useing the same dict/data.
1618
1719
Note that it does NOT extend the functionality of its non-Admin sibling,
1820
the MockFideliusRepo and thus does not return a base64 encoded version
@@ -25,13 +27,6 @@ def __init__(self, app_props: FideliusAppProps, tags: Optional[FideliusTags] = N
2527
"""
2628
log.debug('MockFideliusAdmin.__init__')
2729
super().__init__(app_props, tags, **kwargs)
28-
self._cache = {}
29-
30-
def get_app_param(self, name: str, env: Optional[str] = None) -> Optional[str]:
31-
return self._cache.get(self.get_full_path(name, env=env), None)
32-
33-
def get_shared_param(self, name: str, folder: str, env: Optional[str] = None) -> Optional[str]:
34-
return self._cache.get(self.get_full_path(name, folder, env=env), None)
3530

3631
def _create(self, name: str, value: str, env: Optional[str] = None, folder: Optional[str] = None) -> (str, str):
3732
key = self.get_full_path(name, folder=folder, env=env)

fidelius/gateway/mock/_mockrepo.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from fidelius.structs import *
66
from fidelius.gateway._abstract import *
7+
from ._inmemcache import _SingletonDict
78

89
import base64
910

@@ -21,9 +22,10 @@ def __init__(self, app_props: FideliusAppProps, **kwargs):
2122
"""
2223
log.debug('MockFideliusRepo.__init__')
2324
super().__init__(app_props, **kwargs)
25+
self._cache: _SingletonDict[str, str] = _SingletonDict()
2426

2527
def get_app_param(self, name: str, env: Optional[str] = None) -> Optional[str]:
26-
return base64.encodebytes(self.get_full_path(name, env=env).encode('utf-8')).decode('utf-8').strip()
28+
return self._cache.get(self.get_full_path(name, env=env), None)
2729

2830
def get_shared_param(self, name: str, folder: str, env: Optional[str] = None) -> Optional[str]:
29-
return base64.encodebytes(self.get_full_path(name, folder=folder, env=env).encode('utf-8')).decode('utf-8').strip()
31+
return self._cache.get(self.get_full_path(name, folder, env=env), None)

0 commit comments

Comments
 (0)