~sircmpwn/builds.sr.ht

builds.sr.ht/buildsrht-keys -rwxr-xr-x 985 bytes
570f7196Francesco Gazzetta Remove end-of-life NixOS 20.09 15 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
from srht.config import cfg, get_origin
import os
import requests
import sys

key_type = sys.argv[3]
b64key = sys.argv[4]

def fail(reason):
    owner = cfg("sr.ht", "owner-name")
    email = cfg("sr.ht", "owner-email")
    print(reason)
    print(f"Please reach out to {owner} <{email}> for support.")
    sys.exit(1)

meta_origin = get_origin("meta.sr.ht")
r = requests.get(f"{meta_origin}/api/ssh-key/{b64key}")
if r.status_code == 200:
    username = r.json()["owner"]["name"]
elif r.status_code == 404:
    fail("We don't recognize your SSH key. Make sure you've added it to " +
        f"your account.\n{get_origin('meta.sr.ht', external=True)}/keys")
else:
    fail("Temporary authentication failure. Try again later.")

default_shell = os.path.join(os.path.dirname(sys.argv[0]), "master-shell")
shell = cfg("builds.sr.ht", "shell", default=default_shell)
print(f"restrict,pty,command=\"{shell} '{username}'\" {key_type} {b64key} somebody\n")
sys.exit(0)