示例#1
0
文件: v2.py 项目: redsymbol/faws
def signed_request_basic(method, service_endpoint, params, creds, timestamp_val):
    from urllib.parse import urlparse
    sig_params = dict(params)
    sig_params.update({
        'Timestamp'        : timestamp_val,
        'SignatureMethod'  : 'HmacSHA256',
        'SignatureVersion' : '2',
        'AWSAccessKeyId'   : creds.access_key,
        })
    parsed_url = urlparse(service_endpoint)
    netloc = parsed_url.hostname.lower()
    if parsed_url.port not in {80, 443, None}:
        netloc += ':' + str(parsed_url.port)
    string_to_sign_value = string_to_sign(method, netloc, parsed_url.path, sig_params)
    sig_params['Signature'] = signature(string_to_sign_value, creds.secret_key)
    url = build_url(service_endpoint, sig_params)
    aux = {
        'string_to_sign_value' : string_to_sign_value,
        'sig_params' : sig_params,
        'signature' : sig_params['Signature'],
        }
    return SignedRequestInfo(
        headers = {},
        url     = url,
        payload = None,
        aux     = aux,
        )
示例#2
0
文件: v4.py 项目: redsymbol/faws
def signed_request(service, params, creds, when=None):
    from urllib.parse import urlparse
    service_name = service.name
    method = service.method
    if 'GET' == method:
        url = build_url(service.endpoint(), params)
        data = None
    else:
        url = service.endpoint()
        data = params
    headers = {
        'Date' : when.strftime(DATETIME_HTTP_F),
        'Host' : urlparse(url).hostname,
        'Content-Type': 'application/json',
        }
    return signed_request_basic(
        method,
        service_name,
        url,
        headers,
        datadict2payload(data),
        creds,
        when,
        )