Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secret access API added based on renku secrets implementation #271

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions oda_api/secret.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Optional
import os
volodymyrss marked this conversation as resolved.
Show resolved Hide resolved

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

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()
16 changes: 16 additions & 0 deletions tests/test_secret.py
Original file line number Diff line number Diff line change
@@ -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
Loading