Skip to content

Instantly share code, notes, and snippets.

View pmarques's full-sized avatar

Patrick Marques pmarques

  • Proofpoint
  • London
View GitHub Profile
@pmarques
pmarques / vm_power_state.csl
Last active July 21, 2021 09:05
Azure Resource Graph Queries
// Number of VMs by PowerState
// Filter per:
// * Management Group
// * Tags
Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| where tags.service =~ "svc1" and tags.application in~ ("app1", "app2")
| join kind=inner (
ResourceContainers
| where type == "microsoft.resources/subscriptions" and properties.managementGroupAncestorsChain[0].name in ("staging", "prod")
@pmarques
pmarques / gcloud-member-roles.sh
Last active June 3, 2021 15:36
gcloud IAM member roles
gcloud projects get-iam-policy ${GOOGLE_CLOUD_PROJECT} \
--flatten='bindings[].members' \
--format='table(bindings.role)' \
--filter="bindings.members:${MEMBER_EMAIL}"
@pmarques
pmarques / s3-destination.yaml
Last active November 11, 2019 13:30
AWS CloudFormation files with S3 buckets and resources needed for Cross-Account / Region replication with Owner[ship] override
---
Description: >
Create a simple encrypted S3 bucket
Parameters:
BucketName:
Type: String
Default: pmarques1234567890-x-account-replication
SourceAccount:
Type: String
Resources:
@pmarques
pmarques / dummy-resource.yaml
Created September 6, 2019 09:38
Cloudformation template with a simple resource for testing
AWSTemplateFormatVersion: 2010-09-09
Parameters:
ResourceName:
Type: String
MinLength: 1
Resources:
DummyResource:
Type: AWS::CloudWatch::Dashboard
@pmarques
pmarques / octokit_test.js
Last active June 16, 2019 13:29
Fetch file from private github repo
const Octokit = require('@octokit/rest')
const octokit = new Octokit({
auth: "<my github access token",
userAgent: "pmarques 1.0" // tried with and without
})
octokit.repos.getContents({
"owner": "ansible",
"repo": "ansible",
"path": "README.rst",
"ref": "devel"
@pmarques
pmarques / aws-redirect-service.yaml
Created April 15, 2019 12:48
Use AWS LoadBalancer V2 to redirect traffic.
---
Resources:
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow http to client host
VpcId: "vpc-1"
SecurityGroupIngress:
- IpProtocol: tcp
@pmarques
pmarques / gist:2d0d016db579126cf4ee6f59f7ec1519
Last active February 15, 2018 23:30
Windows alias/functions
# How to install, tested in Windows Server R2012
# Write the functions in file %HOMEPATH\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
#
function checkPort {
New-Object System.Net.Sockets.TcpClient($args[0], $args[1])
}
# Test it
# C:\> checkPort "127.0.0.1" 80
@pmarques
pmarques / awscli-snippets.sh
Last active December 7, 2017 20:03
Useful AWS CLI snippets
# Delete buckets tagged with a key
for bucket in `aws --profile mojintegration s3api list-buckets --query "Buckets[].Name" --output text` ; doecho -n "Bucket: [${bucket}]: " ; [ "$(aws --profile mojintegration s3api get-bucket-tagging --bucket "${bucket}" --query 'TagSet[?Key==`pm` && Value==`works`].Key' --output text 2>/dev/null)" == "pm" ] && echo -e "\033[31mdelete\033[0m" || echo -e "\033[32mkeep\033[0m" ; done
# Delte old logstreams from a logGroup
LOG_GROUP=a
for streamName in $(aws --profile mojintegration logs describe-log-streams --log-group-name "${LOG_GROUP}" --query 'logStreams[?lastIngestionTime <= `1502092833000`].logStreamName' --output text) ; do aws --profile mojintegration logs delete-log-stream --log-group-name "${LOG_GROUP}" --log-stream-name "${streamName}" ; done
# Delte log grouos which name starts with <LOG_GROUP>
for logGroup in $(aws --profile mojintegrations logs describe-log-groups --query "logGroups[?starts_with(logGroupName, \`${LOG_GROUP}\`)].logGroupName" --output text) ; d

Keybase proof

I hereby claim:

  • I am pmarques on github.
  • I am pmarques (https://keybase.io/pmarques) on keybase.
  • I have a public key whose fingerprint is FFC5 303F 47F1 89C8 515A D807 D67D B7CB 1472 CB5B

To claim this, I am signing this object:

@pmarques
pmarques / azcli-snippets.sh
Created November 3, 2017 10:56
Useful AZ CLI snippets
R_GROUP=a
# Delete all VMs in a group
az vm list --resource-group "${R_GROUP}" | jq '.[] .id' | xargs az vm delete --yes --ids