Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interactive prompt for user/pass #15

Merged
merged 1 commit into from
Apr 2, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions scripts/pepper
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import optparse
import os
import textwrap
import ConfigParser
import getpass

import pepper

Expand Down Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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():
Expand All @@ -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']
Expand Down