STEP# | CODE | COMMENT |
---|---|---|
01 | echo -n "Are you sure (Y/N)? " |
print prompt just once with echo |
02 | answered= |
initiate an empty test binding |
03 | while [[ ! $answered ]]; do |
loop until test binding is populated |
04 | read -r -n 1 -s answer |
get input, supress escape, only 1 char, supress input |
05 | if [[ $answer = [Yy] ]]; then |
test if input is y or Y |
06 | answered="yes" |
..if true, set test binding to yes → step #12 |
07 | elif [[ $answer = [Nn] ]]; then |
else, test is input is n or N |
08 | answered="no" |
..if trye, set test binding to no → step #12 |
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
moduleMissingError = 'Missing dependency module: Run "pip install -r requirements.txt" → Retry' | |
try: | |
import #<module1> | |
import #<package2> | |
import #<subpackage1> | |
except ImportError: | |
sys.exit(moduleMissingError) |
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
# Sometimes URL is copied from a browser and arrives as | |
# https://consul.foo.com/client/ami_size/edit | |
# Othertimes URL is copied from Consul CLI and arrives as | |
# client/ami_size | |
# And I just need the actual key, being 'ami_size' for the script | |
$url = ($url -match "^https://") ? | |
($url -replace "https://consul.foo.com/client/", "") -replace "/edit", "": | |
($url -replace "client/", "") |
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
### func1 | |
function query-consul () { | |
param ( | |
[String[]]$consul_keys, | |
[String]$queryString, | |
) | |
foreach ($consul_key in $consul_keys) { | |
consul kv get -recurse $consul_key_ | | |
Select-String $queryString |
NR | CODE | COMMENT |
---|---|---|
#1 | response = requests.get(url,...) |
within a try block, create variable with a response object |
#2 | response.raise_for_status() |
raises exception 4xx & 5xx HTTP Statuses/errors |
#3 | except requests.exceptions.RequestException as e: |
exception base class for all other exceptions |
#4 | print(e, file=sys.stderr) |
print exception object into stderr stream |
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
function test-certificate([string[]]$domains, $contextLength = 10, [switch]$download) { | |
$cacertPath = "${env:USERPROFILE}\cacert.pem" | |
if (-not(Test-Path $cacertPath)) { | |
Invoke-WebRequest "https://curl.se/ca/cacert.pem" -OutFile "${env:USERNAME}\cacert.pem" | |
} | |
foreach ($domain in $domains) { | |
$connectDomain = $domain + ":443" | |
if ($download) { | |
echo "q" | | |
openssl s_client -servername $domain -connect $connectDomain -CAfile $cacertPath | |
ATTRIBUTE | ON PREM | CLOUD |
---|---|---|
COSTS_INIT | great / CAPEX (capital expenses) | small / OPEX (operational/variable expense) |
COSTS_MAINTENANCE | expensive / need to staff data center (DC) | elastic / cheaper (economies of scale) |
COMPLIANCE | own responsibility | shared responsibility model / less risk |
DEPLOYMENT_PACE | slow | fast / efficient (economies of scale) / go global in minutes |
FORECASTING | difficult / imprecise | elastic scaling |
FINANCING | no money no honey | speed and agility / test capacity against real users with minimal costs |
RELIABILITY | additional dimension / failovers required | global infra built with reliability in mind |
TYPE NAME | DESCRIPTION |
---|---|
AT_SEQUENCE_NUMBER |
Start reading from the position denoted by a specific sequence number, provided in the value StartingSequenceNumber. |
AFTER_SEQUENCE_NUMBER |
Start reading right after the position denoted by a specific sequence number, provided in the value StartingSequenceNumber. |
AT_TIMESTAMP |
Start reading from the position denoted by a specific timestamp, provided in the value Timestamp. |
TRIM_HORIZON |
Start reading at the last untrimmed record in the shard in the system, which is the OLDEST data record in the shard. |
LATEST |
Start reading just after the most recent record in the shard, so that you always read the NEWEST data record in the shard. |
the puzzle is, how to assign a match in regex search to a new variable: to test-path it and eventually create a folder, if the test fails.
Use the -match
with your regex and find the matches in the build-in $matches
hash table!
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
function test-certificate($domain, $contextLength = 10) { | |
$cacertPath = "c:\cacert.pem" | |
$domain += ":443" | |
echo "q" | openssl s_client -connect $domain -CAfile $cacertPath | openssl x509 -noout -enddate | sls "notAfter.*" | |
echo "q" | openssl s_client -connect $domain -CAfile $cacertPath | sls "certificate chain" -Context $contextLength | |
Write-Host "~~~" -ForegroundColor darkcyan | |
Write-Host "→ If needed, pass a desired output length after domainname" -ForegroundColor darkcyan | |
Write-Host "→ To update the list of trusted Certificates, run:" -ForegroundColor darkcyan | |
Write-Host "→ Invoke-WebRequest https://curl.se/ca/cacert.pem -OutFile 'c:\cacert.pem'" -ForegroundColor darkcyan |