-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
65 lines (52 loc) · 1.59 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
import json
import os
import sys
import jwt
ICON_ROOT = '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources'
ICON_ERROR = os.path.join(ICON_ROOT, 'AlertStopIcon.icns')
ICON_INFO = "jwt.png"
class WorkFlow:
def __init__(self):
self.items = []
def add_item(
self, title: str, subtitle: str,
arg: str, autocomplete: str, icon: str=ICON_INFO
):
self.items.append(
{
"uid": "desktop",
"type": "string",
"title": title,
"subtitle": subtitle,
"arg": arg,
"autocomplete": autocomplete,
"icon": icon,
}
)
def run(self, args: str):
if len(args.split('.')) == 2:
args = "{}.xxxx".format(args)
elif len(args.split('.')) == 1:
args = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.{}.xxxx".format(args)
try:
res = jwt.decode(
args,
"secret",
algorithms=["HS256"],
options={"verify_signature": False},
issuer="auth",
verify=False
)
except Exception as e:
self.add_item(str(e), "Error", "", "", ICON_ERROR)
else:
for key, value in res.items():
value = str(value)
self.add_item(value, key, value, value)
json.dump({"items": self.items}, sys.stdout)
sys.stdout.flush()
if __name__ == '__main__':
s = sys.argv
wf = WorkFlow()
wf.run(s[1])