@@ -59,16 +59,16 @@ def build(self):
59
59
self .lowest_level = 2
60
60
display = False
61
61
elif self .level == 2 :
62
- if not (self .args .username or self .args .password or
63
- self .args .session_id or self .args .session_file or self .args .root ):
62
+ if not (self .args .api_key or self . args . username or self .args .password or
63
+ self .args .session_id or self .args .session_file or self .args .root ):
64
64
self .title = "Please select a login method:"
65
65
self .options = ["Enter user credentials manually" , "Login as Root" ,
66
66
"Use an existing session file" , "Use an existing session UID" ]
67
67
self .last_option = "Back"
68
68
else :
69
69
if self .args .root :
70
70
self .self_args .login = '2'
71
- elif self .args .username or self .args .password :
71
+ elif self .args .username or self .args .password or self . args . api_key :
72
72
self .self_args .login = '1'
73
73
elif self .args .session_file :
74
74
self .self_args .login = '3'
@@ -80,10 +80,13 @@ def build(self):
80
80
elif self .level == 3 and self .export :
81
81
if not self .args .force :
82
82
self .title = "The script will run with the following parameters:\n " + \
83
- "Export Access-Control layers = " + str (self .self_args .access or self .self_args .all ) + "\n " + \
83
+ "Export Access-Control layers = " + str (
84
+ self .self_args .access or self .self_args .all ) + "\n " + \
84
85
"Export NAT layers = " + str (self .self_args .nat or self .self_args .all ) + "\n " + \
85
- "Export Threat-Prevention layers = " + str (self .self_args .threat or self .self_args .all ) + "\n " + \
86
- "Export HTTPS Inspection layers = " + str (self .self_args .https or self .self_args .all ) + "\n " + \
86
+ "Export Threat-Prevention layers = " + str (
87
+ self .self_args .threat or self .self_args .all ) + "\n " + \
88
+ "Export HTTPS Inspection layers = " + str (
89
+ self .self_args .https or self .self_args .all ) + "\n " + \
87
90
"Output-file name = " + str (self .self_args .output_file ) + "\n " + \
88
91
"Management Server IP = " + str (self .self_args .management ) + "\n " + \
89
92
"Management Server Port = " + str (self .self_args .port ) + "\n " + \
@@ -129,19 +132,14 @@ def build(self):
129
132
"Change Management Server Port" , "Change the domain name" ]
130
133
self .last_option = "Exit" if self .level == self .lowest_level else "Back"
131
134
elif self .level == 5 :
132
- if not self .args .username :
133
- self .title = "Please enter your username:"
134
- self .options = []
135
+ if not self .self_args .api_key and not self .self_args .username and not self .self_args .password :
136
+ self .title = "Please select authentication method:"
137
+ self .options = ["Username & Password" ,
138
+ "API Key" ]
139
+ self .last_option = "Exit" if self .level == self .lowest_level else "Back"
135
140
else :
136
- self .level = 6
137
- display = False
138
- elif self .level == 6 :
139
- if not self .args .password :
140
- # The menu title will be provided at the password prompt
141
141
self .title = ""
142
142
self .options = []
143
- else :
144
- return
145
143
if display :
146
144
self .display ()
147
145
else :
@@ -212,7 +210,8 @@ def handle_input(self):
212
210
elif choice == 2 :
213
211
self .self_args .threat = not self .self_args .threat
214
212
self .menu_print (
215
- "Exporting of Threat-Prevention layers " + "enabled" if self .self_args .threat else "disabled" , 2 )
213
+ "Exporting of Threat-Prevention layers " + "enabled" if self .self_args .threat else "disabled" ,
214
+ 2 )
216
215
elif choice == 3 :
217
216
self .self_args .nat = not self .self_args .nat
218
217
self .menu_print (
@@ -255,17 +254,39 @@ def handle_input(self):
255
254
except ValueError :
256
255
self .display_wrong_choice ()
257
256
elif self .level == 5 :
258
- if not self .self_args .username :
259
- self .self_args .username = input ()
260
- self .level = 6
261
- elif self .level == 6 :
262
- if not self .self_args .password :
263
- if sys .stdin .isatty ():
264
- self .self_args .password = getpass .getpass ("Please enter your password:\n " )
257
+ try :
258
+ choice = None
259
+ if self .self_args .username or self .self_args .password :
260
+ choice = 1
261
+ elif self .self_args .api_key :
262
+ choice = 2
265
263
else :
266
- print ("Attention! Your password will be shown on the screen!" , file = sys .stderr )
267
- self .self_args .password = input ("Please enter your password:\n " )
268
- return
264
+ choice = int (input ())
265
+ if choice == 1 :
266
+ if not self .self_args .username :
267
+ self .menu_print ("Please enter your username:" , 0 )
268
+ self .self_args .username = input ()
269
+ if not self .self_args .password :
270
+ if sys .stdin .isatty ():
271
+ self .self_args .password = getpass .getpass ("Please enter your password:\n " )
272
+ else :
273
+ print ("Attention! Your password will be shown on the screen!" , file = sys .stderr )
274
+ self .self_args .password = input ("Please enter your password:\n " )
275
+ return
276
+ elif choice == 2 :
277
+ if not self .self_args .api_key :
278
+ if sys .stdin .isatty ():
279
+ self .self_args .api_key = getpass .getpass ("Please enter your API key:\n " )
280
+ else :
281
+ print ("Attention! Your API key will be shown on the screen!" , file = sys .stderr )
282
+ self .self_args .api_key = input ("Please enter your API key:\n " )
283
+ return
284
+ elif choice == 99 :
285
+ self .level = 3
286
+ else :
287
+ self .display_wrong_choice ()
288
+ except ValueError :
289
+ self .display_wrong_choice ()
269
290
self .build ()
270
291
271
292
def display_wrong_choice (self ):
0 commit comments