Skip to content

Commit

Permalink
Merge pull request #122 from olcf/ngin_remove_setupsh_cleanup_setuppy
Browse files Browse the repository at this point in the history
Create a cleaner setup environment
  • Loading branch information
Noah Ginsburg authored Sep 24, 2019
2 parents 695f4ec + 7a071e6 commit e643a74
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 308 deletions.
2 changes: 1 addition & 1 deletion docs/source/Development And Testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Development and Testing
Testing Scripts
---------------
Currently there exists a shell script ``./test/pki/generatepki.sh`` that will generate certificates for a developer to use for unittests
After running this script, you can run tox or the ``./unittest.sh`` file; note that ``./unittest.sh`` does not test multiple versions of
After running this script, you can run tox or the ``python -m unittest discover`` note that ``python -m unittest discover`` does not test multiple versions of
python like tox does

Plugin Behavior - Connectors
Expand Down
11 changes: 6 additions & 5 deletions docs/source/Setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ The bash script ``./setup.sh`` obviously will only work on systems with bash suc
The python script ``./setup.py`` *should* run on all systems.

* bash:
This script will walk you through a full installation including setting up venvs if you need that.
This is a wrapper script for ``./setup.py`` it serves the function of installing pkpass in a python3 virtualenv

* python:
| This will run through specific commands
| ``python setup.py rcfile`` will create an rcfile
| ``python setup.py install`` will run the installation on a system level
| ``python setup.py install --user`` will run the installation on a user level
| ``python setup.py verify -r "/path/to/.pkpassrc"`` will do basic linting of the pkpassrc file
| ``./setup.py rcfile`` will create an rcfile
| ``./setup.py install`` will run the installation on a system level
| ``./setup.py install --user`` will run the installation on a user level
| ``./setup.py verify -r "/path/to/.pkpassrc"`` will do basic linting of the pkpassrc file
| ``./setup.py verify`` will do basic linting on a pkpassrc file located at ``~/.pkpassrc``
| if you need the -h flag may help.
In both cases, these files can install dependencies and create a .pkpassrc file for you
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cryptography>=2.3
exrex>=0.10.5
future>=0.17.1
mock>=2.0.0
nginsecretsharing>=0.3.0
pyperclip>=1.6.0
PyYAML>=4.2b1
setuptools>=41.2.0
34 changes: 34 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[metadata]
name = pkpass
author = Noah Ginsburg
author_email = [email protected]
url = https://github.com/olcf/pkpass
description = Public Key based Password Management
long_description = file: README.md
long_description_content_type = text/markdown
license = GPLV3
classifiers =
Environment :: Console
Intended Audience :: Developers
Intended Audience :: Information Technology
Intended Audience :: System Administrators
LICENSE :: OSI Approved :: GNU GENERAL PUBLIC LICENSE V3 (GPLV3)
Operating System :: OS Independent
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Topic :: Security :: Cryptography

[options]
include_package_data = True
packages = find:
scripts =
bin/pkpass

[options.packages.find]
exclude =
tests

[options.extras_require]
testing: mock; tox
153 changes: 62 additions & 91 deletions setup.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,18 @@
import getpass
from shutil import rmtree

from setuptools import find_packages, setup, Command

# Package meta-data
NAME = 'pkpass'
DESCRIPTION = 'Public Key based password manager'
URL = 'https://github.com/olcf/pkpass'
EMAIL = '[email protected]'
AUTHOR = 'Noah Ginsburg'
VERSION = None
from setuptools import setup, Command

with io.open('requirements.txt') as requirements_file:
REQUIRED = requirements_file.read().splitlines()

HOME = os.path.expanduser("~")
HERE = os.path.abspath(os.path.dirname(__file__))

# Import the README and use it as the long-description.
# Note: this will only work if 'README.md' is present in your MANIFEST.in file!
try:
with io.open(os.path.join(HERE, 'README.md'), encoding='utf-8') as f:
LONG_DESCRIPTION = '\n' + f.read()
except IOError:
LONG_DESCRIPTION = DESCRIPTION

# Load the package's __version__.py module as a dictionary.
ABOUT = {}
if not VERSION:
with open(os.path.join(HERE, 'VERSION')) as version_file:
ABOUT['__version__'] = version_file.read().strip()
else:
ABOUT['__version__'] = VERSION
with open(os.path.join(HERE, 'VERSION')) as version_file:
ABOUT['__version__'] = version_file.read().strip()

class UploadCommand(Command):
"""Support setup.py upload."""
Expand Down Expand Up @@ -82,11 +64,10 @@ class RCFile(Command):
user_options = []

def initialize_options(self):
self.home = os.path.expanduser("~")
pass

def finalize_options(self):
# this command object complains with you do stuff in init
self.home = os.path.expanduser("~") #pylint: attribute-defined-outside-init
pass

def user_input(self, prompt, default):
u_input = input(prompt).strip()
Expand All @@ -110,52 +91,62 @@ def file_creation(self, user_prompt, default):

def finish_run(self):
testing = """testing versions of openssl and pkcs15-tool if version numbers return you're probably good
for sanity sake Noah's return values were:
openssl version: LibreSSL 2.2.7
pkcs15-tool --version: OpenSC-0.18.0, rev: eb60481f, commit-time: 2018-05-16 13:48:37 +0200
------YOUR VALUES BELOW THIS LINE -----------"""
for sanity sake Noah's return values were:
openssl version: LibreSSL 2.2.7
pkcs15-tool --version: OpenSC-0.18.0, rev: eb60481f, commit-time: 2018-05-16 13:48:37 +0200
------YOUR VALUES BELOW THIS LINE -----------"""

print(testing)
print(Popen("openssl version".split(), stdout=PIPE, stdin=PIPE, stderr=STDOUT).communicate()[0])
print(Popen("pkcs15-tool --version".split(), stdout=PIPE, stdin=PIPE, stderr=STDOUT).communicate()[0])
print(Popen("openssl version".split(), stdout=PIPE, stdin=PIPE, stderr=STDOUT).communicate()[0].decode("ASCII"))
print(Popen("pkcs15-tool --version".split(), stdout=PIPE, stdin=PIPE, stderr=STDOUT).communicate()[0].decode("ASCII"))

def run(self):
args = {
'cabundle': '',
'card_slot': '',
'certpath': '',
'connect': '',
'dstpwstore': '',
'escrow_users': '',
'groups': '',
'identity': '',
'keypath': '',
'min_escrow': '',
'pwstore': '',
'time': '',
'rules': '',
'rules_map': '',
'users': ''
}
print("If not using defaults for the following paths please use full filepath or relative to home using ~")
passdb_home = os.path.join(self.home, "passdb")
certs = self.directory_creation("Directory for certpath (defaults to ~/passdb/certs): ",
os.path.join(passdb_home, "certs"))
keys = self.directory_creation("Directory for keypath (defaults to ~/passdb/keys): ",
os.path.join(passdb_home, "keys"))
cabundle = self.file_creation("Path to cabundle (defaults to ~/passdb/cabundles/ca.bundle): ",
os.path.join(passdb_home, "cabundles", "ca.bundle"))
passwords = self.directory_creation("Directory for passwords (defaults to ~/passdb/passwords): ",
os.path.join(passdb_home, "passwords"))

print(Popen("pkcs11-tool -L".split(), stdout=PIPE, stdin=PIPE, stderr=STDOUT).communicate()[0])
card_slot = self.user_input("Available slots listed above, which would you like to use? (defaults to 0): ", "0")
identity = self.user_input("What user name would you like to use? (defaults to system user): ", getpass.getuser())
passdb_home = os.path.join(HOME, "passdb")
args['certpath'] = self.directory_creation("Directory for certpath (defaults to ~/passdb/certs): ",
os.path.join(passdb_home, "certs"))
args['keypath'] = self.directory_creation("Directory for keypath (defaults to ~/passdb/keys): ",
os.path.join(passdb_home, "keys"))
args['cabundle'] = self.file_creation("Path to cabundle (defaults to ~/passdb/cabundles/ca.bundle): ",
os.path.join(passdb_home, "cabundles", "ca.bundle"))
args['pwstore'] = self.directory_creation("Directory for passwords (defaults to ~/passdb/passwords): ",
os.path.join(passdb_home, "passwords"))

print(Popen("pkcs11-tool -L".split(), stdout=PIPE, stdin=PIPE, stderr=STDOUT).communicate()[0].decode("ASCII"))
args['card_slot'] = self.user_input("Available slots listed above, which would you like to use? (defaults to 0): ", "0")
args['identity'] = self.user_input("What user name would you like to use? (defaults to system user): ", getpass.getuser())
print("Escrow users is a feature of Pkpass. Escrow allows a password to be recovered by the majority of the escrow users in the event of an emergency.")
check_escrow = self.user_input("Would you like to setup escrow? ", "n")
if check_escrow.lower()[0] != 'y':
escrow_users = ""
min_escrow = ""
else:
if check_escrow.lower()[0] == 'y':
escrow_users = self.user_input("Please enter a comma seperated list of usernames: ", "").split(',')
escrow_users = ",".join([user.strip() for user in escrow_users])
min_escrow = self.user_input("What should be the minimum number of escrow users required to unlock? ",
len(escrow_users.split(',')) - 1)

contents = """certpath: %s
keypath: %s
cabundle: %s
pwstore: %s
card_slot: %s
identity: %s
escrow_users: %s
min_escrow: %s""" % (certs, keys, cabundle, passwords, card_slot, identity, escrow_users, min_escrow)

with open(os.path.join(self.home, '.pkpassrc'), 'w') as fname:
fname.write(contents)
args['escrow_users'] = ",".join([user.strip() for user in escrow_users])
args['min_escrow'] = self.user_input("What should be the minimum number of escrow users required to unlock? ",
len(args['escrow_users'].split(',')) - 1)

with open(os.path.join(HOME, '.pkpassrc'), 'w') as fname:
# fname.write(contents)
for key, value in args.items():
if value:
fname.write("%s: %s\n" % (key, value))
else:
fname.write("#%s:\n" % key)

self.finish_run()

Expand All @@ -167,7 +158,7 @@ class Verify(Command):
user_options = [("rcfile=", "r", 'Specify the rc file path')]

def initialize_options(self):
self.rcfile = ""
self.rcfile = "~/.pkpassrc"

def finalize_options(self):
pass
Expand Down Expand Up @@ -219,12 +210,13 @@ def run(self):
'nosign', 'noverify', 'overwrite',
'pwfile', 'pwname', 'recovery', 'stdin']
args_dict = {}
with open(self.rcfile, 'r') as rcyaml:
try:
args_dict = yaml.safe_load(rcyaml)
except yaml.YAMLError as err:
valid = False
print(err)
if self.rcfile:
with open(os.path.expanduser(self.rcfile), 'r') as rcyaml:
try:
args_dict = yaml.safe_load(rcyaml)
except yaml.YAMLError as err:
valid = False
print(err)
for arg in store_args:
if arg in args_dict.keys():
valid = False
Expand All @@ -244,32 +236,11 @@ def run(self):
print("Config Valid")

setup(
name=NAME,
version=ABOUT['__version__'],
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
long_description_content_type='text/markdown',
author=AUTHOR,
author_email=EMAIL,
url=URL,
packages=find_packages(exclude=('tests',)),
install_requires=REQUIRED,
include_package_data=True,
license='GPLV3',
classifiers=[
'License :: OSI Approved :: GNU GENERAL PUBLIC LICENSE V3 (GPLV3)',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
cmdclass={
'upload': UploadCommand,
'rcfile': RCFile,
'verify': Verify,
},
scripts=[
'bin/pkpass'
]
)
Loading

0 comments on commit e643a74

Please sign in to comment.