From 136ce6e4b0e3db5e594f2c61b41335c3a77afc53 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 18 May 2016 22:19:01 +0100 Subject: [PATCH] List yubikeys --- yubi_lock/api/__init__.py | 0 yubi_lock/api/yubikey.py | 14 ++++++++++++++ yubi_lock/status/__init__.py | 0 yubi_lock/status/cli.py | 10 ++++++++++ 4 files changed, 24 insertions(+) create mode 100644 yubi_lock/api/__init__.py create mode 100644 yubi_lock/api/yubikey.py create mode 100644 yubi_lock/status/__init__.py create mode 100644 yubi_lock/status/cli.py diff --git a/yubi_lock/api/__init__.py b/yubi_lock/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/yubi_lock/api/yubikey.py b/yubi_lock/api/yubikey.py new file mode 100644 index 0000000..4d0cf65 --- /dev/null +++ b/yubi_lock/api/yubikey.py @@ -0,0 +1,14 @@ +import yubico + + +def get_all_yubikeys(debug): + keys = [] + try: + skip = 0 + while skip < 255: + key = yubico.find_yubikey(debug=debug, skip=skip) + keys.append(key) + skip += 1 + except yubico.yubikey.YubiKeyError: + pass + return keys diff --git a/yubi_lock/status/__init__.py b/yubi_lock/status/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/yubi_lock/status/cli.py b/yubi_lock/status/cli.py new file mode 100644 index 0000000..17daff6 --- /dev/null +++ b/yubi_lock/status/cli.py @@ -0,0 +1,10 @@ +import click +from yubi_lock.api.yubikey import get_all_yubikeys + + +@click.command('status', short_help='List connected devices.') +def cli(): + print('Scanning for keys...') + keys = get_all_yubikeys(False) + for key in keys: + print("Found {}!".format(key.description))