Skip to content

Instantly share code, notes, and snippets.

@mitchelldavis
mitchelldavis / NullResourceToVault.tf
Last active August 23, 2018 12:54
This Gist is a reference on how to use Terraform's null_resource to apply configuration to Vault when the configuration endpoint doesn't define all of the expected http methods. (GET, PUT, POST, DELETE)
resource "null_resource" "secret_tune" {
triggers {
config_content = "${sha512("${file("data/sys/mounts/secret/tune.json")}")}"
}
provisioner "local-exec" {
command = "curl -X POST -H \"X-VAULT-TOKEN:$VAULT_TOKEN\" -d '${file("data/sys/mounts/secret/tune.json")}' $VAULT_ADDR/v1/sys/mounts/secret/tune"
}
}
@mitchelldavis
mitchelldavis / clean_aws_cache.sh
Created May 21, 2018 17:00
A Bash script to clean out the Identity Whitelist from Hashicorp Vault's AWS Auth Provider
#! /bin/bash
WHITELIST=$(vault list -format=json auth/aws-ec2/identity-whitelist | jq -r '.[]')
INSTANCES=$(aws ec2 describe-instances)
INSTANCE_LIST=$(echo $INSTANCES | jq -r '.Reservations[].Instances[] | .InstanceId')
for item in $WHITELIST; do
if echo $INSTANCE_LIST | grep -w $item > /dev/null; then
echo "Skipping..."
var SCREEN_WIDTH = window.innerWidth,
SCREEN_HEIGHT = window.innerHeight,
mousePos = {
x: 400,
y: 300
},
// create canvas
canvas = document.createElement('canvas'),
context = canvas.getContext('2d'),
@mitchelldavis
mitchelldavis / Get-FileHash.ps1
Created February 9, 2015 14:26
Get-FileHash
function Get-FileHash
{
param( [string]$filePath,
[string]$alg = 'SHA256')
$stream = $null
$filePath = Resolve-Path $filePath
try
{
@mitchelldavis
mitchelldavis / Base64Conversions.ps1
Created January 19, 2015 16:37
Base64 String Conversions in Powershell
function Convert-ToBase64
{
param( [Parameter(Mandatory=$true)][String]$target )
$b = [System.Text.Encoding]::UTF8.GetBytes($target)
[System.Convert]::ToBase64String($b)
}
function Convert-FromBase64
{
param( [Parameter(Mandatory=$true)][String]$target )
@mitchelldavis
mitchelldavis / get-hash.ps1
Last active August 29, 2015 14:03
Get SHA256 hash of a file.
param(
[string] $file = $(throw 'a filename is required'),
[string] $algorithm = 'sha256'
)
$fileStream = [system.io.file]::openread((resolve-path $file))
$hasher = [System.Security.Cryptography.HashAlgorithm]::create($algorithm)
$hash = $hasher.ComputeHash($fileStream)
$fileStream.close()
$fileStream.dispose()
@mitchelldavis
mitchelldavis / Liquibase.Common.Tasks
Last active November 15, 2022 23:05
Some MSBuild Scripts for Liquibase and MS Sql.
<?xml version="1.0" encoding="utf-8"?>
<Project InitialTargets="" DefaultTargets="All" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<AssemblyFile>$(MSBuildThisFileDirectory)\..\packages\MSBuild.Extension.Pack\tools\net40\MSBuild.ExtensionPack.TaskFactory.PowerShell.dll</AssemblyFile>
</PropertyGroup>
<UsingTask TaskFactory="PowershellTaskFactory" TaskName="CreateDatabaseTask" AssemblyFile="$(AssemblyFile)">
<ParameterGroup>
<ScriptsDirectory Required="true" ParameterType="System.String" />
<Server Required="true" ParameterType="System.String" />
@mitchelldavis
mitchelldavis / mingw.common.targets
Created December 31, 2013 04:11
MSBuild for MinGW
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Target Name="SetupProject">
<MakeDir Directories="$(MSBuildProjectDirectory)\obj;$(MSBuildProjectDirectory)\bin" />
</Target>
<Target Name="CleanProject">
<RemoveDir Directories="$(MSBuildProjectDirectory)\obj;$(MSBuildProjectDirectory)\bin" />
</Target>
@mitchelldavis
mitchelldavis / Remote-Connect.ps1
Created December 13, 2013 16:47
A simple cmdlet that will take care of all the lifting while only asking me for the machine name and credentials.
# All you should have to do to connect to a remote machine is type:
# Remote-Connect <machineIP>
# Then the cmdlet will ask you for your credentials and you can continue.
function Remote-Connect
{
param([Parameter(Mandatory=$true)][string]$machine)
$opt=New-PSSessionOption –skipcacheck
Enter-PsSession $machine -usessl -SessionOption $opt –cred (get-credential)
@mitchelldavis
mitchelldavis / PowershellDiff.ps1
Created November 14, 2013 17:01
A simple diff function for two files in powershell.
param($VersionOne, $VersionTwo)
$result = compare-object (get-content $VersionOne) (get-content $VersionTwo) -IncludeEqual
Write-Host "+ " $VersionOne -ForegroundColor DarkGray
Write-Host "- " $VersionTwo -ForegroundColor DarkGray
Write-Host "=======================================" -ForegroundColor DarkGray
$result | foreach {
if($_.SideIndicator -eq "==")