Skip to content

Instantly share code, notes, and snippets.

@Xiol
Xiol / README.md
Last active June 20, 2024 08:16
Extend Gitlab access token expiry dates

Extend Gitlab Access Tokens

Gitlab enforced token expiry limits to 365 days last year, and the time is now upon us.

They don't have an opt-out for this, and haven't provided a way to easily extend tokens in the web interface. They have also gated their credential management interface behind their Ultimate license.

This quickly thrown together script will allow you to add an extra year to all tokens that expire in the next 30 days. It will not reactivate tokens that have already expired.

Requires the python-gitlab module. Edit your self-hosted Gitlab instance details into the script and run it. It will dump out CSVs of all expiring tokens, and then dump out a list of commands you can paste into a gitlab-rails console session to extend the expiry date by another year. If you need them to be active for longer, change 1.year.from_now to the value of your choice, e.g. `10.years.fro

@Xiol
Xiol / git2go-checkout-branch.go
Created March 1, 2017 08:37 — forked from danielfbm/git2go-checkout-branch.go
How to do a git checkout branch using git2go
package main
import (
"errors"
"log"
"github.com/libgit2/git2go"
)
func checkoutBranch(repo *git.Repository, branchName string) error {
checkoutOpts := &git.CheckoutOpts{
#!/usr/bin/env python3
# Given a load of HTML pages from the BBC Food website, this script will
# scrape the recipes from the HTML and output them in structured JSON format.
import argparse
import sys
import os
import json
import base64
from bs4 import BeautifulSoup
@Xiol
Xiol / primary_ip.py
Created October 8, 2015 11:18
Salt grain for discovering primary IP address on a Linux machine.
#!/usr/bin/env python
import subprocess
def linux_get_primary_ip4():
grains = {}
try:
defroute_device = subprocess.check_output("ip route | grep default | grep -Eo 'dev\s+\w+' | awk '{print $2}'", shell=True).strip()
devip = subprocess.check_output("ip a s {0} | grep -E 'inet\s' | cut -d'/' -f1 | awk '{{print $2}}'".format(defroute_device), shell=True).strip()
except subprocess.CalledProcessError as e:
@Xiol
Xiol / bacula_b64decode.py
Created May 28, 2014 08:42
Bacula Base64 decode implementation in Python
# This is a Python implementation of the Perl code from the following link
# http://bacula.10910.n7.nabble.com/The-File-LStat-field-td3960.html
# Bacula uses a custom base64 implementation to encode file stats
# This should allow us to decode the values in the lstat field in the Bacula DB
B64_VALS = {
'+': 62, '/': 63, '1': 53, '0': 52, '3': 55, '2': 54, '5': 57,
'4': 56, '7': 59, '6': 58, '9': 61, '8': 60, 'A': 0, 'C': 2,
'B': 1, 'E': 4, 'D': 3, 'G': 6, 'F': 5, 'I': 8, 'H': 7, 'K': 10,
'J': 9, 'M': 12, 'L': 11, 'O': 14, 'N': 13, 'Q': 16, 'P': 15,