Skip to content

Instantly share code, notes, and snippets.

View mmerickel's full-sized avatar

Michael Merickel mmerickel

View GitHub Profile
@mmerickel
mmerickel / aws-profile.sh
Last active February 6, 2024 17:10
a bash / zsh compatible alias that can assist in switching between aws profiles and triggering sso login if necessary
aws-profile() {
read -r -d '' SCRIPT <<'EOF'
import argparse
from configparser import RawConfigParser
import os
import shutil
import subprocess
import sys
from textwrap import dedent
@mmerickel
mmerickel / ssm-proxy.sh
Last active November 11, 2023 20:23
Connect to AWS instance using SSM and ec2-instance-connect with public access, and no shared keys.
#!/bin/bash
# Install an SSH key on an instance automatically and then configure an
# SSM proxy to the instance which will be used by SSH.
#
# Copy this script to ~/.ssh/ssm-proxy and make it executable:
#
# chmod +x ~/.ssh/ssm-proxy
#
# This script should be set as the ProxyCommand. For example:
#
@mmerickel
mmerickel / .env
Last active June 5, 2023 09:09
render an ini file based on env vars
##############################################################################
# Settings made available in site.ini.in.
#
# After making changes re-run render-config
#
# Override settings by making a .env.local file.
##############################################################################
DEBUG=yes
WEB_CONCURRENCY=10
@mmerickel
mmerickel / cors.py
Last active December 6, 2022 14:13
cors in pyramid
from pyramid.security import NO_PERMISSION_REQUIRED
def includeme(config):
config.add_directive(
'add_cors_preflight_handler', add_cors_preflight_handler)
config.add_route_predicate('cors_preflight', CorsPreflightPredicate)
config.add_subscriber(add_cors_to_response, 'pyramid.events.NewResponse')
class CorsPreflightPredicate(object):
import collections
class DictProxy(collections.Mapping):
"""
A proxy for a dictionary that allows attribute access to underlying keys.
You may pass a custom ``wrapper`` to override the logic for wrapping
various custom types.
"""
@mmerickel
mmerickel / factory.py
Last active June 1, 2022 19:19
session proxy
cookie_state = {
'session_id': session_id,
'is_deleted': False,
}
def update_cookie(request, response):
exc = getattr(request, 'exception', None)
# exit early if there's an exception and the user specified
@mmerickel
mmerickel / pyproject.toml
Created December 13, 2020 23:12
poetry config for pyramid scaffold
[tool.poetry]
name = "pyramid_scaffold"
version = "0.1.0"
description = "Pyramid Scaffold"
authors = []
classifiers = [
"Programming Language :: Python",
"Framework :: Pyramid",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
@mmerickel
mmerickel / Dockerfile
Last active February 11, 2022 19:25
istio-launcher for implementing graceful shutdown and one-off job termination
FROM ...
COPY istio-launcher.py /app/istio-launcher.py
ENTRYPOINT ["tini", "--", "/app/istio-launcher.py"]
import argparse
import boto3
from collections import defaultdict
import csv
from datetime import datetime, timedelta
import logging
from pprint import pprint
import queue
import signal
import sys
@mmerickel
mmerickel / basic_auth_example.py
Last active April 27, 2021 18:27
Basic Auth in Pyramid with simple ACLs
from pyramid.authentication import BasicAuthAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.config import Configurator
from pyramid.httpexceptions import HTTPForbidden
from pyramid.httpexceptions import HTTPUnauthorized
from pyramid.security import ALL_PERMISSIONS
from pyramid.security import Allow
from pyramid.security import Authenticated
from pyramid.security import forget
from pyramid.view import forbidden_view_config