Browse Source

Improve virtualenv and installation

python
IamTheFij 3 years ago
parent
commit
62c393ffe3
  1. 1
      .gitignore
  2. 0
      8486DCAA-AFB7-407D-A0E9-E57E09997B24.png
  3. 60
      Makefile
  4. 34
      README.md
  5. 0
      alfred_yauth/__init__.py
  6. 2
      alfred_yauth/controller.py
  7. 3
      alfred_yauth/main.py
  8. 0
      alfred_yauth/version
  9. 0
      icon.png
  10. 40
      info.plist
  11. 8
      replace-workflow.sh
  12. 4
      set_version.sh
  13. 5
      vendor.py

1
.gitignore

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

0
src/8486DCAA-AFB7-407D-A0E9-E57E09997B24.png → 8486DCAA-AFB7-407D-A0E9-E57E09997B24.png

Before

Width: 512  |  Height: 512  |  Size: 239 KiB

After

Width: 512  |  Height: 512  |  Size: 239 KiB

60
Makefile

@ -1,51 +1,47 @@
.PHONY: default
default: run
# Simple execution of the workflow to see all results
.PHONY: run
run: install-requirements
./src/main.py
.PHONY: build
build: venv install-ports
# Runs workflow and prompts for Yubikey password
.PHONY: set-password
set-password: install-requirements
./src/main.py set-password
.PHONY: install
install: venv
./replace-workflow.sh
.PHONY: install-requirements
install-requirements: src/vendor src/libusb-1.0.dylib
Yauth.alfredWorkflow: venv
mkdir Yauth.alfredWorkflow
cp -r alfred_yauth Yauth.alfredworkflow/
cp -r venv Yauth.alfredWorkflow/
cp info.plist Yauth.alfredWorkflow/
cp icon.png Yauth.alfredWorkflow/
# Installs libusb from /opt/local, where MacPorts installs it
src/libusb-1.0.dylib:
cp /opt/local/lib/libusb-1.0.dylib ./src/
# Installs required MacPorts
.PHONY: install-ports
install-ports:
sudo port install swig swig-python ykpers libu2f-host libusb
# 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 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
# Creates virtualenv for testing using MacPorts Python
virtualenv:
virtualenv --python=/opt/local/bin/python2.7 virtualenv
./virtualenv_run/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 using virtualenv Python
.PHONY: virtualenv_run
virtualenv_run: virtualenv
./virtualenv/bin/python src/main.py
# 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 virtualenv src/vendor src/libusb-1.0.dylib
rm -fr venv Yauth.alfredWorkflow
find . -name '*.pyc' -delete
find . -name '__pycache__' -delete
# Installs required MacPorts
.PHONY: install-ports
install-ports:
sudo port install swig swig-python ykpers libu2f-host libusb
# Install precommit hooks
.PHONY: intall-hooks
install-hooks:

34
README.md

@ -1,19 +1,37 @@
Alfred Yubico Auth
==================
# Alfred Yubico Auth
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.
* 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.
* 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
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

0
alfred_yauth/__init__.py

2
src/controller.py → alfred_yauth/controller.py

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

3
src/main.py → alfred_yauth/main.py

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

0
src/version → alfred_yauth/version

0
src/icon.png → icon.png

Before

Width: 512  |  Height: 512  |  Size: 239 KiB

After

Width: 512  |  Height: 512  |  Size: 239 KiB

40
src/info.plist → info.plist

@ -92,6 +92,23 @@
<string>Yubico Auth</string>
<key>objects</key>
<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>
<key>config</key>
<dict>
@ -113,23 +130,6 @@
<key>version</key>
<integer>1</integer>
</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>
<key>config</key>
<dict>
@ -173,6 +173,8 @@
<dict>
<key>alfredfiltersresults</key>
<true/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
@ -192,7 +194,7 @@
<key>runningsubtext</key>
<string></string>
<key>script</key>
<string>python main.py</string>
<string>./venv/bin/python -m alfred_yauth.main</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
@ -202,7 +204,7 @@
<key>title</key>
<string>Yubikey 2FA</string>
<key>type</key>
<integer>8</integer>
<integer>0</integer>
<key>withspace</key>
<true/>
</dict>

8
replace-workflow.sh

@ -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"

4
set_version.sh

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

5
vendor.py

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