-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathawscli_plugin.py
More file actions
43 lines (30 loc) · 1.05 KB
/
awscli_plugin.py
File metadata and controls
43 lines (30 loc) · 1.05 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import requests
from botocore.auth import AUTH_TYPE_MAPS
from botocore.auth import BaseSigner
from requests.auth import HTTPBasicAuth
def make_signing_request(request):
basic = HTTPBasicAuth(os.environ["USER"], "password")
resp = requests.post("http://localhost:8000", json=request, auth=basic)
return resp.json()
class ExternalSigner(BaseSigner):
REQUIRES_REGION = False
def __init__(self, credentials):
pass
def add_auth(self, request):
ea_request = dict(
method=request.method,
url=request.url,
params=request.params,
headers=dict(request.headers),
)
response = make_signing_request(ea_request)
request.url = response["url"]
request.headers = response["headers"]
def choose_signer(*args, **kwargs):
return "mysigner"
def awscli_initialize(event_hooks):
if os.environ.get("AWS_SKIP_SIGNER", "0") != "0":
return
AUTH_TYPE_MAPS["mysigner"] = ExternalSigner
event_hooks.register("choose-signer.s3", choose_signer)