diff --git a/azure_client.py b/azure_client.py
index bd67483..f5a7c1a 100644
--- a/azure_client.py
+++ b/azure_client.py
@@ -65,11 +65,6 @@ def get_app_registrations():
app_registrations = response.json().get('value', [])
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
except requests.exceptions.RequestException as e:
diff --git a/data_export.py b/data_export.py
index 0eed4f4..2c21b07 100644
--- a/data_export.py
+++ b/data_export.py
@@ -32,6 +32,15 @@ def generate_html(app_registrations):
App Registrations
+
+
Azure App Registration Expiry Notification
+
This is an automated notification regarding expiring Azure App Registrations that you own or manage.
+
+
Why am I receiving this?
+ 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.
+
+
Required Actions:
+
+ - Review the list of app registrations below
+ - For any expiring or expired registrations:
+
+ - Verify if the app registration is still needed
+ - If needed, renew the credentials before they expire
+ - If not needed, consider removing the app registration
+
+
+
+
+
Color Coding:
+
+ - Green: More than 30 days until expiry
+ - Yellow: Between 8-30 days until expiry
+ - Orange: 7 days or less until expiry
+ - Red: Expired
+
+
+
If you need assistance, please contact the IT Support team.
+
+
App Registrations
Exported on: {current_time}
@@ -127,6 +166,27 @@ def generate_html(app_registrations):
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"""
+
+
The app registration {app_name} is set to expire in
+
+ {days_to_expiry}
+
+ days on {expiry_date.strftime('%Y-%m-%d')}
+
+ """
+
# Example usage
if __name__ == "__main__":
# Sample app registration data
diff --git a/notification.py b/notification.py
index 4ec60be..5d44a51 100644
--- a/notification.py
+++ b/notification.py
@@ -7,7 +7,7 @@ from datetime import datetime
import requests
import json
import logging
-from data_export import generate_html
+from data_export import generate_html, generate_expiry_text
# Load environment variables
load_dotenv()
@@ -65,11 +65,11 @@ def send_notifications(app_registrations):
days_to_expiry = (expiry_date - current_date).days
if days_to_expiry in notification_periods or days_to_expiry < 0:
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')}.
{html_content}"
+ body = generate_expiry_text(app['displayName'], days_to_expiry, expiry_date) + html_content
# Fetch and debug log owner information
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
cc_emails = []
diff --git a/requirements.txt b/requirements.txt
index 08651da..5e9f953 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,4 @@
-azure-identity==1.19.0
+azure-identity
azure-mgmt-resource==23.2.0
msal==1.24.0
python-dotenv==1.0.0