-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpie-nsof-setup
More file actions
executable file
·40 lines (32 loc) · 1.14 KB
/
httpie-nsof-setup
File metadata and controls
executable file
·40 lines (32 loc) · 1.14 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
#!/usr/bin/python
import getpass
import json
import sys
import os
is_windows = 'win32' in str(sys.platform).lower()
conf_dir = str(os.getenv(
'HTTPIE_CONFIG_DIR',
os.path.expanduser('~/.httpie' if not is_windows else r'%APPDATA%\\httpie')
))
conf_path = os.path.join(conf_dir, "config.json")
prompt = '>> '
user_input = input if sys.version_info > (3, 0) else raw_input
print("Welcome to Nsof's HTTPie setup")
print("Please enter your organization's shortname")
org = user_input(prompt)
print("Please enter your Nsof login username (email address) or API key ID:")
username = user_input(prompt)
if '@' not in username and 'key-' not in username:
print("httpie-nsof error: invalid username format or "
"invalid API key ID format")
exit(1)
print("Please enter your Nsof login password or API key secret:")
password = getpass.getpass(prompt)
default_options = ["--auth=%s/%s:%s" % (org, username, password)]
conf = {"default_options": default_options}
if not os.path.exists(conf_dir):
os.makedirs(conf_dir)
with open(conf_path, 'w') as f:
json.dump(conf, f, indent=4)
f.write('\n')
print("Updated %s successfully" % conf_path)