47 lines
2.6 KiB
Python
47 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""gitea_egress.py LABEL — D57 on 9202: what may Gitea's repository import (migration) reach? Installs Gitea from the
|
|
drill through the product (the box fixture's own first-run installer = the admin), then asks POST /api/v1/repos/migrate
|
|
for: a LAN address (192.168.0.1), a docker-internal one (traefik on 172.18.0.x), a small public GitHub repo, and a public
|
|
host that an allow-list would not name (gitea.com). Prints and writes egress-LABEL.json; removes the app at the end.
|
|
usage: SC=<dir with .ctlpw> TARGET=9202 EV=<dir> python3 gitea_egress.py LABEL"""
|
|
import json, os, secrets, sys
|
|
sys.path.insert(0, "/mnt/5_hdd/felhom.eu/git/app-catalog-felhom.eu/scripts")
|
|
import box_walk as w
|
|
import upgrade_fixtures_box as fb
|
|
label, EV = sys.argv[1], os.environ["EV"]
|
|
os.makedirs(EV, exist_ok=True)
|
|
sub = "git"
|
|
w.login()
|
|
res = {"label": label}
|
|
try:
|
|
if w.stack("gitea").get("deployed"):
|
|
w.remove("gitea")
|
|
w.refresh_box_mirror(); w.sync_rescan()
|
|
if not w.deploy("gitea", sub):
|
|
print("install failed"); sys.exit(1)
|
|
t = fb.Gitea().seed(w, sub, w.say)
|
|
if not t:
|
|
print("seed failed"); sys.exit(1)
|
|
res["image"] = w.guest("docker inspect -f '{{.Config.Image}}' gitea").strip()
|
|
res["egress_env"] = [l for l in w.guest("docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' gitea").split("\n")
|
|
if "migrations" in l or "EGRESS" in l]
|
|
traefik = w.guest("docker inspect -f '{{with index .NetworkSettings.Networks \"traefik-public\"}}{{.IPAddress}}{{end}}' traefik").strip()
|
|
targets = {"lan": "http://192.168.0.1/x.git", "docker_internal": f"http://{traefik}/x.git",
|
|
"github": "https://github.com/octocat/Hello-World.git", "not_listed_public": "https://gitea.com/gitea/act_runner.git"}
|
|
for k, url in targets.items():
|
|
rc, code, body = w.app_curl(sub, "/api/v1/repos/migrate", "-u", f"{t['user']}:{t['pw']}",
|
|
"-H", "Content-Type: application/json",
|
|
data=json.dumps({"clone_addr": url, "repo_name": "mig" + k.replace("_", "") + secrets.token_hex(2),
|
|
"service": "git", "private": True}), method="POST", timeout=180)
|
|
try:
|
|
msg = json.loads(body).get("message", "")[:160]
|
|
except ValueError:
|
|
msg = (body or "")[:160]
|
|
res[k] = {"url": url, "http": code, "message": msg}
|
|
print(k, code, msg)
|
|
finally:
|
|
json.dump(res, open(os.path.join(EV, f"egress-{label}.json"), "w"), indent=1)
|
|
if w.stack("gitea").get("deployed"):
|
|
w.remove("gitea")
|
|
print("\n".join(w.LOG[-2:]))
|