Skip to content

Commit 4d9aa61

Browse files
author
dakodakov
authored
vdk-test-utils: add vdk sdk secrets api - part 2 (#2320)
Incremental change for adding the secrets capability. Adopt secrets interface in test utils. Actual tests and full implementation will follow in next MR. Signed-off-by: Dako Dakov <ddakov@vmware.com>
1 parent 057725b commit 4d9aa61

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

projects/vdk-plugins/vdk-test-utils/src/vdk/plugin/test_utils/util_funcs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from vdk.internal.core.statestore import StateStore
4242
from vdk.internal.plugin.plugin import PluginRegistry
4343
from vdk.plugin.test_utils.util_plugins import TestPropertiesPlugin
44+
from vdk.plugin.test_utils.util_plugins import TestSecretsPlugin
4445

4546

4647
def cli_assert(
@@ -121,7 +122,7 @@ def __init__(self, *plugins):
121122
:param plugins: the list of plugins that should be loaded during this test run.
122123
"""
123124
self._plugins = plugins
124-
self._default_plugins = [TestPropertiesPlugin()]
125+
self._default_plugins = [TestPropertiesPlugin(), TestSecretsPlugin()]
125126

126127
def clear_default_plugins(self):
127128
self._default_plugins.clear()

projects/vdk-plugins/vdk-test-utils/src/vdk/plugin/test_utils/util_plugins.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from vdk.api.plugin.hook_markers import hookimpl
1414
from vdk.api.plugin.plugin_input import IIngesterPlugin
1515
from vdk.api.plugin.plugin_input import IPropertiesServiceClient
16+
from vdk.api.plugin.plugin_input import ISecretsServiceClient
1617
from vdk.internal.builtin_plugins.connection.decoration_cursor import DecorationCursor
1718
from vdk.internal.builtin_plugins.connection.managed_connection_base import (
1819
ManagedConnectionBase,
@@ -148,6 +149,46 @@ def initialize_job(self, context: JobContext) -> None:
148149
)
149150

150151

152+
class TestSecretsServiceClient(ISecretsServiceClient):
153+
"""Testing secrets client that keeps in memory per job properties."""
154+
155+
def __init__(self):
156+
self._secrets = {}
157+
158+
def read_secrets(self, job_name: str, team_name: str) -> Dict:
159+
res = deepcopy(self._secrets.get(job_name, {}))
160+
return res
161+
162+
def write_secrets(self, job_name: str, team_name: str, secrets: Dict) -> Dict:
163+
self._secrets[job_name] = deepcopy(secrets)
164+
return self._secrets[job_name]
165+
166+
167+
class TestSecretsPlugin:
168+
def __init__(self):
169+
self.secrets_client = TestSecretsServiceClient()
170+
171+
@hookimpl
172+
def initialize_job(self, context: JobContext) -> None:
173+
context.secrets.set_secrets_factory_method(
174+
"default", lambda: self.secrets_client
175+
)
176+
177+
178+
class TestSecretsDecoratedPlugin(ISecretsServiceClient):
179+
def read_secrets(self, job_name: str, team_name: str) -> Dict:
180+
raise NotImplementedError()
181+
182+
def write_secrets(self, job_name: str, team_name: str, secrets: Dict) -> Dict:
183+
return {**secrets, **{"test": "True"}}
184+
185+
@hookimpl
186+
def initialize_job(self, context: JobContext) -> None:
187+
context.secrets.set_secrets_factory_method(
188+
"test-secret-decorated", lambda: self
189+
)
190+
191+
151192
class IngestIntoMemoryPlugin(IIngesterPlugin):
152193
"""
153194
Create a new ingestion mechanism to ingest data into memory

0 commit comments

Comments
 (0)