Created
December 27, 2021 13:43
-
-
Save uolter/dbf609f83028325fa8f539a04fd2af25 to your computer and use it in GitHub Desktop.
List certificate expire dates in azure key vault
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
#!/bin/bash | |
############################### | |
# pip install python-dateutil # | |
############################### | |
KEYVAULTS=$(az keyvault list --query "[].name" -o tsv) | |
# KEYVAULTS="<space_delimited_list_of_vault_names>" | |
for KEYVAULT in $KEYVAULTS; do | |
for CERT in $(az keyvault certificate list \ | |
--vault-name "$KEYVAULT" \ | |
--query "[].name" -o tsv); do | |
EXPIRES=$(az keyvault certificate show \ | |
--vault-name "$KEYVAULT" \ | |
--name "$CERT" \ | |
--query "attributes.expires" -o tsv) | |
PYCMD=$(cat <<EOF | |
from datetime import datetime | |
from dateutil import parser | |
from dateutil.tz import tzutc | |
expire_days = (parser.parse('$EXPIRES') - datetime.utcnow().replace(tzinfo=tzutc())).days | |
if expire_days > 0: | |
msg = "in {} days".format(expire_days) | |
else: | |
msg = "already expired!!!" | |
print(msg) | |
EOF | |
) | |
EXPIRES_DELTA=$(python3 -c "$PYCMD") | |
echo "$CERT (Vault: $KEYVAULT) expires on $EXPIRES ($EXPIRES_DELTA)" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment