Improve virtualenv and installation

This commit is contained in:
IamTheFij 2018-04-12 15:55:55 -07:00
parent 0b599cfd37
commit 62c393ffe3
13 changed files with 92 additions and 75 deletions

1
.gitignore vendored
View File

@ -73,3 +73,4 @@ virtualenv_run/
src/vendor/ src/vendor/
src/libusb-1.0.dylib src/libusb-1.0.dylib
*.pyc *.pyc
venv

View File

Before

Width:  |  Height:  |  Size: 239 KiB

After

Width:  |  Height:  |  Size: 239 KiB

View File

@ -1,51 +1,47 @@
.PHONY: default .PHONY: default
default: run default: run
# Simple execution of the workflow to see all results .PHONY: build
.PHONY: run build: venv install-ports
run: install-requirements
./src/main.py
# Runs workflow and prompts for Yubikey password .PHONY: install
.PHONY: set-password install: venv
set-password: install-requirements ./replace-workflow.sh
./src/main.py set-password
.PHONY: install-requirements Yauth.alfredWorkflow: venv
install-requirements: src/vendor src/libusb-1.0.dylib mkdir Yauth.alfredWorkflow
cp -r alfred_yauth Yauth.alfredworkflow/
# Installs libusb from /opt/local, where MacPorts installs it cp -r venv Yauth.alfredWorkflow/
src/libusb-1.0.dylib: cp info.plist Yauth.alfredWorkflow/
cp /opt/local/lib/libusb-1.0.dylib ./src/ cp icon.png Yauth.alfredWorkflow/
# Installs 3rd party packages into vendor directory
src/vendor:
mkdir -p .pip-cache
pip install -r ./requirements.txt -t ./src/vendor --cache-dir .pip-cache
cp vendor.py src/vendor/__init__.py
# Creates virtualenv for testing using MacPorts Python
virtualenv:
virtualenv --python=/opt/local/bin/python2.7 virtualenv
./virtualenv_run/bin/pip install -r ./requirements.txt
# Runs workflow using virtualenv Python
.PHONY: virtualenv_run
virtualenv_run: virtualenv
./virtualenv/bin/python src/main.py
# Clears the virtualenv and other installed files
.PHONY: clean
clean:
rm -fr virtualenv src/vendor src/libusb-1.0.dylib
find . -name '*.pyc' -delete
find . -name '__pycache__' -delete
# Installs required MacPorts # Installs required MacPorts
.PHONY: install-ports .PHONY: install-ports
install-ports: install-ports:
sudo port install swig swig-python ykpers libu2f-host libusb sudo port install swig swig-python ykpers libu2f-host libusb
# Creates venv using MacPorts Python (Required for it to refrence libusb)
venv:
virtualenv --python=/opt/local/bin/python2.7 venv
./venv/bin/pip install -r ./requirements.txt
# Simple execution of the workflow to see all results
.PHONY: run
run: venv
@./venv/bin/python -m alfred_yauth.main
# Runs workflow and prompts for Yubikey password
.PHONY: set-password
set-password: venv
@./venv/bin/python -m alfred_yauth.main set-password
# Clears the virtualenv and other installed files
.PHONY: clean
clean:
rm -fr venv Yauth.alfredWorkflow
find . -name '*.pyc' -delete
find . -name '__pycache__' -delete
# Install precommit hooks # Install precommit hooks
.PHONY: intall-hooks .PHONY: intall-hooks
install-hooks: install-hooks:

View File

@ -1,19 +1,37 @@
Alfred Yubico Auth # Alfred Yubico Auth
==================
An Alfred Workflow for auto filling authentication codes stored on your Yubikey. An Alfred Workflow for auto filling authentication codes stored on your Yubikey.
Notes ## Notes
-----
This is definitely a work in progress. There are a lot of rough edges yet to be polished, but here it goes. This is definitely a work in progress. There are a lot of rough edges yet to be polished, but here it goes.
* Requires some to be installed with a package manager
* There is no way to input your key password through the UI yet. Do that with `make set-password` and then it should work fine. * There is no way to input your key password through the UI yet. Do that with `make set-password` and then it should work fine.
* Does not bundle dylibs for you. Hanve't quite figured out what needs to be done to make this portable
* Requires MacPorts to install dependencies
* Error handling is terrible right now. If things don't work, check the debug log in Alfred * Error handling is terrible right now. If things don't work, check the debug log in Alfred
Credits ## Installation
-------
Clone this repo
```bash
git clone https://git.iamthefij.com/iamthefij/alfred-yubico-auth.git
```
Either install your dependencies manually or, if you have MacPorts, you can use:
```bash
make install-ports
```
Otherwise you need to install `swig swig-python ykpers libu2f-host libusb` some other way.
Finally up the virtualenv and install to your Alfred with
```bash
make install
```
## Credits
Uses the amazing [deanishe/alfred-workflow](https://github.com/deanishe/alfred-workflow) package Uses the amazing [deanishe/alfred-workflow](https://github.com/deanishe/alfred-workflow) package

0
alfred_yauth/__init__.py Normal file
View File

View File

@ -13,8 +13,6 @@ from ykman.util import derive_key
from ykman.util import parse_b32_key from ykman.util import parse_b32_key
from ykman.util import TRANSPORT from ykman.util import TRANSPORT
import vendor # noqa
NON_FEATURE_CAPABILITIES = [CAPABILITY.CCID, CAPABILITY.NFC] NON_FEATURE_CAPABILITIES = [CAPABILITY.CCID, CAPABILITY.NFC]

3
src/main.py → alfred_yauth/main.py Executable file → Normal file
View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys import sys
from getpass import getpass from getpass import getpass
@ -108,7 +107,7 @@ class YubicoAuth(Workflow3):
command_action = None command_action = None
if command == 'set-password': if command == 'set-password':
command_action = self.ask_yubikey_password command_action = self.ask_yubikey_password
if command == 'list': elif command == 'list':
command_action = self.list_credentials command_action = self.list_credentials
else: else:
command_action = self.refresh_credentials command_action = self.refresh_credentials

View File

Before

Width:  |  Height:  |  Size: 239 KiB

After

Width:  |  Height:  |  Size: 239 KiB

View File

@ -92,6 +92,23 @@
<string>Yubico Auth</string> <string>Yubico Auth</string>
<key>objects</key> <key>objects</key>
<array> <array>
<dict>
<key>config</key>
<dict>
<key>autopaste</key>
<false/>
<key>clipboardtext</key>
<string>{query}</string>
<key>transient</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.output.clipboard</string>
<key>uid</key>
<string>9F48DDE6-BBE7-42ED-ABE5-C9255C92F1CD</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict> <dict>
<key>config</key> <key>config</key>
<dict> <dict>
@ -113,23 +130,6 @@
<key>version</key> <key>version</key>
<integer>1</integer> <integer>1</integer>
</dict> </dict>
<dict>
<key>config</key>
<dict>
<key>autopaste</key>
<false/>
<key>clipboardtext</key>
<string>{query}</string>
<key>transient</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.output.clipboard</string>
<key>uid</key>
<string>9F48DDE6-BBE7-42ED-ABE5-C9255C92F1CD</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict> <dict>
<key>config</key> <key>config</key>
<dict> <dict>
@ -173,6 +173,8 @@
<dict> <dict>
<key>alfredfiltersresults</key> <key>alfredfiltersresults</key>
<true/> <true/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttrimmode</key> <key>argumenttrimmode</key>
<integer>0</integer> <integer>0</integer>
<key>argumenttype</key> <key>argumenttype</key>
@ -192,7 +194,7 @@
<key>runningsubtext</key> <key>runningsubtext</key>
<string></string> <string></string>
<key>script</key> <key>script</key>
<string>python main.py</string> <string>./venv/bin/python -m alfred_yauth.main</string>
<key>scriptargtype</key> <key>scriptargtype</key>
<integer>1</integer> <integer>1</integer>
<key>scriptfile</key> <key>scriptfile</key>
@ -202,7 +204,7 @@
<key>title</key> <key>title</key>
<string>Yubikey 2FA</string> <string>Yubikey 2FA</string>
<key>type</key> <key>type</key>
<integer>8</integer> <integer>0</integer>
<key>withspace</key> <key>withspace</key>
<true/> <true/>
</dict> </dict>

8
replace-workflow.sh Executable file
View File

@ -0,0 +1,8 @@
#! /bin/bash
set -e
echo "Warning! This will remove the workflow at the provided path and replace it with a link to this directory"
read -p "Path to workflow to replace: " existing_workflow
rm -fr "$existing_workflow"
ln -s `pwd` "$existing_workflow"

View File

@ -1,4 +1,4 @@
#! /bin/bash #! /bin/bash
echo "$1" > ./src/version echo "$1" > ./alfred_yauth/version
plutil -replace version -string "$1" ./src/info.plist plutil -replace version -string "$1" ./info.plist

View File

@ -1,5 +0,0 @@
import os
import sys
sys.path.append(os.path.basename(__file__))