Skip to content

Commit

Permalink
Merge pull request #66 from buchanan/master
Browse files Browse the repository at this point in the history
Python 3 support and prompt for user/password when missing from .pepperrc
  • Loading branch information
whiteinge committed Dec 31, 2015
2 parents 148a7d8 + 71e8dfb commit 2085586
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
8 changes: 8 additions & 0 deletions files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/usr/lib/python3.5/site-packages/pepper/__init__.py
/usr/lib/python3.5/site-packages/pepper/libpepper.py
/usr/lib/python3.5/site-packages/pepper/cli.py
/usr/lib/python3.5/site-packages/pepper/__pycache__/__init__.cpython-35.pyc
/usr/lib/python3.5/site-packages/pepper/__pycache__/libpepper.cpython-35.pyc
/usr/lib/python3.5/site-packages/pepper/__pycache__/cli.cpython-35.pyc
/usr/bin/pepper
/usr/lib/python3.5/site-packages/salt_pepper-0.4.0.dev21-py3.5.egg-info
46 changes: 28 additions & 18 deletions pepper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
# Python 2
import ConfigParser

try:
input = raw_input
except NameError:
pass

import pepper

try:
Expand All @@ -25,6 +30,11 @@
class NullHandler(logging.Handler):
def emit(self, record): pass

try:
import configparser
except ImportError:
import ConfigParser as configparser

logging.basicConfig(format='%(levelname)s %(asctime)s %(module)s: %(message)s')
logger = logging.getLogger('pepper')
logger.addHandler(NullHandler())
Expand Down Expand Up @@ -191,8 +201,8 @@ def get_login_details(self):
# setting default values
results = {
'SALTAPI_URL': 'https://localhost:8000/',
'SALTAPI_USER': 'saltdev',
'SALTAPI_PASS': 'saltdev',
'SALTAPI_USER': None,
'SALTAPI_PASS': None,
'SALTAPI_EAUTH': 'auto',
}

Expand All @@ -210,7 +220,7 @@ def get_login_details(self):
results[key] = config.get(profile, key)

# get environment values
for key, value in results.items():
for key, value in list(results.items()):
results[key] = os.environ.get(key, results[key])

# get eauth prompt options
Expand All @@ -222,22 +232,22 @@ def get_login_details(self):

if self.options.eauth:
results['SALTAPI_EAUTH'] = self.options.eauth
if self.options.username is None:
if self.options.interactive:
results['SALTAPI_USER'] = raw_input('Username: ')
else:
logger.error("SALTAPI_USER required")
raise SystemExit(1)
if self.options.username is None and results['SALTAPI_USER'] is None:
if self.options.interactive:
results['SALTAPI_USER'] = input('Username: ')
else:
results['SALTAPI_USER'] = self.options.username
if self.options.password is None:
if self.options.interactive:
results['SALTAPI_PASS'] = getpass.getpass(prompt='Password: ')
else:
logger.error("SALTAPI_PASS required")
raise SystemExit(1)
logger.error("SALTAPI_USER required")
raise SystemExit(1)
else:
if self.options.username is not None: results['SALTAPI_USER'] = self.options.username
if self.options.password is None and results['SALTAPI_PASS'] is None:
if self.options.interactive:
results['SALTAPI_PASS'] = getpass.getpass(prompt='Password: ')
else:
results['SALTAPI_PASS'] = self.options.password
logger.error("SALTAPI_PASS required")
raise SystemExit(1)
else:
if self.options.password is not None: results['SALTAPI_PASS'] = self.options.password

return results

Expand Down Expand Up @@ -305,7 +315,7 @@ def poll_for_returns(self, api, load):
break

jid_ret = api.lookup_jid(jid)
ret_nodes = jid_ret['return'][0].keys()
ret_nodes = list(jid_ret['return'][0].keys())

if set(ret_nodes) == set(nodes):
ret = jid_ret
Expand Down
7 changes: 6 additions & 1 deletion pepper/libpepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
import functools
import json
import logging
import ssl
import os
import ssl
try:
ssl._create_default_https_context = ssl._create_stdlib_context
except:
pass

try:
from urllib.request import HTTPHandler, Request, urlopen, \
install_opener, build_opener
Expand Down

0 comments on commit 2085586

Please sign in to comment.