-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_app.py
42 lines (34 loc) · 1.51 KB
/
streamlit_app.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
import streamlit as st
from dotenv import load_dotenv
from policy_exception import create_exemption_for_policy, get_policies
from azure_resource_graph_query import run_azure_rg_query
def main():
"""run streamlit app"""
load_dotenv()
st.header("Azure Policy Exemption Tool", divider='rainbow')
subscription_name = st.text_input("Enter Subscription Name")
if subscription_name:
st.session_state.subscription_name = subscription_name
subscription_id = run_azure_rg_query(subscription_name=subscription_name)
st.session_state.subscription_id = subscription_id
st.success(f"Subscription ID of {subscription_name}: {subscription_id}")
else:
st.error(f"Subscription {subscription_name} not found")
if subscription_id:
# if 'subscription_id' in st.session_state:
policies = get_policies(subscription_id=subscription_id)
selected_policy = st.selectbox("Select a Policy", policies)
if selected_policy:
st.write(f"You selected: {selected_policy}")
st.session_state.selected_policy = selected_policy
expires_after = st.text_input("Policy Will Expires After")
unit = st.selectbox("Unit", ["hour", "day", "month"])
# Print the exemption period
st.write(f"Policy exemption will expire after {expires_after} {unit}")
# Run streamlit app by clicking submit
if st.button("Apply Exemption"):
# call policy exemption creation function
create_exemption_for_policy(subscription_id=subscription_id, policy_name=selected_policy,
expires_after=expires_after, unit=unit)
if __name__ == "__main__":
main()