Skip to content

Instantly share code, notes, and snippets.

View brmzkw's full-sized avatar

Julien Castets brmzkw

  • Freelancer for app.koyeb.com and beta.gouv.fr. Previously scaleway.com
  • France
View GitHub Profile
@brmzkw
brmzkw / ratelimit.go
Created February 12, 2024 10:55
chain rate limiting golang
package main
import (
"fmt"
"time"
"golang.org/x/time/rate"
)
func deploy(quotas map[string]*rate.Limiter, orga string, service string) bool {
@brmzkw
brmzkw / gist:de597da4cdbda4476b62f9019b91242e
Created November 17, 2021 10:56
Decrypt AWX credentials
AWX credentials are encrypted with django SECRET_KEY.
If you have access to the container `awx_web`, you can follow the following procedure to decrypt secrets.
$> docker exec -ti awx_web bash
$> source /var/lib/awx/venv/awx/bin/activate
$> awx-manage shell
$> python
>>> CREDENTIAL_ID = xxx # replace me
>>> from awx.main.models import Credential
Infra:
- laptop
- server
- container where commands can be executed
Steps:
- install and run ssh on the container
@brmzkw
brmzkw / gist:0992ff2399cb64edd24c59ddbea7debd
Created February 24, 2020 11:15
VLAN over GRE TAP tunnel
ip link add enp1s1 type gretap remote <other host> local <me>
ip link add link enp1s1 name enp1s1.1337 type vlan id 1337
ip link set dev enp1s1 up
ip link set dev enp1s1.1337 up
ip addr add 10.0.0.1/24 dev enp1s1.1337
"""This snippet uses Scaleway APIs to:
- Create a PostgreSQL database
- Create a S3 bucket
- Create one loadbalancer
- Create 3 instances and install nginx with cloud-init
- Attach instances to the loadbalancer
Install dependencies with `pip install boto3 requests`.
@brmzkw
brmzkw / view-long-saltcommands.py
Created December 12, 2018 09:32
View long salt commands
#!/usr/bin/env python
import argparse
import datetime
import re
import sys
SALT_LOGLINE_DATE_REGEXP = r'^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3})'
SALT_LOGLINE_DATE_FORMAT = '%Y-%m-%d %H:%M:%S,%f'
@brmzkw
brmzkw / json_to_shell.py
Created May 11, 2018 01:14
JSON to shell
import json
import pipes
def shell(json_input):
""" Flattens a JSON-dict as a list of key-value pairs.
For each key/value of the dictionary:
- "Simple" elements (strings, bools, integers) are represented as a string
"KEY=value". pipes.quote is used to handle escaping.
### Keybase proof
I hereby claim:
* I am brmzkw on github.
* I am jcastets (https://keybase.io/jcastets) on keybase.
* I have a public key ASCsYcb7hY6KnFaDkjc_5SpezhhOVWCkr-i8KNSCPgfNrAo
To claim this, I am signing this object:
@brmzkw
brmzkw / dynpydoc.py
Last active June 21, 2016 10:47
Override method pydoc in subclasses
class DynPyDoc(type):
def __new__(cls, name, bases, attrs):
start_match = 'pydoc_for_'
for attr_name, attr_value in attrs.items():
if attr_name.startswith(start_match):
method_name = attr_name[len(start_match):]