Skip to content

Commit

Permalink
Improve feedback using @oracle:eval
Browse files Browse the repository at this point in the history
If the given command fails (non-zerro exit code), show a configuration
error instead of a stack-trace.  The error include the command's stderr.
  • Loading branch information
gdetrez committed Feb 18, 2016
1 parent 0b91ff2 commit 544dae6
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions bugwarrior/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,27 @@ def get_service_password(service, username, oracle=None, interactive=False):
password = getpass.getpass(prompt)
elif oracle.startswith('@oracle:eval:'):
command = oracle[13:]
p = subprocess.Popen(
command,
shell=True,
stdout=subprocess.PIPE,
#stderr=subprocess.STDOUT
)
password = p.stdout.read()[:-1]
return oracle_eval(command)

if password is None:
die("MISSING PASSWORD: oracle='%s', interactive=%s for service=%s" %
(oracle, interactive, service))
return password


def oracle_eval(command):
""" Retrieve password from the given command """
p = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
if p.returncode == 0:
return p.stdout.readline().strip()
else:
die(
"Error retrieving password: `{command}` returned '{error}'".format(
command=command, error=p.stderr.read().strip()))


def load_example_rc():
fname = os.path.join(
os.path.dirname(__file__),
Expand Down

0 comments on commit 544dae6

Please sign in to comment.