-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokenmanager.py
More file actions
62 lines (48 loc) · 2.1 KB
/
tokenmanager.py
File metadata and controls
62 lines (48 loc) · 2.1 KB
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
import configparser
import os
from pathlib import Path
CONFIG_FILE_NAME = ".mojimanjerconfig"
def add_command_args(argparser):
argparser.add_argument("--token", "-t",
help="Api token, xoxs token required for upload. Grab it from your headers when uploading manually",
action='store', required=False)
argparser.add_argument("--workspace", "-w", action='store', required=False,
help="Section from config to use and directory to output to")
argparser.add_argument("--configfile", action='store', required=False,
help="Path to config file. Defaults (~/.mojimanjerconfig)",
default=os.path.join(Path.home(), CONFIG_FILE_NAME))
def get_token(workspace, token, configfile):
token_result = None
if token:
token_result = token
if workspace:
print(configfile)
config = configparser.ConfigParser()
if not token_result:
config.read(configfile)
if workspace in config:
token_result = config[workspace]["token"]
if token_result:
if workspace not in config:
config[workspace] = {}
if "token" not in config[workspace] or token_result != config[workspace]["token"]:
config[workspace]["token"] = token_result
with open(configfile, 'w') as configfileupdate:
config.write(configfileupdate)
if not token_result and not workspace:
config = configparser.ConfigParser()
config.read(configfile)
if "default" in config:
token_result = config["default"]["token"]
if not token_result:
print("\nNo token provided or found in " + configfile)
print("""
Example config:
[default]
token = xoxs-1111111-111111111111...
[thegoodplace]
token = xoxs-946546546544-654656454659-968498546566-...
[thebadplace]
token = xoxp-998713211087-987979841210-306546506974-...
""")
return token_result