|
34 | 34 | token_expiration = 300 |
35 | 35 | expiration_buffer = 30 |
36 | 36 |
|
| 37 | +#--- Functions |
| 38 | +def show_popup_message(message, background_color, text_color, duration=3): |
| 39 | + """ |
| 40 | + Displays a temporary popup message in Streamlit. |
| 41 | +
|
| 42 | + Args: |
| 43 | + message (str): The message to display. |
| 44 | + background_color (str): The background color of the popup. |
| 45 | + text_color (str): The text color of the popup. |
| 46 | + duration (int): The duration (in seconds) the message should be displayed. |
| 47 | + """ |
| 48 | + |
| 49 | + with st.container(): |
| 50 | + popup_style = f""" |
| 51 | + position: fixed; |
| 52 | + top: 50%; |
| 53 | + left: 50%; |
| 54 | + transform: translate(-50%, -50%); |
| 55 | + background-color: {background_color}; |
| 56 | + color: {text_color}; |
| 57 | + padding: 20px; |
| 58 | + border-radius: 5px; |
| 59 | + z-index: 9999; |
| 60 | + opacity: 1; |
| 61 | + transition: opacity 1s ease-in-out; |
| 62 | + """ |
| 63 | + |
| 64 | + st.markdown(f'<div style="{popup_style}" id="popup">{message}</div>', unsafe_allow_html=True) |
| 65 | + |
| 66 | + time.sleep(duration) |
| 67 | + |
| 68 | + st.markdown(f""" |
| 69 | + <script> |
| 70 | + setTimeout(function() {{ |
| 71 | + document.getElementById('popup').style.opacity = '0'; |
| 72 | + }}, 100); // Small delay before fade |
| 73 | + setTimeout(function() {{ |
| 74 | + document.getElementById('popup').remove(); |
| 75 | + }}, {duration * 1000 + 1000}); // Remove after fade |
| 76 | + </script> |
| 77 | + """, unsafe_allow_html=True) |
| 78 | + return None |
| 79 | + |
37 | 80 | def load_secrets(): |
38 | 81 | """Loads API credentials from secrets.yml if it exists.""" |
39 | 82 | try: |
@@ -105,16 +148,18 @@ def make_auth_request(): |
105 | 148 | json_response = auth_response.json() |
106 | 149 | last_token_fetch_time = time.time() |
107 | 150 | token_expiration = json_response['expires_in'] |
| 151 | + print("Authenticated with controller.") |
| 152 | + show_popup_message(f"Connection established. {auth_response}","green","black",3) |
| 153 | + |
108 | 154 | else: |
| 155 | + show_popup_message(f"Unable to log in at: {BASE_URL} \n\n HTTP Status Code: {auth_response} - {status}","red","black",3) |
109 | 156 | print(f"Unable to log in at: {BASE_URL}") |
110 | 157 | print("Please check your controller URL and try again.") |
111 | | - sys.exit(9) |
| 158 | + return False |
112 | 159 |
|
113 | 160 | __session__.headers['X-CSRF-TOKEN'] = json_response['access_token'] |
114 | 161 | __session__.headers['Authorization'] = f'Bearer {json_response["access_token"]}' |
115 | 162 |
|
116 | | - print("Authenticated with controller.") |
117 | | - |
118 | 163 | if DEBUG: |
119 | 164 | print(f"Last token fetch time: {last_token_fetch_time}") |
120 | 165 | print(f"Token expires in: {json_response['expires_in']}") |
@@ -537,7 +582,7 @@ def get_snapshots(application_id): |
537 | 582 | snapshots_url = BASE_URL + "/controller/rest/applications/" + str(application_id) + \ |
538 | 583 | "/request-snapshots?time-range-type=BEFORE_NOW&duration-in-mins=" + str(snapshot_duration_mins) + \ |
539 | 584 | "&first-in-chain=" + str(first_in_chain) + "&need-exit-calls=" + str(need_exit_calls) + \ |
540 | | - "&need-props=" + str(need_props) + "&maximum-results=1000000" |
| 585 | + "&need-props=" + str(need_props) + "&maximum-results=65000" |
541 | 586 |
|
542 | 587 | if DEBUG: |
543 | 588 | print(" --- Fetching snapshots from: "+ snapshots_url) |
|
0 commit comments