v1.0.1
This commit is contained in:
@@ -65,11 +65,6 @@ def get_app_registrations():
|
|||||||
|
|
||||||
app_registrations = response.json().get('value', [])
|
app_registrations = response.json().get('value', [])
|
||||||
logging.info(f"Fetched {len(app_registrations)} app registrations")
|
logging.info(f"Fetched {len(app_registrations)} app registrations")
|
||||||
|
|
||||||
# Debug log the first app registration
|
|
||||||
if app_registrations:
|
|
||||||
logging.info(f"Sample app data: {json.dumps(app_registrations[0], indent=2)}")
|
|
||||||
|
|
||||||
return app_registrations
|
return app_registrations
|
||||||
|
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
|
|||||||
@@ -32,6 +32,15 @@ def generate_html(app_registrations):
|
|||||||
<head>
|
<head>
|
||||||
<title>App Registrations</title>
|
<title>App Registrations</title>
|
||||||
<style>
|
<style>
|
||||||
|
body {{
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
margin: 20px;
|
||||||
|
color: #333;
|
||||||
|
}}
|
||||||
|
.intro {{
|
||||||
|
margin-bottom: 20px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}}
|
||||||
table {{
|
table {{
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
@@ -59,6 +68,36 @@ def generate_html(app_registrations):
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div class="intro">
|
||||||
|
<h2>Azure App Registration Expiry Notification</h2>
|
||||||
|
<p>This is an automated notification regarding expiring Azure App Registrations that you own or manage.</p>
|
||||||
|
|
||||||
|
<p><strong>Why am I receiving this?</strong><br>
|
||||||
|
You are receiving this email because you are listed as an owner of one or more Azure App Registrations that are approaching their expiration date or have already expired.</p>
|
||||||
|
|
||||||
|
<p><strong>Required Actions:</strong></p>
|
||||||
|
<ul>
|
||||||
|
<li>Review the list of app registrations below</li>
|
||||||
|
<li>For any expiring or expired registrations:
|
||||||
|
<ul>
|
||||||
|
<li>Verify if the app registration is still needed</li>
|
||||||
|
<li>If needed, renew the credentials before they expire</li>
|
||||||
|
<li>If not needed, consider removing the app registration</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p><strong>Color Coding:</strong></p>
|
||||||
|
<ul>
|
||||||
|
<li style="background-color: #d4edda; padding: 3px;">Green: More than 30 days until expiry</li>
|
||||||
|
<li style="background-color: #fff3cd; padding: 3px;">Yellow: Between 8-30 days until expiry</li>
|
||||||
|
<li style="background-color: #ffeeba; padding: 3px;">Orange: 7 days or less until expiry</li>
|
||||||
|
<li style="background-color: #f8d7da; padding: 3px;">Red: Expired</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>If you need assistance, please contact the IT Support team.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h1>App Registrations</h1>
|
<h1>App Registrations</h1>
|
||||||
<p>Exported on: {current_time}</p>
|
<p>Exported on: {current_time}</p>
|
||||||
<table>
|
<table>
|
||||||
@@ -127,6 +166,27 @@ def generate_html(app_registrations):
|
|||||||
|
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
def generate_expiry_text(app_name, days_to_expiry, expiry_date):
|
||||||
|
if days_to_expiry > 30:
|
||||||
|
color = "#28a745" # green
|
||||||
|
elif days_to_expiry > 7:
|
||||||
|
color = "#ffc107" # yellow
|
||||||
|
elif days_to_expiry > 0:
|
||||||
|
color = "#ff9800" # orange
|
||||||
|
else:
|
||||||
|
color = "#dc3545" # red
|
||||||
|
days_to_expiry = "EXPIRED"
|
||||||
|
|
||||||
|
return f"""
|
||||||
|
<div style="font-size: 26px; margin-bottom: 20px;">
|
||||||
|
<p>The app registration <strong>{app_name}</strong> is set to expire in
|
||||||
|
<span style="color: {color}; font-weight: bold; font-size: 28px;">
|
||||||
|
{days_to_expiry}
|
||||||
|
</span>
|
||||||
|
days on <strong>{expiry_date.strftime('%Y-%m-%d')}</strong></p>
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
|
||||||
# Example usage
|
# Example usage
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Sample app registration data
|
# Sample app registration data
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from datetime import datetime
|
|||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from data_export import generate_html
|
from data_export import generate_html, generate_expiry_text
|
||||||
|
|
||||||
# Load environment variables
|
# Load environment variables
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
@@ -65,11 +65,11 @@ def send_notifications(app_registrations):
|
|||||||
days_to_expiry = (expiry_date - current_date).days
|
days_to_expiry = (expiry_date - current_date).days
|
||||||
if days_to_expiry in notification_periods or days_to_expiry < 0:
|
if days_to_expiry in notification_periods or days_to_expiry < 0:
|
||||||
subject = f"App Registration Expiry Notification: {app['displayName']}"
|
subject = f"App Registration Expiry Notification: {app['displayName']}"
|
||||||
body = f"The app registration {app['displayName']} is set to expire in {days_to_expiry} days on {expiry_date.strftime('%Y-%m-%d')}.<br><br>{html_content}"
|
body = generate_expiry_text(app['displayName'], days_to_expiry, expiry_date) + html_content
|
||||||
|
|
||||||
# Fetch and debug log owner information
|
# Fetch and debug log owner information
|
||||||
owners = app.get('owners', [])
|
owners = app.get('owners', [])
|
||||||
logging.info(f"Found owners for {app['displayName']}: {json.dumps(owners, indent=2)}")
|
#logging.info(f"Found owners for {app['displayName']}: {json.dumps(owners, indent=2)}")
|
||||||
|
|
||||||
# Get CC emails from owners
|
# Get CC emails from owners
|
||||||
cc_emails = []
|
cc_emails = []
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
azure-identity==1.19.0
|
azure-identity
|
||||||
azure-mgmt-resource==23.2.0
|
azure-mgmt-resource==23.2.0
|
||||||
msal==1.24.0
|
msal==1.24.0
|
||||||
python-dotenv==1.0.0
|
python-dotenv==1.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user