Skip to content

Commit

Permalink
Handle a callable in credentials._LazyPassword.__str__
Browse files Browse the repository at this point in the history
It is possible that the self._pwfunc() call returns a callable. For
instance, if the keyutils.osc.OscKernelKeyringBackend is configured
in the oscrc. Hence, check in credentials._LazyPassword.__str__
if the returned password is a callable and, if so, call it. Moreover,
a deprecation warning is printed. Eventually, this compat code will
be removed again.

This is a follow-up commit for commit
784d330 ("Only prompt for a password
if the server asks for it") (actually, it is a regression that was
not caught during the review...).
  • Loading branch information
marcus-h committed Apr 13, 2022
1 parent ff45f10 commit 3262c05
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions osc/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ def __init__(self, pwfunc):

def __str__(self):
if self._password is None:
self._password = self._pwfunc()
if self._password is None:
password = self._pwfunc()
if callable(password):
print('Warning: use of a deprecated credentials manager API.',
file=sys.stderr)
password = password()
if password is None:
raise oscerr.OscIOError(None, 'Unable to retrieve password')
self._password = password
return self._password

def __len__(self):
Expand Down

0 comments on commit 3262c05

Please sign in to comment.