Add script to combine cb uri with URL munging to access via tailscale

This commit is contained in:
Dan Buch 2024-09-21 12:35:50 -04:00
parent 950d1a928e
commit 39c2f883e7
Signed by: meatballhat
GPG Key ID: A12F782281063434

27
local/bin/cb-uri-tailscale Executable file
View File

@ -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())