Skip to content

Commit

Permalink
Fix current_sha missing
Browse files Browse the repository at this point in the history
* Fix issue with current_sha not being saved
* Fix creation of distribution
* Fix pip install
* Bump to python-gnupg==0.4.5, If no expiry sent, don't filter
* Remove references to pyinstaller
* Put .PHONY about each PHONY item
* Swap TMPDIR for TMP_DIR b/c Mac OS

Closes #28
  • Loading branch information
drGrove committed Nov 6, 2019
1 parent 3381945 commit f7e5fde
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 114 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ commands:
- run:
name: Pipenv Install
command: |
pip install --user pip==18.0
pip install --user pipenv
pipenv --three install --dev
python -m pip install --user pip==18.0
python -m pip install --user pipenv
python -m pipenv --three install --dev
environment:
PIP_SHIMS_BASE_MODULE: pipenv.patched.notpip
- save_cache:
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
command: pipenv lock -r > requirements.txt
- run:
name: Create Distribution
command: make pkg-pypi
command: make pkg
- store_artifacts:
path: dist/

Expand Down
43 changes: 18 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.PHONY: setup env clean lint build test
SHELL := /bin/bash
PIP_ENV:=$(shell pipenv --venv)
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
Expand All @@ -12,77 +11,71 @@ else
UNAME := $(shell uname -s)
endif

.PHONY: shell
shell:
@pipenv shell

.PHONY: setup
setup: set-hooks
@pipenv --three install --dev
@pipenv run easy_install PyInstaller==3.4
@pipenv sync --dev

.PHONY: pipenv-lock
pipenv-lock:
@pipenv update
@pipenv lock -r > requirements.txt

.PHONY: set-hooks
set-hooks:
@echo "Setting commit hooks"
@ ([ ! -L ".git/hooks/pre-commit" ] && \
ln -s $(PWD)/scripts/git-hooks/pre-commit.sh .git/hooks/pre-commit) \
|| true

install: build
@mkdir -p $(DESTDIR)
@echo "Copying mtls/mtls to $(DESTDIR), Please ensure you have $(DESTDIR) in your PATH"
@cp mtls-$(UNAME)/mtls $(DESTDIR)

.PHONY: format
format:
@pipenv run black -l 79 ./mtls/*.py
@pipenv run black -l 79 ./test/*.py

.PHONY: lint
lint:
@pipenv run pycodestyle **/*.py

.PHONY: build-develop
build-develop:
@pipenv run python setup.py develop

build-pyinstaller-binary:
@pipenv run pyinstaller --onefile --distpath=mtls-$(UNAME) mtls.spec

.PHONY: build-pypi
build-pypi:
@pipenv run python setup.py sdist bdist_wheel

.PHONY: build
build: setup
@pipenv run python setup.py build

.PHONY: run
run:
@pipenv run python3 bin/mtls $(ARGS)

run-build:
@./mtls-$(UNAME)/mtls $(ARGS)

.PHONY: test
test: setup
-@$(PIP_ENV)/bin/coverage run -m unittest -v

.PHONY: test-by-name
test-by-name:
-@$(PIP_ENV)/bin/coverage run -m unittest $(TEST) -v

.PHONY: coverage
coverage:
@$(PIP_ENV)/bin/coverage report -m

.PHONY: coveralls
coveralls:
@$(PIP_ENV)/bin/coveralls


pkg: build-pyinstaller-binary
@echo "Generating sha256sum of Binary"
@shasum -a256 mtls-$(UNAME)/mtls > mtls-$(UNAME)/mtls.sha256sum
ifeq ($(SIGN), 1)
@echo "Signing binary"
@gpg --sign --detach-sign --output mtls-$(UNAME)/mtls.sig mtls-$(UNAME)/mtls
endif
@tar -zcvf mtls-$(UNAME)-$(VERSION).tar.gz mtls-$(UNAME)

pkg-pypi: build
.PHONY: pkg
pkg: build
@pipenv run python setup.py sdist bdist_wheel

.PHONY: clean
clean:
@rm -r build dist $(PIP_ENV) mtls-$(UNAME)
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ click = "==7.0"
cryptography = "==2.4.2"
pyOpenSSL = "==19.0.0"
pycodestyle = "==2.4.0"
python-gnupg = "==0.4.4"
python-gnupg = "==0.4.5"
requests = "==2.21.0"
urllib3 = "==1.24.3"
108 changes: 56 additions & 52 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 16 additions & 10 deletions mtls/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python3
import datetime
import os
import sys
from configparser import ConfigParser
from datetime import datetime

import click

Expand Down Expand Up @@ -245,7 +245,7 @@ def add_user(ctx, admin, fingerprint, email, keyserver):
click.secho("A server was not provided.", fg="red")
sys.exit(1)
if fingerprint is None and email is None:
click.echo("A fingerprint must be provided")
click.echo("A fingerprint or email must be provided")
sys.exit(1)
if email is not None:
fingerprint = handle_email(ctx, email, keyserver)
Expand Down Expand Up @@ -288,26 +288,32 @@ def handle_email(ctx, email, keyserver=None):
search_res = ctx.obj.gpg.search_keys(email, keyserver=keyserver)
else:
search_res = ctx.obj.gpg.search_keys(email)
now = str(int(datetime.datetime.now().timestamp()))
now = str(int(datetime.now().timestamp()))
non_expired = []
for res in search_res:
if res["expires"] < now:
continue
non_expired.append(res)
if res["expires"] == "" or res["expires"] > now:
non_expired.append(res)
if len(non_expired) == 0:
click.secho("A fingerprint with the key could not be found.")
sys.exit(1)
if len(non_expired) == 1:
return non_expired[0]["keyid"]
for idx, res in enumerate(non_expired):
click.echo(
"{idx}) {fingerprint} {uid}".format(
idx=idx, fingerprint=res["keyid"], uid=res["uids"][0]
"{idx}) {fingerprint} {uid} - Created: {created}".format(
idx=idx,
fingerprint=res["keyid"],
uid=res["uids"][0],
created=datetime.utcfromtimestamp(int(res["date"])).strftime('%m/%d/%Y %H:%M:%S')
)
)
num = len(non_expired)
value = int(input("Please select a key to add: "))
if value > num:
try:
value = int(input("Please select a key to add: "))
if value > num:
click.secho("Invalid number, exiting")
sys.exit(1)
except:
click.secho("Invalid number, exiting")
sys.exit(1)
return non_expired[value]["keyid"]
Expand Down
Loading

0 comments on commit f7e5fde

Please sign in to comment.