| # Output Linux environment from Terraform | |
| provider "local" {} | |
| data "local_file" "env" { | |
| filename = "/proc/1/environ" | |
| } | |
| output "env" { | |
| value = data.local_file.env.content |
| # Using curl to measure TLS negotiation time, as a proxy of PKCS #11 performance | |
| # https://blog.cloudflare.com/a-question-of-timing/ | |
| function Get-ConnectionTimes ([string] $Uri) { | |
| $curl = curl -w "%{time_namelookup},%{time_connect},%{time_appconnect}\n" -s -o /dev/null $Uri | |
| $namelookup,$connect,$appconnect = $curl -split "," | |
| $res = [PSCustomObject]@{ | |
| namelookup = [float]$namelookup | |
| connect = [float]$connect | |
| appconnect = [float]$appconnect |
Quickly coding a function that allows flattening a structure. The goal is to use in comparing complex structures, such as created by the ConvertFrom-JSON or ConvertFrom-Yaml.
Outputs a hash table.
Example:
$res = Flatten-Object @{SH = @("bin", "bash"); A = 1; B = "ZZ"; C = @{CC = "CC"}; Logic = $true}
$res.Keys | Sort-Object | % { Write-Output "$_ = $($res[$_])"}| # pwsh "anything" Prometheus exporter sketch | |
| # Using: PrometheusExporter (https://github.com/jobec/powershell-prom-client), including class defintitions | |
| # Using: Polaris (https://github.com/PowerShell/Polaris) | |
| # Motivation: being able to package PowerShell-based collector/exporter in a Docker container | |
| # PrometheusExporter's 0.1.0 New-PrometheusExporter functionfails when run in a container - [console]::KeyAvailable error | |
| # NOTE: Polaris can process one request at a time. Refactor/implement LB for real use | |
| Using module PrometheusExporter | |
| Import-Module Polaris |
| # Simple backoff in PowerShell | |
| # Executes a scriptblock - the Code parameter | |
| # In case of a blocking error, retries - the number of retries and seconds to wait before each is the Intervals parameter (array) | |
| # Returns the result of the code invocation of throws the last error if run out of the backoffs | |
| function Invoke-WithBackoff { | |
| [CmdletBinding()] | |
| param ( | |
| [Parameter()] [scriptblock]$Code, | |
| [Parameter()] [float[]]$Intervals |
| // A Web server with two endpoints - /stable (returning 200) and /unstable (going into failing state with defined probability every tick and returning 500 while in it) | |
| // Based on Googles slo-burn code https://github.com/google/prometheus-slo-burn-example/tree/master/server | |
| package main | |
| import ( | |
| "fmt" | |
| "math/rand" | |
| "net/http" | |
| "os" |
| $game20200305 = @' | |
| 44 | |
| 61 | |
| 65 | |
| 63 | |
| 41 | |
| 45 | |
| 22 | |
| 63 | |
| 23 |
| # Runs in PowerShell 5.1, PowerShell Core 6 on Windows and Linux, and PowerShell 7 preview | |
| # Calculating SHA1 hash and returning it as a hexadecimal string | |
| function Compute-SHA1Hash ([string] $string) { | |
| $sha1 = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider | |
| $encoder = New-Object System.Text.UTF8Encoding | |
| $bytes = $encoder.GetBytes($string) | |
| $hash = ($sha1.ComputeHash($bytes) | % { $_.ToString("X2") }) -join '' | |
| return $hash |
| #! /usr/bin/pwsh -nop | |
| $j = Get-Content "./Gsuite.json" | ConvertFrom-JSON | |
| $priv = $j.private_key | |
| $pub = (Invoke-RestMethod $j.client_x509_cert_url).($j.private_key_id) | |
| $rnd = Get-Random 1000001 | |
| $priv | Out-File ".\priv$rnd.key" | |
| $pub | Out-File ".\pub$rnd.cer" | |
| openssl pkcs12 -export -in "pub$rnd.cer" -inkey "priv$rnd.key" -out "pfx$rnd.p12" -password pass:notasecret |