From 794ae7c365db2e29a93e97713e8e32e8e8da84a2 Mon Sep 17 00:00:00 2001 From: Sijis Aviles Date: Wed, 2 Apr 2014 10:33:35 -0500 Subject: [PATCH] Add interactive prompt for user/pass Fixes #7 --- scripts/pepper | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/scripts/pepper b/scripts/pepper index a47d39a..dc9fcbe 100644 --- a/scripts/pepper +++ b/scripts/pepper @@ -9,6 +9,7 @@ import optparse import os import textwrap import ConfigParser +import getpass import pepper @@ -95,10 +96,10 @@ def add_authopts(parser): SALTAPI_URL, SALTAPI_USER, SALTAPI_PASS, SALTAPI_EAUTH. """)) - # optgroup.add_option('-a', '--auth', '--eauth', '--extended-auth', - # default='', dest='eauth', help=textwrap.dedent("""\ - # Specify the external_auth backend to authenticate against and - # interactively prompt for credentials""")) + optgroup.add_option('-a', '--auth', '--eauth', '--extended-auth', + default='', dest='eauth', help=textwrap.dedent("""\ + Specify the external_auth backend to authenticate against and + interactively prompt for credentials""")) # optgroup.add_option('-T', '--make-token', default=False, # dest='mktoken', action='store_true', @@ -109,7 +110,7 @@ def add_authopts(parser): parser.add_option_group(optgroup) -def get_login_details(config_file, profile='main'): +def get_login_details(opts): ''' This parses the config file and environment variables and returns the config values @@ -125,8 +126,11 @@ def get_login_details(config_file, profile='main'): 'SALTAPI_EAUTH': 'auto', } + valid_auths = ('pam') + profile = 'main' + config = ConfigParser.RawConfigParser() - config.read(config_file) + config.read(opts.config) # read file if config.has_section(profile): @@ -138,6 +142,11 @@ def get_login_details(config_file, profile='main'): for key, value in results.items(): results[key] = os.environ.get(key, results[key]) + # get eauth prompt options + if opts.eauth and opts.eauth in valid_auths: + results['SALTAPI_USER'] = raw_input('Username: ') + results['SALTAPI_PASS'] = getpass.getpass(prompt='Password: ') + return results def main(): @@ -163,7 +172,7 @@ def main(): kwarg = None # placeholder kwargs = opts.__dict__ - login_details = get_login_details(opts.config) + login_details = get_login_details(opts) # Auth values placeholder; grab interactively at CLI or from config file salturl = login_details['SALTAPI_URL']