Skip to content

Instantly share code, notes, and snippets.

View slmcmahon's full-sized avatar

Stephen McMahon slmcmahon

View GitHub Profile
@slmcmahon
slmcmahon / getnsgroup.ps1
Last active June 20, 2025 18:37
Displays the security groups that are associated with an AKS namespace
function Get-CurrentContext {
# Get the output of 'kubectl config get-contexts' and convert it to a string array
$contexts = kubectl config get-contexts | Out-String -Stream
# Split the output into lines and remove empty lines
$lines = $contexts | Where-Object { $_.Trim() -ne "" }
# Parse the header to determine column positions
$headerLine = $lines[0]
@slmcmahon
slmcmahon / checksecrets.sh
Created June 7, 2025 19:18
Bash: Get all of the environment variable values where the name is AZURE_CLIENT_ID in all deployments in the current namespace and check the Azure AD app registration to see if any of them have secrets that are expiring in the next 30 days.
#!/bin/bash
threshold_days=30
echo 'Extracting all AZURE_CLIENT_IDs...'
kubectl get deployments -o json \
| jq -r '
.items[]
| .spec.template.spec.containers[]
@slmcmahon
slmcmahon / checksecrets.ps1
Last active June 7, 2025 19:24
PowerShell: Get all of the environment variable values where the name is AZURE_CLIENT_ID in all deployments in the current namespace and check the Azure AD app registration to see if any of them have secrets that are expiring in the next 30 days.
#!/usr/bin/env pwsh
$thresholdDays = 30
Write-Host "Extracting all AZURE_CLIENT_IDs..."
# Get all unique AZURE_CLIENT_ID values from deployments
$clientIds = kubectl get deployments -o json | ConvertFrom-Json |
ForEach-Object { $_.items } |
ForEach-Object {
@slmcmahon
slmcmahon / keybase.md
Last active April 16, 2025 19:24
Keybase Proof

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@slmcmahon
slmcmahon / getnsgroup.sh
Created May 25, 2024 12:24
Displays the security groups that are associated with an AKS namespace
#!/bin/bash
if [ $# -eq 0 ]; then
# if no namespace was passed, then get the currently selected namespace
ns=$(kubectl config get-contexts | awk '$1 == "*" {print $5}')
else
ns=$1
fi
# get the rolebinding for the response matching ROLE = "Role/edit"
@slmcmahon
slmcmahon / checkprodtags.sh
Created January 26, 2024 13:31
Check if current deployments are tagged as production in Azure Container Registry
#!/bin/bash
ACR_NAME='the name of your ACR'
# Get all the deployment names in the current namespace
deployments=$(kubectl get deployments -o jsonpath='{.items[*].metadata.name}')
# For each deployment
for deployment in $deployments; do
# Extract the image that is currently used in this deployment
@slmcmahon
slmcmahon / azdo-var-list-compare.py
Created October 11, 2023 18:32
Compares two variable lists and reports variables that don't match
import json
import requests
import os
from requests.auth import HTTPBasicAuth
org = 'your-org'
project = 'your-project'
# the variableGroupId values from the variable libs that
# you want to compare
@slmcmahon
slmcmahon / exchangerates.py
Created February 24, 2020 21:56
Python scrape for exchange rates against USD.
from bs4 import BeautifulSoup
import requests
import collections
currencies = []
Currency = collections.namedtuple('Currency', 'country usd')
sd = requests.get("https://www.x-rates.com/table/?from=USD&amount=1")
sp = BeautifulSoup(sd.content, 'html.parser')
table = sp.find('table', {"class": "tablesorter ratesTable"})
@slmcmahon
slmcmahon / statecodes.js
Created February 23, 2020 23:43
U.S. State Codes
const axios = require('axios');
const cheerio = require('cheerio');
const url = 'https://www.infoplease.com/us/postal-information/state-abbreviations-and-state-postal-codes';
axios.get(url).then(response => {
const $ = cheerio.load(response.data);
$('table.sgmltable tr').each((i, elem) => {
const children = $(elem).children()
const stateName = $(children[0]).text();
@slmcmahon
slmcmahon / exchangerates.js
Created February 23, 2020 23:41
Exchange Rates for USD
const axios = require('axios');
const cheerio = require('cheerio');
const url = 'https://www.x-rates.com/table/?from=USD&amount=1';
axios.get(url).then(response => {
const $ = cheerio.load(response.data);
$('table.ratesTable tr').each((i, elem) => {
const children = $(elem).children()
const country = $(children[0]).text();