uncloud-cli/commands/helper.py

21 lines
531 B
Python
Raw Normal View History

import json
2019-07-17 14:58:39 +00:00
from pyotp import TOTP
class OTPCredentials:
2019-09-13 12:33:19 +00:00
def __init__(self, name, realm, seed):
self.name = name # type: str
self.realm = realm # type: str
self.seed = seed # type: str
2019-07-17 14:58:39 +00:00
def get_json(self):
2019-09-13 12:33:19 +00:00
return {"name": self.name, "realm": self.realm, "token": TOTP(self.seed).now()}
def load_dump_pretty(content):
2019-10-15 15:26:46 +00:00
if isinstance(content, bytes):
content = content.decode("utf-8")
parsed = json.loads(content)
2019-09-13 12:33:19 +00:00
return json.dumps(parsed, indent=4, sort_keys=True)