Skip to content

Instantly share code, notes, and snippets.

View andymotta's full-sized avatar

Andy Motta andymotta

View GitHub Profile
@andymotta
andymotta / 2s3.py
Created August 9, 2017 03:21
Watch a directory for changes with Python Watchdog then multipart upload to S3
import sys
import os
import time
from watchdog.observers import Observer
from watchdog.events import FileModifiedEvent, FileCreatedEvent
import boto3
import mimetypes
from botocore.exceptions import ClientError
# Create an S3 client
@andymotta
andymotta / credentials.py
Created June 14, 2017 00:24
Read or Write to ~/.aws/credentials file with SafeConfigParser
from ConfigParser import SafeConfigParser
credentials = os.path.join(os.environ['HOME'], '.aws', 'credentials')
parser = SafeConfigParser()
parser.read(credentials)
print parser.get('default', 'aws_access_key_id',)
parser.set('default', 'aws_access_key_id', 'AKXXX55555XXXXXXXXXA')
parser.set('default', 'aws_secret_access_key', 'XXXXXXXXXX00000/555XXXXX555555555XXXXX')
@andymotta
andymotta / find_user_from_access_key.py
Last active June 22, 2022 11:17
Find an AWS IAM user corresponding to an AWS Access Key (boto3)
# Find the IAM username belonging to the TARGET_ACCESS_KEY
import boto3
from botocore.exceptions import ClientError
iam = boto3.client('iam')
def find_user(key):
try:
key_info = iam.get_access_key_last_used(AccessKeyId=key)
@andymotta
andymotta / strokeit.py
Last active August 15, 2017 00:00
Wrapper to scan network with built-in OS X port scanner
#!/usr/bin/env python3
# python3 strokeit.py 192.168.1.0/24 0 1024
import subprocess
import ipaddress
import os
import sys
strokeEC="/System/Library/CoreServices/Applications/Network Utility.app/Contents/Resources/stroke"
@andymotta
andymotta / buckets_public_read.py
Last active December 9, 2017 03:07
Compliance: Find S3 buckets with public access, send offending statements to SNS topic
#!/usr/bin/env python
import json
import boto3
import botocore
s3 = boto3.resource('s3')
client = boto3.client('s3')
sns = boto3.client('sns')
@andymotta
andymotta / main.yml
Last active August 18, 2022 14:34
Trigger Jenkins job with Ansible
---
- name: trigger jenkins job
shell: "{{ lookup('template', 'trigger-jenkins.j2') }}"
delegate_to: localhost
- name: wait for job to complete
wait_for:
path: {{ lockfile }}
timeout: 600
@andymotta
andymotta / ansiBool.yml
Created October 5, 2016 15:53
Force JSON boolean in json jinja template
query_boolean: false
query_string: "{{ query_boolean | bool | to_json }}"