Skip to content

Instantly share code, notes, and snippets.

View gbvanrenswoude's full-sized avatar

Gijs van Renswoude gbvanrenswoude

View GitHub Profile
@gbvanrenswoude
gbvanrenswoude / convert.sh
Created May 15, 2020 11:13
convert json to html in bash (using python)
python - <<EOF
from json2html import *
with open("report.json", "r") as f:
with open("report.html", "w") as nf:
nf.write(json2html.convert(json = f.read()))
EOF
@gbvanrenswoude
gbvanrenswoude / graph-out.sh
Created May 15, 2020 19:51
graph terraform infra out for architecture
terraform graph | dot -Tsvg > graph.svg
inkscape -z -e frontofficev2.png -w 1000 -h 1000 graphg.svg
@gbvanrenswoude
gbvanrenswoude / alb-oidc.py
Last active April 8, 2021 13:26
oidc-on-aws-alb with aws cdk (python)
from aws_cdk import (
core,
aws_elasticloadbalancingv2 as elbv2,
aws_secretsmanager as sm
)
[...]
secret_bundle = sm.Secret.from_secret_arn(
self,
# Talk to an AWS IAM protected ElasticSearch cluster
# Since its pretty hard to resort for this kind of stuff to curl (or extentions on it) we use Python
# Also, since its bothersome to check for the correct credentials place (disk, env, metadata endpoint, containerdata endpoint)
# its better to just peel out SigV4Auth from botocore.auth
# pip3 install boto3 requests
import boto3
from botocore.auth import SigV4Auth
from botocore.awsrequest import AWSRequest
import requests, sys
from requests_aws4auth import AWS4Auth
import boto3
import requests
credentials = boto3.Session().get_credentials()
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, 'eu-central-1', 'es', session_token=credentials.token)
r = requests.get(url, auth=awsauth)
@gbvanrenswoude
gbvanrenswoude / grafana-dashboard-handler.py
Created July 8, 2021 13:18
A grafana dashboard CR handler leveraging requests.
import json
import os
import requests
from requests.structures import CaseInsensitiveDict
headers = {"Accept": "application/json","Content-Type": "application/json" ,"Authorization": "Bearer " + os.environ['grafana_pw']}
# package dashboard with on the fs since usually the string is too long
with open("dashboard.json") as file:
@gbvanrenswoude
gbvanrenswoude / proxy-wss-to-request-authorizer.ts
Last active August 30, 2021 17:13
AWS API Gateway v2 Websocket API - Custom Lambda Authorizer for JWT Token
// Proxies https://github.com/ottokruse/aws-apigw-authorizer to function as a Custom Authorizer for AWS API Gatewayv2 Websocket Custom Authorizer when sending JWT tokens.
// Send your JWT token as a querystringparameter 't' in the connection url to your Websocket api
// or set your own querystringparameter name using process.env.webSocketQueryStringParameterName
import { ApiGatewayAuthorizer } from 'aws-apigw-authorizer';
import * as AWSLambda from 'aws-lambda';
const lambdaAuthorizer = new ApiGatewayAuthorizer({ policyBuilder: customPolicyBuilder });
// NOTE type checking seems off in the source, this does not return a AWSLambda.PolicyDocument, but we ignore it
@gbvanrenswoude
gbvanrenswoude / index.py
Last active September 17, 2021 14:48
eventbridge-lambda-model-premade-AWSEvent
from schema.your_schema_openapiv3 import Event
from schema.your_schema_openapiv3 import AWSEvent
from schema.your_schema_openapiv3 import Marshaller
import json
def lambda_handler(event, context):
"""function
Parameters
----------
@gbvanrenswoude
gbvanrenswoude / index.py
Created September 17, 2021 14:51
custom-event-bridge-code-binding
# Lets take a simple event
# and event.json is the jsonschema of it
# {
# "administration": "YOURBACKOFFICECODE",
# "personNumber": 1337
# }
import json
from logging import getLogger, INFO
@gbvanrenswoude
gbvanrenswoude / whoof.json
Created October 27, 2021 21:46
whoof.json OAS
{
"openapi": "3.0.1",
"info": {
"title": "fwhoof",
"version": "2021-10-17T18:09:20Z"
},
"servers": [
{
"url": "https://whoof.corp"
}