mirror of
https://github.com/famedly/ansible-collection-base
synced 2024-11-10 06:24:17 +00:00
chore(gpg_secretstore): assert existence of user supplied secret
This commit is contained in:
parent
1bd01fc376
commit
265036be47
2 changed files with 13 additions and 0 deletions
|
@ -245,6 +245,10 @@ def check_module_import_errors():
|
|||
return errors
|
||||
|
||||
|
||||
class UserSuppliedSecretMissingError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class SecretGenerator:
|
||||
ALLOWED_SECRET_TYPES = ["random", "binary", "user_supplied"]
|
||||
|
||||
|
@ -294,6 +298,10 @@ class SecretGenerator:
|
|||
|
||||
@staticmethod
|
||||
def __userSuppliedSecret(user_supplied_secret: str, **kwargs):
|
||||
if user_supplied_secret is None:
|
||||
raise UserSuppliedSecretMissingError(
|
||||
"User supplied secret configured, but it's neither in the store nor supplied"
|
||||
)
|
||||
return user_supplied_secret
|
||||
|
||||
|
||||
|
|
|
@ -135,6 +135,11 @@ class TestSecretGenerator:
|
|||
secret = generator.getSecret()
|
||||
assert len(secret) == 30
|
||||
|
||||
def test_missing_user_supplied_secret(self, monkeypatch):
|
||||
generator = gpg_secretstore.SecretGenerator(secret_type="user_supplied")
|
||||
with pytest.raises(Exception):
|
||||
generator.getSecret()
|
||||
|
||||
def test_plain_user_supplied_secret(self, monkeypatch):
|
||||
generator = gpg_secretstore.SecretGenerator(
|
||||
secret_type="user_supplied", user_supplied_secret="secretdata"
|
||||
|
|
Loading…
Reference in a new issue