-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathghe2json.py
executable file
·181 lines (137 loc) · 4.15 KB
/
ghe2json.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env python3
"""
ghe2json command line tool to convert gheboot output to json.
"""
import string
import argparse
import logging
import logging.config
import thepower
import json
import pprint
def generate_template(environment):
e = json.loads(environment)
values = {}
values['hostname'] = e['hostname']
values['password_recovery'] = e['password_recovery']
values['ip_replica'] = e['ip_replica'] or None
t = string.Template(r"""H=$hostname
U=admin
replica_ip=$ip_replica
I=$U@$H
export U H I
function ch() {
# Start chrome with one the profiles you can list below:
# ls -l ~/Library/Application\ Support/Google/Chrome/
# You will need to work out which profile is wich person
open -n -a "Google Chrome" --args --profile-directory="Profile 19" "http://$H"
}
function chrepo() {
# Start chrome with one the profiles you can list below:
# ls -l ~/Library/Application\ Support/Google/Chrome/
# You will need to work out which profile is wich person
. ./.gh-api-examples.conf
open -n -a "Google Chrome" --args --profile-directory="Profile 19" "http://$H/$org/$repo"
}
function chmona() {
# In this on my mona user has a Profile 20:
open -n -a "Google Chrome" --args --profile-directory="Profile 20" "http://$H"
}
function ffx() {
open -a "Firefox" "http://$H"
}
function edg() {
open -a "Microsoft Edge" "http://$H"
}
function ve() {
cat .ghe
}
function pa() {
# This runs the ssh command on line 7 of the ghe output
# to fetch the password from the ghe server.
$password_recovery
}
function st() {
# SSH onto the ghe server
>&2 echo ssh to: $I
ssh -o StrictHostKeyChecking=no -p122 $I
}
function sr() {
# SSH onto the ghe server
>&2 echo ssh to: $replica_ip
ssh -o StrictHostKeyChecking=no -p122 admin@$replica_ip
}
export PATH="/usr/local/opt/curl/bin:$PATH"
export PS1="%m %F{yellow}:%1~%f $ "
""")
return t.safe_substitute(values)
def main(args):
text = ""
if args.ghe_file == False:
message="""Please paste below the output from gheboot informing you that the
appliance is ready (optionally paste in a token for an admin user
with all scopes set). When that's done press the return key twice to proceed:\n"""
thepower.clear_screen()
print(f"\033[93m\n\n{message}\033[0m\n")
lines = []
while True:
line = input()
if line:
lines.append(line)
else:
break
text = '\n'.join(lines)
else:
# assume the file exists
with open(args.ghe_file, "r") as f:
text = f.read()
environment = (thepower.ghe2json(text))
with open(args.environment_file, "w") as f:
f.write(environment)
t = generate_template(environment)
with open('shell-profile', 'w') as f:
f.write(t)
print(f"\033[92m")
print("\n")
thepower.print_progress_bar()
print(f"""\n\nConverted Hubot output to "{args.environment_file}" file:\n""")
with open(args.environment_file, "r") as f:
j = json.loads(f.read())
pprint.pprint(j)
print(f"{'='*80}")
print("\n")
message = """To create a PAT quick. In Chrome Open the developer console (Option + Command J):
$$('input[type="checkbox"').map(i => i.checked = true)
"""
print(f"\033[93m\n\n{message}\033[0m\n")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--ghe-file",
action="store",
dest="ghe_file",
default=False,
)
parser.add_argument(
"--environment-file",
action="store",
dest="environment_file",
default="environment.json",
)
parser.add_argument(
"-l",
"--loglevel",
action="store",
dest="loglevel",
default="info",
help="Set the log level",
)
args = parser.parse_args()
logging.basicConfig(level=logging.INFO)
logging.getLogger().handlers.clear()
logger = logging.getLogger(__name__)
console_handler = logging.StreamHandler()
console_handler.setLevel(args.loglevel.upper())
logger = logging.getLogger(__name__)
logger.addHandler(console_handler)
main(args)