Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -145,27 +145,17 @@ with gr.Blocks(
|
|
| 145 |
opacity: 0.5;
|
| 146 |
pointer-events: none;
|
| 147 |
}
|
| 148 |
-
.
|
| 149 |
-
position: fixed;
|
| 150 |
-
top: 50%;
|
| 151 |
-
left: 50%;
|
| 152 |
-
transform: translate(-50%, -50%);
|
| 153 |
-
background: rgba(255, 255, 255, 0.95);
|
| 154 |
-
padding: 20px 40px;
|
| 155 |
-
border-radius: 10px;
|
| 156 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 157 |
-
z-index: 1000;
|
| 158 |
-
text-align: center;
|
| 159 |
-
font-size: 1.2em;
|
| 160 |
-
}
|
| 161 |
-
.overlay-background {
|
| 162 |
position: fixed;
|
| 163 |
top: 0;
|
| 164 |
left: 0;
|
| 165 |
width: 100%;
|
| 166 |
height: 100%;
|
| 167 |
-
background: rgba(
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
| 169 |
}
|
| 170 |
"""
|
| 171 |
) as demo:
|
|
@@ -309,48 +299,10 @@ with gr.Blocks(
|
|
| 309 |
gr.update(visible=visibilities[2])
|
| 310 |
]
|
| 311 |
|
| 312 |
-
loading_overlay = gr.HTML(
|
| 313 |
-
visible=False,
|
| 314 |
-
value='''
|
| 315 |
-
<div class="overlay-background"></div>
|
| 316 |
-
<div class="processing-popup">
|
| 317 |
-
⏳ Processing Endpoints...
|
| 318 |
-
</div>
|
| 319 |
-
'''
|
| 320 |
-
)
|
| 321 |
-
|
| 322 |
-
# Add validation function for enabling/disabling Call API button
|
| 323 |
-
def validate_inputs(spec_choice, api_base_url, grant_type, client_id, client_secret,
|
| 324 |
-
api_token, iiq_username, iiq_password, *param_values):
|
| 325 |
-
"""Validate all required inputs to enable/disable Call API button"""
|
| 326 |
-
if not api_base_url.strip():
|
| 327 |
-
return gr.update(interactive=False)
|
| 328 |
-
|
| 329 |
-
# Validate auth fields based on API choice
|
| 330 |
-
if spec_choice == "Okta (JSON)":
|
| 331 |
-
if not api_token:
|
| 332 |
-
return gr.update(interactive=False)
|
| 333 |
-
elif spec_choice == "SailPoint IdentityNow (YAML)":
|
| 334 |
-
if not all([grant_type, client_id, client_secret]):
|
| 335 |
-
return gr.update(interactive=False)
|
| 336 |
-
elif spec_choice == "Sailpoint IIQ (YAML)":
|
| 337 |
-
if not all([iiq_username, iiq_password]):
|
| 338 |
-
return gr.update(interactive=False)
|
| 339 |
|
| 340 |
-
# Validate parameter inputs if they're visible
|
| 341 |
-
param_inputs = param_values[:len(param_components)]
|
| 342 |
-
param_displays = [comp[1].value for comp in param_components]
|
| 343 |
-
|
| 344 |
-
for display, value in zip(param_displays, param_inputs):
|
| 345 |
-
if display and display.visible and not value.strip():
|
| 346 |
-
return gr.update(interactive=False)
|
| 347 |
-
|
| 348 |
-
return gr.update(interactive=True)
|
| 349 |
-
|
| 350 |
def confirm_selected_endpoints(spec_choice, *checkbox_values):
|
| 351 |
"""Collect and confirm all selected endpoints"""
|
| 352 |
-
#gr.update(visible=True)(loading_overlay)
|
| 353 |
-
header_text = "### Parameters Required"
|
| 354 |
all_selected = []
|
| 355 |
for checkbox_group in checkbox_values:
|
| 356 |
if isinstance(checkbox_group, list) and checkbox_group:
|
|
@@ -361,8 +313,6 @@ with gr.Blocks(
|
|
| 361 |
[], # display_values_state
|
| 362 |
gr.update(visible=False), # param_group
|
| 363 |
gr.update(value="❌ No endpoints selected", visible=True), # param_header
|
| 364 |
-
gr.update(visible=True), # loading_overlay - show processing message
|
| 365 |
-
gr.update(visible=False), # call_api_btn
|
| 366 |
*[gr.update(visible=False) for _ in range(15)]) # 5 sets of 3 components each
|
| 367 |
|
| 368 |
# Get the API spec
|
|
@@ -388,103 +338,62 @@ with gr.Blocks(
|
|
| 388 |
required_params_count += len(path_params) + len(query_params)
|
| 389 |
|
| 390 |
# Create updates for all components
|
| 391 |
-
updates = [
|
| 392 |
-
endpoints_with_params, # confirmed_endpoints_state
|
| 393 |
-
display_values, # display_values_state
|
| 394 |
-
]
|
| 395 |
updates.append(endpoints_with_params) # confirmed_endpoints_state
|
| 396 |
updates.append(display_values) # display_values_state
|
| 397 |
-
updates.append(gr.update(visible=bool(required_params_count))) # param_group
|
| 398 |
-
updates.append(gr.update(value=header_text, visible=True)) # param_header
|
| 399 |
-
updates.append(gr.update(visible=False)) # loading_overlay - hide when done
|
| 400 |
-
updates.append(gr.update(visible=True)) # call_api_btn
|
| 401 |
|
| 402 |
if not required_params_count:
|
|
|
|
|
|
|
| 403 |
updates.append(gr.update(value="✅ No parameters required. You can proceed to call the API.",
|
| 404 |
visible=True)) # param_header
|
|
|
|
| 405 |
else:
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
|
| 411 |
# Then create updates for each parameter component
|
| 412 |
-
|
| 413 |
param_index = 0
|
| 414 |
for endpoint, path_params, query_params in endpoints_with_params:
|
| 415 |
# Handle path parameters
|
| 416 |
for param_name in path_params:
|
| 417 |
if param_index < 5:
|
| 418 |
updates.extend([
|
|
|
|
| 419 |
gr.update(visible=True,
|
| 420 |
-
value=f"Endpoint: {endpoint} - Path Parameter (Required)"),
|
| 421 |
gr.update(visible=True,
|
| 422 |
label=f"🔑 Enter path parameter: {param_name}",
|
| 423 |
-
placeholder=f"Required path parameter for {endpoint}")
|
| 424 |
])
|
| 425 |
param_index += 1
|
| 426 |
|
| 427 |
-
# Handle query parameters
|
| 428 |
for _, name, required, description in query_params:
|
| 429 |
if required and param_index < 5:
|
| 430 |
updates.extend([
|
| 431 |
-
gr.update(visible=True,
|
| 432 |
-
|
|
|
|
| 433 |
gr.update(visible=True,
|
| 434 |
label=f"🔍 Enter query parameter: {name}",
|
| 435 |
-
placeholder=description)
|
| 436 |
])
|
| 437 |
param_index += 1
|
| 438 |
|
| 439 |
-
#
|
| 440 |
while param_index < 5:
|
| 441 |
updates.extend([
|
| 442 |
-
gr.update(visible=False),
|
| 443 |
-
gr.update(visible=False
|
|
|
|
| 444 |
])
|
| 445 |
param_index += 1
|
| 446 |
|
| 447 |
-
updates.append(gr.update(value=header_text, visible=True)) # param_header
|
| 448 |
-
updates.append(gr.update(visible=False)) # loading_overlay
|
| 449 |
-
updates.append(gr.update(visible=True)) # call_api_btn
|
| 450 |
-
|
| 451 |
return updates
|
| 452 |
|
| 453 |
-
for input_component in [api_base_url, grant_type, client_id, client_secret,
|
| 454 |
-
api_token, iiq_username, iiq_password]:
|
| 455 |
-
input_component.change(
|
| 456 |
-
fn=validate_inputs,
|
| 457 |
-
inputs=[
|
| 458 |
-
spec_choice,
|
| 459 |
-
api_base_url,
|
| 460 |
-
grant_type,
|
| 461 |
-
client_id,
|
| 462 |
-
client_secret,
|
| 463 |
-
api_token,
|
| 464 |
-
iiq_username,
|
| 465 |
-
iiq_password,
|
| 466 |
-
*[input_box for _, _, input_box in param_components]
|
| 467 |
-
],
|
| 468 |
-
outputs=call_api_btn
|
| 469 |
-
)
|
| 470 |
-
|
| 471 |
-
for _, _, input_box in param_components:
|
| 472 |
-
input_box.change(
|
| 473 |
-
fn=validate_inputs,
|
| 474 |
-
inputs=[
|
| 475 |
-
spec_choice,
|
| 476 |
-
api_base_url,
|
| 477 |
-
grant_type,
|
| 478 |
-
client_id,
|
| 479 |
-
client_secret,
|
| 480 |
-
api_token,
|
| 481 |
-
iiq_username,
|
| 482 |
-
iiq_password,
|
| 483 |
-
*[input_box for _, _, input_box in param_components]
|
| 484 |
-
],
|
| 485 |
-
outputs=call_api_btn
|
| 486 |
-
)
|
| 487 |
-
|
| 488 |
def handle_api_call(spec_choice, api_base_url, session_id, grant_type, client_id, client_secret,
|
| 489 |
api_token, iiq_username, iiq_password, display_values, *args):
|
| 490 |
# Create param_values dictionary
|
|
@@ -546,11 +455,9 @@ with gr.Blocks(
|
|
| 546 |
confirmed_endpoints_state,
|
| 547 |
display_values_state,
|
| 548 |
param_group,
|
| 549 |
-
param_header,
|
| 550 |
-
loading_overlay,
|
| 551 |
-
call_api_btn,
|
| 552 |
*[item for group, display, input_box in param_components
|
| 553 |
-
|
| 554 |
]
|
| 555 |
)
|
| 556 |
|
|
|
|
| 145 |
opacity: 0.5;
|
| 146 |
pointer-events: none;
|
| 147 |
}
|
| 148 |
+
.loading-overlay {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
position: fixed;
|
| 150 |
top: 0;
|
| 151 |
left: 0;
|
| 152 |
width: 100%;
|
| 153 |
height: 100%;
|
| 154 |
+
background: rgba(255, 255, 255, 0.8);
|
| 155 |
+
display: flex;
|
| 156 |
+
justify-content: center;
|
| 157 |
+
align-items: center;
|
| 158 |
+
z-index: 1000;
|
| 159 |
}
|
| 160 |
"""
|
| 161 |
) as demo:
|
|
|
|
| 299 |
gr.update(visible=visibilities[2])
|
| 300 |
]
|
| 301 |
|
| 302 |
+
loading_overlay = gr.HTML(visible=False, value='<div class="loading-overlay">⏳ Processing...</div>')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
def confirm_selected_endpoints(spec_choice, *checkbox_values):
|
| 305 |
"""Collect and confirm all selected endpoints"""
|
|
|
|
|
|
|
| 306 |
all_selected = []
|
| 307 |
for checkbox_group in checkbox_values:
|
| 308 |
if isinstance(checkbox_group, list) and checkbox_group:
|
|
|
|
| 313 |
[], # display_values_state
|
| 314 |
gr.update(visible=False), # param_group
|
| 315 |
gr.update(value="❌ No endpoints selected", visible=True), # param_header
|
|
|
|
|
|
|
| 316 |
*[gr.update(visible=False) for _ in range(15)]) # 5 sets of 3 components each
|
| 317 |
|
| 318 |
# Get the API spec
|
|
|
|
| 338 |
required_params_count += len(path_params) + len(query_params)
|
| 339 |
|
| 340 |
# Create updates for all components
|
| 341 |
+
updates = []
|
|
|
|
|
|
|
|
|
|
| 342 |
updates.append(endpoints_with_params) # confirmed_endpoints_state
|
| 343 |
updates.append(display_values) # display_values_state
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
|
| 345 |
if not required_params_count:
|
| 346 |
+
# No parameters required
|
| 347 |
+
updates.append(gr.update(visible=False)) # param_group
|
| 348 |
updates.append(gr.update(value="✅ No parameters required. You can proceed to call the API.",
|
| 349 |
visible=True)) # param_header
|
| 350 |
+
# Enable API call button here
|
| 351 |
else:
|
| 352 |
+
# Parameters required
|
| 353 |
+
header_text = f"⚠️ Required Parameters ({required_params_count})"
|
| 354 |
+
updates.append(gr.update(visible=True)) # param_group
|
| 355 |
+
updates.append(gr.update(value=header_text, visible=True)) # param_header
|
| 356 |
|
| 357 |
# Then create updates for each parameter component
|
|
|
|
| 358 |
param_index = 0
|
| 359 |
for endpoint, path_params, query_params in endpoints_with_params:
|
| 360 |
# Handle path parameters
|
| 361 |
for param_name in path_params:
|
| 362 |
if param_index < 5:
|
| 363 |
updates.extend([
|
| 364 |
+
gr.update(visible=True),
|
| 365 |
gr.update(visible=True,
|
| 366 |
+
value=f"Endpoint: {endpoint} - Path Parameter (Required)"),
|
| 367 |
gr.update(visible=True,
|
| 368 |
label=f"🔑 Enter path parameter: {param_name}",
|
| 369 |
+
placeholder=f"Required path parameter for {endpoint}")
|
| 370 |
])
|
| 371 |
param_index += 1
|
| 372 |
|
| 373 |
+
# Handle required query parameters only
|
| 374 |
for _, name, required, description in query_params:
|
| 375 |
if required and param_index < 5:
|
| 376 |
updates.extend([
|
| 377 |
+
gr.update(visible=True),
|
| 378 |
+
gr.update(visible=True,
|
| 379 |
+
value=f"Endpoint: {endpoint} - Query Parameter (Required)"),
|
| 380 |
gr.update(visible=True,
|
| 381 |
label=f"🔍 Enter query parameter: {name}",
|
| 382 |
+
placeholder=description)
|
| 383 |
])
|
| 384 |
param_index += 1
|
| 385 |
|
| 386 |
+
# Hide remaining parameter components
|
| 387 |
while param_index < 5:
|
| 388 |
updates.extend([
|
| 389 |
+
gr.update(visible=False),
|
| 390 |
+
gr.update(visible=False, value=""),
|
| 391 |
+
gr.update(visible=False, label="")
|
| 392 |
])
|
| 393 |
param_index += 1
|
| 394 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
return updates
|
| 396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
def handle_api_call(spec_choice, api_base_url, session_id, grant_type, client_id, client_secret,
|
| 398 |
api_token, iiq_username, iiq_password, display_values, *args):
|
| 399 |
# Create param_values dictionary
|
|
|
|
| 455 |
confirmed_endpoints_state,
|
| 456 |
display_values_state,
|
| 457 |
param_group,
|
| 458 |
+
param_header, # Add param_header to outputs
|
|
|
|
|
|
|
| 459 |
*[item for group, display, input_box in param_components
|
| 460 |
+
for item in (group, display, input_box)]
|
| 461 |
]
|
| 462 |
)
|
| 463 |
|