Skip to content

Commit

Permalink
Merge pull request #60 from noverde/feat/rename-secrets-module
Browse files Browse the repository at this point in the history
Rename secrets module
  • Loading branch information
flaviacastro authored Apr 1, 2022
2 parents 7f763db + 0dca40d commit b840f60
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
coverage==6.2
black==21.7b0
black==22.3.0
flake8==4.0.1

boto3==1.20.26
Expand Down
5 changes: 2 additions & 3 deletions serpens/envvars.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import shlex

from serpens import parameters
from serpens import secrets
from serpens import parameters, secrets_manager


def get(key, default=None):
Expand All @@ -19,7 +18,7 @@ def get(key, default=None):
tmp = result.split("://")[1].split("?")
secret_name = tmp[0]
secret_key = tmp[1] if len(tmp) > 1 else None
return secrets.get(secret_name, secret_key)
return secrets_manager.get(secret_name, secret_key)

return result

Expand Down
2 changes: 1 addition & 1 deletion serpens/secrets.py → serpens/secrets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from serpens.cache import cached


@cached("secrets", 900)
@cached("secrets_manager", 900)
def get(secret_id, keyname=None):
client = boto3.client("secretsmanager")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_envvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_get_parameter(self, mock_params):
os.environ["FOO"] = "parameters:///stored_parameter"
self.assertEqual(envvars.get("FOO"), "stored_value")

@patch("envvars.secrets.get")
@patch("envvars.secrets_manager.get")
def test_get_secrets(self, mock_secrets):
mock_secrets.return_value = "stored_value"

Expand Down
17 changes: 9 additions & 8 deletions tests/test_secrets.py → tests/test_secrets_manager.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import json
import secrets
import unittest
from unittest.mock import patch

import secrets_manager

class TestSecrets(unittest.TestCase):
@patch("secrets.boto3")

class TestSecretsManager(unittest.TestCase):
@patch("secrets_manager.boto3")
def test_retrieve_secret_value_without_keyname(self, m_boto3):
aws_response = {"SecretString": '{"key": "s3CrE7-V@1u3"}'}
m_boto3.client.return_value.get_secret_value.return_value = aws_response

secret_value = secrets.get("Secret_Value")
secret_value = secrets_manager.get("Secret_Value")

self.assertDictEqual(secret_value, json.loads(aws_response["SecretString"]))
self.assertEqual(m_boto3.client.call_count, 1)

@patch("secrets.boto3")
@patch("secrets_manager.boto3")
def test_retrieve_secret_value_with_invalid_json(self, m_boto3):
aws_response = {"SecretString": "s3CrE7-V@1u3"}
m_boto3.client.return_value.get_secret_value.return_value = aws_response

secret_value = secrets.get("Another_Secret_Value")
secret_value = secrets_manager.get("Another_Secret_Value")

self.assertEqual(secret_value, aws_response["SecretString"])
self.assertEqual(m_boto3.client.call_count, 1)

@patch("secrets.boto3")
@patch("secrets_manager.boto3")
def test_retrieve_secret_value_with_keyname(self, m_boto3):
aws_response = {"SecretString": '{"key": "s3CrE7-V@1u3"}'}
m_boto3.client.return_value.get_secret_value.return_value = aws_response

secret_value = secrets.get("Another_Secret_Value", "key")
secret_value = secrets_manager.get("Another_Secret_Value", "key")

self.assertEqual(secret_value, json.loads(aws_response["SecretString"])["key"])
self.assertEqual(m_boto3.client.call_count, 1)

0 comments on commit b840f60

Please sign in to comment.