Skip to content

Instantly share code, notes, and snippets.

@MatthewJDavis
MatthewJDavis / main.tf
Last active April 10, 2024 00:41
Example Terraform to show how you can retrieve the MS Graph permissions with Terraform.
terraform {
required_providers {
azuread = {
source = "hashicorp/azuread"
}
}
}
# Authenticated via the Azure CLI
data "azuread_application_published_app_ids" "well_known" {}
@MatthewJDavis
MatthewJDavis / Get-PythonOutput.ps1
Last active March 4, 2023 17:56
Example on how to call a Python script and save the output of the print statement to a variable.
# Calls a Python script. The output of the print statement is saved in a Variable.
$pythonProgramPath = ".venv/bin/python" # location of the Python executable
$pythonScriptPath = "/python/powershell-call-python/main.py" # location of script file.
$arg = "hello"
$pythonOutput = & $pythonProgramPath $pythonScriptPath $arg
$pythonOutput
@MatthewJDavis
MatthewJDavis / main.py
Created March 4, 2023 17:32
Print out input text from command line argument and exit.
# Print out input text from command line argument and exit.
# Used as demo to get data from Python Script in PowerShell.
import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument("text")
args = parser.parse_args()
print(f"{args.text} From Python script.")
sys.exit()
@MatthewJDavis
MatthewJDavis / main.py
Last active August 22, 2022 20:40
Airthings API Python
# Authenticate to the Airthings API and get the latest data from a particular device.
# Requires an API client created in the web gui: https://dashboard.airthings.com/integrations/api-integration
# Update script with client id and device id which can be retrieved from the devices page: https://dashboard.airthings.com/devices
# export the api secret to an environment variable called secret (Bash export secret="secret-key"
# Requires the requests package (pip install requests into the virutal environment of container).
# Python version 3.6 or above needed for f strings.
# Matthew Davis July 2022
import os
import logging
import pprint
@MatthewJDavis
MatthewJDavis / main.py
Last active February 19, 2023 17:15
Create JWKS keys for Okta service application
# Python script to create JWKS public and private keys.
# Can be used when creating an Okta Oauth application.
# Requires https://github.com/latchset/jwcrypto
# https://developer.okta.com/docs/guides/implement-oauth-for-okta-serviceapp/main/
# Warning: These key are being produced for automation which doesn't work well when there are password protected keys.
# Private keys without passwords provide an extreme security risk and should be handled securely and always encrypted at rest after generation.
# Please move the keys created in the keys directory to a secure location for use ASAP.
#%%
import os
import subprocess
@MatthewJDavis
MatthewJDavis / git.txt
Last active October 30, 2021 13:19
Useful Git commands
# Check remote
git remote -v
# Configuration
git config --global --list
git config --global user.name
git config --global user.email
git config --list
# for PowerShell set function to see graph
@MatthewJDavis
MatthewJDavis / unlock-wd.text
Created October 9, 2021 00:47
Unlock Western digital passport on linux
# Unlock Western digital passport on linux
# https://github.com/0-duke/wdpassport-utils
# Need to run as sudo.
# May need to install sudo pip3 install pyudev
cd ~/Documents/western-digital
sudo ./wdpassport-utils.py --device /dev/sdb -u
@MatthewJDavis
MatthewJDavis / matthew-davis.asc
Created October 8, 2021 23:56
My PGP public key
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBGFZ+IsBEAC92IH/s5fpK9Um0tRrxP3QpLowc7hXSjpY4yv6l6H6cLzAZM7h
R9m+Wg2FPHg3/zLSblTXT1jNXQXj4CUJjhKve7YFRut1crsk7zMPmwlLgThHFqNp
BamcAZduLLQxDeS/OvSE7WV3FjZ5MbL80GDIQy+x7yh+CR2CWNXYM5El2ZzlEiO6
uGKwJ1UkGeAz11nVr/iWQd8Un0B8D7NkpyIBPOWUgDAOcbm5anJrqbPDOfiecURE
73fNy/ZF/TZB0qMN5bad8m6SPSDt1yxBZUf+lZVdA3BsynqbXcAMjZt+/gm3iMGO
GDq3l27SZpU1xv3ynhZQvTgwbo7kH0rOkTWE1g/42wSRtqa8KGNnTdPNywsHwaah
63DhodsZaqv4buwN0dHSyaFXKxPSWEcE8iI2Te32heSD3lLPW4/T5kySYZVdZJIm
jemWmmAbgVJKhmorOrVsBmjVSh0DH9k9G4Bsm4Mc0ncJgoFtz3iJ8RjvC2olMaFX
@MatthewJDavis
MatthewJDavis / crash.txt
Created September 1, 2021 16:00
Okta terraform provider import SAML crash
Error: Plugin did not respond
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
Stack trace from the terraform-provider-okta_v3.13.8 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xad46f5]
@MatthewJDavis
MatthewJDavis / get_worker_by_id.py
Last active August 6, 2021 00:38
Python script using Zeep to return a Worker from the Workday API
'''
Query the Workday API using the Zeep package to return the details of the specified worker from their employee ID.
Details of the user and their password should be set in environment variables, like so in bash:
export user=''
export password=''
'''
import zeep, os
from zeep import Client
from zeep.wsse.username import UsernameToken