Skip to content

Instantly share code, notes, and snippets.

Avatar
🏡
Staying home

Chris Adams acdha

🏡
Staying home
View GitHub Profile
View register-qualys-assetview-connector-accounts.py
#!/usr/bin/env python3
"""
Bulk register AWS Accounts with Qualys AssetView
Given a list of account IDs, registers them and prints CSV output of the Account
ID and External ID in the format expected by the account setup Terraform code.
A list of accounts to register can be obtained like this::
$ grep -vf <(csvgrep --invert-match --columns 'External ID' --regex '^$' account-setup/qualys-assetview-accounts.csv | csvcut -c 'Account ID' | sed 1d) \
View eternal-march.py
from datetime import date
ordinal = lambda n: "%d%s" % (n, "tsnrhtdd" [(n // 10 % 10 != 1) * (n % 10 < 4) * n % 10::4])
dom = date.today() - date(year=2020, month=3, day=1)
print(f"Today is March {ordinal(dom.days)}, 2020")
View ansible.cfg
[defaults]
interpreter_python = auto_silent
vault_password_file=get_vault_password_from_keyring
[ssh_connection]
# Enabling pipelining reduces the number of SSH operations required to
# execute a module on the remote server. This can result in a significant
# performance improvement when enabled, however when using "sudo:" you must
# first disable 'requiretty' in /etc/sudoers
#
@acdha
acdha / development.aws_ec2.yaml
Created Aug 10, 2020
Ansible dynamic inventory using EC2 tags
View development.aws_ec2.yaml
---
plugin: aws_ec2
regions:
- us-east-1
filters:
instance-state-name: running
tag:Project: MyProject
tag:Environment: Development
hostnames:
- instance-id
@acdha
acdha / update_cloudflare_ingress_groups.py
Last active Jul 22, 2020
Ensure that AWS security groups have a list of the current Cloudflare CIDR ranges
View update_cloudflare_ingress_groups.py
#!/usr/bin/env python3
"""
Ensure that every security group tagged with 'AllowCloudflareIngress' has
an ingress rule allowing HTTPS in from every public Cloudflare edge IPv4 and
IPv6 CIDR block.
Note that HTTP is intentionally not enabled: use the always-HTTPS page rule for
that to avoid potential security problems.
"""
@acdha
acdha / tasks.json
Last active May 21, 2019
VSCode task for gulp watch output capturing
View tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "gulp",
"task": "watch",
"label": "gulp: watch",
"isBackground": true,
"presentation": {
"reveal": "always",
@acdha
acdha / expand-tagging-policy-template.py
Last active Apr 9, 2019
Utility to expand a YAML template into a cloud-custodian policy for taggable AWS resources
View expand-tagging-policy-template.py
#!/usr/bin/env python
# encoding: utf-8
"""
Given a YAML template, expand the `policy_templates` in the provided YAML
template and generate a YAML file containing each policy expanded for every
taggable AWS resource type.
"""
from __future__ import absolute_import, division, print_function
@acdha
acdha / dom-utilities.js
Created Mar 28, 2019
Simple ES6 utilities which come up on various projects
View dom-utilities.js
export function emptyNode(node) {
while (node.lastChild) {
node.lastChild.remove();
}
}
export function sortChildren(container, sortKeyGenerator) {
/*
Sort all child nodes in a given container using the provided
sortKeyExtractor function to obtain the sort key. The values should be
@acdha
acdha / mirror-ecs-task-environment.sh
Created Sep 7, 2018
Using jq to export bash-compatible exports for an AWS ECS task definition's environment stanza
View mirror-ecs-task-environment.sh
aws ecs describe-task-definition --task-definition=sentry | jq -r '.taskDefinition.containerDefinitions[] | .environment[] | "export \(.name)=\(.value)"'
@acdha
acdha / homepage.html
Created Jun 21, 2018
WDL Homepage Carousel: minimal source extraction
View homepage.html
<div id="featured-items-container" class="well">
<div id="featured-items" class="multi-carousel" data-json-url="{% url 'featured-items-json' %}">
<ul class="items list-unstyled list-inline">
{% for wdl_id, thumbnail_ts, title in featured_items|slice:":5" %}
<li class="item" data-wdl-id="{{ wdl_id|unlocalize }}">
<a href="{% url 'item-detail' wdl_id=wdl_id %}" title="{{ title }}">
<img class="img-rounded" width="308" height="255" src="{% media_url 'item-thumbnail' wdl_id=wdl_id height=255 width=308 timestamp=thumbnail_ts %}" alt="{{ title }}">
<span class="caption">{{ title }}</span>
</a>
</li>
You can’t perform that action at this time.