"""AWS CLI v2 plugin: reach S3 on a private exe.dev VM with a VM token. Adds `X-Exedev-Authorization: Bearer ` to S3 requests for *.exe.xyz hosts, reading the token from ~/.config/exedev/vm-token (or the file named by EXEDEV_TOKEN_FILE). It runs after SigV4 signing (before-send), so the header isn't signed and the exe.dev proxy can strip it. Other hosts, such as Amazon S3, never see the token. """ import os from urllib.parse import urlsplit def _add_token(request, **kwargs): host = urlsplit(request.url).hostname or "" if not host.endswith(".exe.xyz"): return path = os.path.expanduser(os.environ.get("EXEDEV_TOKEN_FILE", "~/.config/exedev/vm-token")) with open(path) as f: request.headers["X-Exedev-Authorization"] = "Bearer " + f.read().strip() def awscli_initialize(cli): cli.register("before-send.s3", _add_token)