From 86ee6a3909e1ea12f2ae1e75166f6681bff02e3d Mon Sep 17 00:00:00 2001 From: Oleg Kalashev Date: Fri, 2 Aug 2024 06:54:03 +0200 Subject: [PATCH 1/3] secret access API added based on renku secrets implementation --- oda_api/secret.py | 11 +++++++++++ tests/test_secret.py | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 oda_api/secret.py create mode 100644 tests/test_secret.py diff --git a/oda_api/secret.py b/oda_api/secret.py new file mode 100644 index 00000000..5f02af3e --- /dev/null +++ b/oda_api/secret.py @@ -0,0 +1,11 @@ +import os + +def get_secret(secret_name: str) -> str: + # Get secret by name + # For now only default renku file secret storage is supported whuch stores secrets as plain text + + secrets_dir = os.getenv('ODA_SECRET_STORAGE', '/secrets') # check for default secret location in renku platform + secrets_file = os.path.join(secrets_dir, secret_name) + if os.path.isfile(secrets_file): + with open(secrets_file, 'r') as f: + return f.read() diff --git a/tests/test_secret.py b/tests/test_secret.py new file mode 100644 index 00000000..4c65fa05 --- /dev/null +++ b/tests/test_secret.py @@ -0,0 +1,16 @@ +import os +import pytest +from oda_api.secret import get_secret + +@pytest.fixture +def secrets_path(tmp_path): + os.environ['ODA_SECRET_STORAGE'] = str(tmp_path) + yield tmp_path + del os.environ['ODA_SECRET_STORAGE'] + +def test_renku_secret(secrets_path): + secret = 'secret' + secret_name = 's' + with open(secrets_path / secret_name, 'w') as f: + f.write(secret) + assert get_secret(secret_name) == secret From c64a6b72cb6ec37b4bf6b6e7da9739549b90e1d9 Mon Sep 17 00:00:00 2001 From: Volodymyr Date: Wed, 4 Sep 2024 11:28:32 +0200 Subject: [PATCH 2/3] Update oda_api/secret.py Co-authored-by: Denys Savchenko <56398430+dsavchenko@users.noreply.github.com> --- oda_api/secret.py | 1 + 1 file changed, 1 insertion(+) diff --git a/oda_api/secret.py b/oda_api/secret.py index 5f02af3e..8503d8ab 100644 --- a/oda_api/secret.py +++ b/oda_api/secret.py @@ -1,3 +1,4 @@ +from typing import Optional import os def get_secret(secret_name: str) -> str: From ee6cd92c4cb46a0b56590345229499a764ecfd80 Mon Sep 17 00:00:00 2001 From: Volodymyr Date: Wed, 4 Sep 2024 11:30:40 +0200 Subject: [PATCH 3/3] Update oda_api/secret.py Co-authored-by: Denys Savchenko <56398430+dsavchenko@users.noreply.github.com> --- oda_api/secret.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oda_api/secret.py b/oda_api/secret.py index 8503d8ab..374d736e 100644 --- a/oda_api/secret.py +++ b/oda_api/secret.py @@ -1,7 +1,7 @@ from typing import Optional import os -def get_secret(secret_name: str) -> str: +def get_secret(secret_name: str) -> Optional[str]: # Get secret by name # For now only default renku file secret storage is supported whuch stores secrets as plain text