Skip to content

Instantly share code, notes, and snippets.

Xiol /
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 / 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 (
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 /
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 = {}
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 /
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
# 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,