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 1 commit
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
11 changes: 11 additions & 0 deletions oda_api/secret.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os
volodymyrss marked this conversation as resolved.
Show resolved Hide resolved

def get_secret(secret_name: str) -> str:
volodymyrss marked this conversation as resolved.
Show resolved Hide resolved
# 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()

Check warning on line 11 in oda_api/secret.py

View check run for this annotation

Codecov / codecov/patch

oda_api/secret.py#L7-L11

Added lines #L7 - L11 were not covered by tests
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']

Check warning on line 9 in tests/test_secret.py

View check run for this annotation

Codecov / codecov/patch

tests/test_secret.py#L7-L9

Added lines #L7 - L9 were not covered by tests

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

Check warning on line 16 in tests/test_secret.py

View check run for this annotation

Codecov / codecov/patch

tests/test_secret.py#L12-L16

Added lines #L12 - L16 were not covered by tests
Loading