-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from devwithkrishna/feature/app
Feature/app
- Loading branch information
Showing
7 changed files
with
146 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
name: azure-policy-exemption | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
subscription_name: | ||
description: 'From which subscription we need to provide exemption. the scope' | ||
type: string | ||
required: true | ||
policy_name: | ||
description: 'Policy Name to be given Exception to' | ||
type: string | ||
required: true | ||
expires_after: | ||
description: 'Policy exemption should be automatically revoked after how long' | ||
type: string | ||
required: true | ||
unit: | ||
description: 'Unit of time' | ||
required: true | ||
type: choice | ||
options: | ||
- hour | ||
- day | ||
- month | ||
run-name: policy exemption for ${{ inputs.policy_name }} for ${{ inputs.expires_after }} ${{ inputs.unit }} | ||
jobs: | ||
azure-policy-exemption: | ||
runs-on: ubuntu-latest | ||
env: | ||
AZURE_CLIENT_ID: ${{ secrets.OWNER_SP_APP_ID }} | ||
AZURE_CLIENT_SECRET: ${{ secrets.OWNER_SP_APP_SECRET }} | ||
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install package mgmt tool | ||
run: | | ||
pip install poetry | ||
poetry install | ||
- name: Execute program | ||
run: | | ||
poetry run python3 policy_exception.py --subscription_name "${{ inputs.subscription_name }}" --policy_name "${{ inputs.policy_name }}" --expires_after ${{ inputs.expires_after }} --unit ${{ inputs.unit }} | ||
- name: Completed | ||
run: echo "Program execution completed" | ||
#name: azure-policy-exemption | ||
#on: | ||
# workflow_dispatch: | ||
# inputs: | ||
# subscription_name: | ||
# description: 'From which subscription we need to provide exemption. the scope' | ||
# type: string | ||
# required: true | ||
# policy_name: | ||
# description: 'Policy Name to be given Exception to' | ||
# type: string | ||
# required: true | ||
# expires_after: | ||
# description: 'Policy exemption should be automatically revoked after how long' | ||
# type: string | ||
# required: true | ||
# unit: | ||
# description: 'Unit of time' | ||
# required: true | ||
# type: choice | ||
# options: | ||
# - hour | ||
# - day | ||
# - month | ||
#run-name: policy exemption for ${{ inputs.policy_name }} for ${{ inputs.expires_after }} ${{ inputs.unit }} | ||
#jobs: | ||
# azure-policy-exemption: | ||
# runs-on: ubuntu-latest | ||
# env: | ||
# AZURE_CLIENT_ID: ${{ secrets.OWNER_SP_APP_ID }} | ||
# AZURE_CLIENT_SECRET: ${{ secrets.OWNER_SP_APP_SECRET }} | ||
# AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | ||
# | ||
# steps: | ||
# - name: Checkout repository | ||
# uses: actions/checkout@v4 | ||
# | ||
# - name: Set up python | ||
# uses: actions/setup-python@v5 | ||
# with: | ||
# python-version: '3.11' | ||
# | ||
# - name: Install package mgmt tool | ||
# run: | | ||
# pip install poetry | ||
# poetry install | ||
# | ||
# - name: Execute program | ||
# run: | | ||
# poetry run python3 policy_exception.py --subscription_name "${{ inputs.subscription_name }}" --policy_name "${{ inputs.policy_name }}" --expires_after ${{ inputs.expires_after }} --unit ${{ inputs.unit }} | ||
# | ||
# - name: Completed | ||
# run: echo "Program execution completed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() |