From 39c2f883e7d527d3f85a8bc29c41322069f3b45b Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 21 Sep 2024 12:35:50 -0400 Subject: [PATCH] Add script to combine `cb uri` with URL munging to access via tailscale --- local/bin/cb-uri-tailscale | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 local/bin/cb-uri-tailscale diff --git a/local/bin/cb-uri-tailscale b/local/bin/cb-uri-tailscale new file mode 100755 index 0000000..6cf9434 --- /dev/null +++ b/local/bin/cb-uri-tailscale @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +import subprocess +import sys +import urllib.parse + + +def main(sysargs=sys.argv[:]): + cb_uri = subprocess.check_output(["cb", "uri", *sysargs[1:]], text=True) + + parsed_cb_uri = urllib.parse.urlsplit(cb_uri) + tailscale_cb_uri = parsed_cb_uri._replace( + netloc=str(parsed_cb_uri.username) + + ":" + + str(parsed_cb_uri.password) + + "@" + + str(parsed_cb_uri.hostname).split(".")[1] + + ":" + + str(parsed_cb_uri.port) + ) + + print(tailscale_cb_uri.geturl()) + + return 0 + + +if __name__ == "__main__": + sys.exit(main())