-
Notifications
You must be signed in to change notification settings - Fork 0
/
yubikey_manager_repl.py
43 lines (37 loc) · 1.11 KB
/
yubikey_manager_repl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import io
import logging
import warnings
import contextlib
import json
from cryptography.utils import CryptographyDeprecationWarning
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=CryptographyDeprecationWarning)
import ykman._cli.__main__
# Restore logger, set by ykman.cli.__main__ import
logging.disable(logging.NOTSET)
def main():
"""
Main function, make ykman calls without restarting the python process
Reads input in JSON format
Returns output in JSON output
"""
while 1:
line = input()
if not line:
break
stdout = io.StringIO()
stderr = io.StringIO()
with contextlib.redirect_stderr(stderr), contextlib.redirect_stdout(stdout):
try:
ykman._cli.__main__.cli.main(args=json.loads(line))
except SystemExit:
pass
print(
json.dumps(
{
"stdout": stdout.getvalue().splitlines(),
"stderr": stderr.getvalue().splitlines(),
}
),
flush=True,
)