Skip to content

Commit

Permalink
Don't use singleton CredentialStore in requires_credentials decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Jun 2, 2020
1 parent e6a4f0f commit 27d55e8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/pyze/api/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ class MissingCredentialException(Exception):
def requires_credentials(*names):
def _requires_credentials(func):
def inner(*args, **kwargs):
credentials = None
if args[0] and hasattr(args[0], '_credentials'):
credentials = args[0]._credentials
elif args[0] and hasattr(args[0], '_kamereon'):
credentials = args[0]._kamereon._credentials
for name in names:
if name not in CredentialStore():
if name not in credentials:
raise MissingCredentialException(name)
return func(*args, **kwargs)

Expand Down Expand Up @@ -100,6 +105,11 @@ def _add_api_keys_from_env(self):
if 'KAMEREON_API_KEY' in os.environ:
self.store('kamereon-api-key', os.environ['KAMEREON_API_KEY'], None)

def requires(self, *names):
for name in names:
if name not in self._store:
raise MissingCredentialException(name)


Credential = namedtuple(
'Credential',
Expand Down

0 comments on commit 27d55e8

Please sign in to comment.