From 4d58b61e76de1a14b9ec3e3d74e32ce6ffe0b0a6 Mon Sep 17 00:00:00 2001 From: Neal Buchanan Date: Thu, 29 Oct 2015 11:24:14 -0600 Subject: [PATCH 1/5] setup.py convert tag from bytes to string __init__.py open version.json as text not bytes for json parse cli.py import configparser compatable with python3 cli.py set default SALTAPI_PASS to None added check to get_login_details if password none prompt for password libpepper.py import ssl and set default https context to ignore unverified certs --- pepper/__init__.py | 2 +- pepper/cli.py | 25 ++++++++++++++++++------- pepper/libpepper.py | 5 +++++ setup.py | 1 + 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/pepper/__init__.py b/pepper/__init__.py index 77b3af1..5b77217 100644 --- a/pepper/__init__.py +++ b/pepper/__init__.py @@ -13,7 +13,7 @@ # First try to grab the version from the version.json build file. vfile = os.path.join(os.path.dirname(__file__), 'version.json') - with open(vfile, 'rb') as f: + with open(vfile, 'r') as f: ret = json.load(f) version = ret.get('version') sha = ret.get('sha') diff --git a/pepper/cli.py b/pepper/cli.py index 0a535d4..bb361fd 100644 --- a/pepper/cli.py +++ b/pepper/cli.py @@ -9,7 +9,6 @@ import optparse import os import textwrap -import ConfigParser import getpass import time @@ -21,6 +20,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()) @@ -181,11 +185,11 @@ def get_login_details(self): results = { 'SALTAPI_URL': 'https://localhost:8000/', 'SALTAPI_USER': 'saltdev', - 'SALTAPI_PASS': 'saltdev', + 'SALTAPI_PASS': None, 'SALTAPI_EAUTH': 'auto', } - config = ConfigParser.RawConfigParser() + config = configparser.RawConfigParser() config.read(self.options.config) # read file @@ -196,7 +200,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 @@ -210,7 +214,7 @@ def get_login_details(self): results['SALTAPI_EAUTH'] = self.options.eauth if self.options.username is None: if self.options.interactive: - results['SALTAPI_USER'] = raw_input('Username: ') + results['SALTAPI_USER'] = input('Username: ') else: logger.error("SALTAPI_USER required") raise SystemExit(1) @@ -225,6 +229,13 @@ def get_login_details(self): else: results['SALTAPI_PASS'] = self.options.password + if results['SALTAPI_PASS'] is None: + if self.options.interactive: + results['SALTAPI_PASS'] = getpass.getpass(prompt='Password: ') + else: + logger.error("SALTAPI_PASS required") + raise SystemExit(1) + return results def parse_login(self): @@ -291,7 +302,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 @@ -318,7 +329,7 @@ def run(self): load = self.parse_cmd() creds = iter(self.parse_login()) - api = pepper.Pepper(creds.next(), debug_http=self.options.debug_http) + api = pepper.Pepper(next(creds), debug_http=self.options.debug_http) auth = api.login(*list(creds)) if self.options.fail_if_minions_dont_respond: diff --git a/pepper/libpepper.py b/pepper/libpepper.py index 75b345f..9fe7cd0 100644 --- a/pepper/libpepper.py +++ b/pepper/libpepper.py @@ -8,6 +8,11 @@ import json import logging import os +try: + import ssl + ssl._create_default_https_context = ssl._create_unverified_context +except: + pass try: from urllib.request import HTTPHandler, Request, urlopen, \ install_opener, build_opener diff --git a/setup.py b/setup.py index 2d02dce..c6e6e3b 100644 --- a/setup.py +++ b/setup.py @@ -67,6 +67,7 @@ def parse_version_tag(tag): Returns a tuple of the version number, number of commits (if any), and the Git SHA (if available). ''' + tag = tag.decode('UTF-8') if not tag or '-g' not in tag: return tag, None, None From 32b088b6e2ce2acd903a348ccdcb44dad6cbe895 Mon Sep 17 00:00:00 2001 From: Neal Buchanan Date: Thu, 29 Oct 2015 11:24:14 -0600 Subject: [PATCH 2/5] setup.py convert tag from bytes to string __init__.py open version.json as text not bytes for json parse cli.py minor changes for python3 compatability cli.py set default SALTAPI_PASS to None added check to get_login_details if password none prompt for password libpepper.py import ssl and set default https context to ignore unverified certs --- pepper/__init__.py | 2 +- pepper/cli.py | 25 ++++++++++++++++++------- pepper/libpepper.py | 5 +++++ setup.py | 1 + 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/pepper/__init__.py b/pepper/__init__.py index 77b3af1..5b77217 100644 --- a/pepper/__init__.py +++ b/pepper/__init__.py @@ -13,7 +13,7 @@ # First try to grab the version from the version.json build file. vfile = os.path.join(os.path.dirname(__file__), 'version.json') - with open(vfile, 'rb') as f: + with open(vfile, 'r') as f: ret = json.load(f) version = ret.get('version') sha = ret.get('sha') diff --git a/pepper/cli.py b/pepper/cli.py index 0a535d4..bb361fd 100644 --- a/pepper/cli.py +++ b/pepper/cli.py @@ -9,7 +9,6 @@ import optparse import os import textwrap -import ConfigParser import getpass import time @@ -21,6 +20,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()) @@ -181,11 +185,11 @@ def get_login_details(self): results = { 'SALTAPI_URL': 'https://localhost:8000/', 'SALTAPI_USER': 'saltdev', - 'SALTAPI_PASS': 'saltdev', + 'SALTAPI_PASS': None, 'SALTAPI_EAUTH': 'auto', } - config = ConfigParser.RawConfigParser() + config = configparser.RawConfigParser() config.read(self.options.config) # read file @@ -196,7 +200,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 @@ -210,7 +214,7 @@ def get_login_details(self): results['SALTAPI_EAUTH'] = self.options.eauth if self.options.username is None: if self.options.interactive: - results['SALTAPI_USER'] = raw_input('Username: ') + results['SALTAPI_USER'] = input('Username: ') else: logger.error("SALTAPI_USER required") raise SystemExit(1) @@ -225,6 +229,13 @@ def get_login_details(self): else: results['SALTAPI_PASS'] = self.options.password + if results['SALTAPI_PASS'] is None: + if self.options.interactive: + results['SALTAPI_PASS'] = getpass.getpass(prompt='Password: ') + else: + logger.error("SALTAPI_PASS required") + raise SystemExit(1) + return results def parse_login(self): @@ -291,7 +302,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 @@ -318,7 +329,7 @@ def run(self): load = self.parse_cmd() creds = iter(self.parse_login()) - api = pepper.Pepper(creds.next(), debug_http=self.options.debug_http) + api = pepper.Pepper(next(creds), debug_http=self.options.debug_http) auth = api.login(*list(creds)) if self.options.fail_if_minions_dont_respond: diff --git a/pepper/libpepper.py b/pepper/libpepper.py index 75b345f..9fe7cd0 100644 --- a/pepper/libpepper.py +++ b/pepper/libpepper.py @@ -8,6 +8,11 @@ import json import logging import os +try: + import ssl + ssl._create_default_https_context = ssl._create_unverified_context +except: + pass try: from urllib.request import HTTPHandler, Request, urlopen, \ install_opener, build_opener diff --git a/setup.py b/setup.py index 2d02dce..c6e6e3b 100644 --- a/setup.py +++ b/setup.py @@ -67,6 +67,7 @@ def parse_version_tag(tag): Returns a tuple of the version number, number of commits (if any), and the Git SHA (if available). ''' + tag = tag.decode('UTF-8') if not tag or '-g' not in tag: return tag, None, None From 53a0d047ca81bf17ef166bb1248d87dba4428b4b Mon Sep 17 00:00:00 2001 From: buchanan Date: Tue, 29 Dec 2015 16:04:57 -0700 Subject: [PATCH 3/5] Fix merge conflict --- pepper/cli.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pepper/cli.py b/pepper/cli.py index 9ab75c1..34d84e2 100644 --- a/pepper/cli.py +++ b/pepper/cli.py @@ -344,11 +344,7 @@ def run(self): load = self.parse_cmd() creds = iter(self.parse_login()) -<<<<<<< HEAD - api = pepper.Pepper(next(creds), debug_http=self.options.debug_http) -======= api = pepper.Pepper(next(creds), debug_http=self.options.debug_http, ignore_ssl_errors=self.options.ignore_ssl_certificate_errors) ->>>>>>> 148a7d86dc7d746590d6c61b71da1cb1726c03bf auth = api.login(*list(creds)) if self.options.fail_if_minions_dont_respond: From f64aae87db97309f5fc6a9040737dace15118b25 Mon Sep 17 00:00:00 2001 From: buchanan Date: Tue, 29 Dec 2015 17:02:18 -0700 Subject: [PATCH 4/5] Prompt for username/password if missing from .pepperrc --- files.txt | 8 ++++++++ pepper/__init__.py | 2 +- pepper/cli.py | 29 +++++++++++------------------ pepper/libpepper.py | 1 - 4 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 files.txt diff --git a/files.txt b/files.txt new file mode 100644 index 0000000..f81ee07 --- /dev/null +++ b/files.txt @@ -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 diff --git a/pepper/__init__.py b/pepper/__init__.py index 5b77217..77b3af1 100644 --- a/pepper/__init__.py +++ b/pepper/__init__.py @@ -13,7 +13,7 @@ # First try to grab the version from the version.json build file. vfile = os.path.join(os.path.dirname(__file__), 'version.json') - with open(vfile, 'r') as f: + with open(vfile, 'rb') as f: ret = json.load(f) version = ret.get('version') sha = ret.get('sha') diff --git a/pepper/cli.py b/pepper/cli.py index 34d84e2..af7c857 100644 --- a/pepper/cli.py +++ b/pepper/cli.py @@ -196,7 +196,7 @@ def get_login_details(self): # setting default values results = { 'SALTAPI_URL': 'https://localhost:8000/', - 'SALTAPI_USER': 'saltdev', + 'SALTAPI_USER': None, 'SALTAPI_PASS': None, 'SALTAPI_EAUTH': 'auto', } @@ -227,29 +227,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'] = input('Username: ') - else: - logger.error("SALTAPI_USER required") - raise SystemExit(1) - 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) + if self.options.username is None and results['SALTAPI_USER'] is None: + if self.options.interactive: + results['SALTAPI_USER'] = input('Username: ') else: - results['SALTAPI_PASS'] = self.options.password - - if results['SALTAPI_PASS'] is None: + 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: logger.error("SALTAPI_PASS required") raise SystemExit(1) + else: + if self.options.password is not None: results['SALTAPI_PASS'] = self.options.password return results diff --git a/pepper/libpepper.py b/pepper/libpepper.py index 29310cc..1a336e9 100644 --- a/pepper/libpepper.py +++ b/pepper/libpepper.py @@ -7,7 +7,6 @@ import functools import json import logging -import ssl import os try: import ssl From 71e8dfb68c1eb6558a7f2739759078b958b63e0b Mon Sep 17 00:00:00 2001 From: buchanan Date: Thu, 31 Dec 2015 07:02:35 -0700 Subject: [PATCH 5/5] Map input to raw_input for 2.7 compatability change default https context to the more universal stdlib context --- pepper/cli.py | 5 +++++ pepper/libpepper.py | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pepper/cli.py b/pepper/cli.py index af7c857..3682a34 100644 --- a/pepper/cli.py +++ b/pepper/cli.py @@ -17,6 +17,11 @@ # Python 2 import ConfigParser +try: + input = raw_input +except NameError: + pass + import pepper try: diff --git a/pepper/libpepper.py b/pepper/libpepper.py index 1a336e9..e188ebf 100644 --- a/pepper/libpepper.py +++ b/pepper/libpepper.py @@ -8,11 +8,12 @@ import json import logging import os +import ssl try: - import ssl - ssl._create_default_https_context = ssl._create_unverified_context + ssl._create_default_https_context = ssl._create_stdlib_context except: pass + try: from urllib.request import HTTPHandler, Request, urlopen, \ install_opener, build_opener