bumblebee-status/modules/contrib/yubikey.py

36 lines
910 B
Python
Raw Normal View History

2020-04-13 09:32:41 +02:00
# pylint: disable=C0111,R0903
"""Shows yubikey information
Requires: https://github.com/Yubico/python-yubico
The output indicates that a YubiKey is not connected or it displays
the corresponding serial number.
"""
import yubico
2020-04-13 09:40:24 +02:00
import core.module
import core.widget
import core.decorators
2020-04-13 09:32:41 +02:00
2020-04-13 09:40:24 +02:00
class Module(core.module.Module):
@core.decorators.every(seconds=5)
2020-04-13 09:40:24 +02:00
def __init__(self, config):
super().__init__(config, core.widget.Widget(self.keystate))
self.__keystate = 'No YubiKey'
2020-04-13 09:32:41 +02:00
def keystate(self, widget):
2020-04-13 09:40:24 +02:00
return self.__keystate
2020-04-13 09:32:41 +02:00
2020-04-13 09:40:24 +02:00
def update(self):
2020-04-13 09:32:41 +02:00
try:
2020-04-13 09:40:24 +02:00
self.__keystate = "YubiKey: " + str(yubico.find_yubikey(debug=False).serial())
2020-04-13 09:32:41 +02:00
except yubico.yubico_exception.YubicoError:
2020-04-13 09:40:24 +02:00
self.__keystate = "No YubiKey"
except Exception:
self.__keystate = 'n/a'
2020-04-13 09:32:41 +02:00
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4