Esempio n. 1
0
 def calc_signature(self, request, params):
     logger.debug("Calculating signature using v2 auth.")
     split = urlsplit(request.url)
     path = split.path
     if len(path) == 0:
         path = '/'
     string_to_sign = '%s\n%s\n%s\n' % (request.method,
                                        split.netloc,
                                        path)
     lhmac = hmac.new(self.credentials.secret_key.encode('utf-8'),
                      digestmod=sha256)
     pairs = []
     for key in sorted(params):
         # Any previous signature should not be a part of this
         # one, so we skip that particular key. This prevents
         # issues during retries.
         if key == 'Signature':
             continue
         value = six.text_type(params[key])
         pairs.append(quote(key.encode('utf-8'), safe='') + '=' +
                      quote(value.encode('utf-8'), safe='-_~'))
     qs = '&'.join(pairs)
     string_to_sign += qs
     logger.debug('String to sign: %s', string_to_sign)
     lhmac.update(string_to_sign.encode('utf-8'))
     b64 = base64.b64encode(lhmac.digest()).strip().decode('utf-8')
     return (qs, b64)
Esempio n. 2
0
 def calc_signature(self, request, params):
     logger.debug("Calculating signature using v2 auth.")
     split = urlsplit(request.url)
     path = split.path
     if len(path) == 0:
         path = '/'
     string_to_sign = '%s\n%s\n%s\n' % (request.method,
                                        split.netloc,
                                        path)
     lhmac = hmac.new(self.credentials.secret_key.encode('utf-8'),
                      digestmod=sha256)
     pairs = []
     for key in sorted(params):
         # Any previous signature should not be a part of this
         # one, so we skip that particular key. This prevents
         # issues during retries.
         if key == 'Signature':
             continue
         value = six.text_type(params[key])
         pairs.append(quote(key.encode('utf-8'), safe='') + '=' +
                      quote(value.encode('utf-8'), safe='-_~'))
     qs = '&'.join(pairs)
     string_to_sign += qs
     logger.debug('String to sign: %s', string_to_sign)
     lhmac.update(string_to_sign.encode('utf-8'))
     b64 = base64.b64encode(lhmac.digest()).strip().decode('utf-8')
     return (qs, b64)
Esempio n. 3
0
 def _canonical_query_string_params(self, params):
     l = []
     for param in sorted(params):
         value = str(params[param])
         l.append('%s=%s' % (quote(param, safe='-_.~'),
                             quote(value, safe='-_.~')))
     cqs = '&'.join(l)
     return cqs
Esempio n. 4
0
def percent_encode(input_str, safe=SAFE_CHARS):
    """Urlencodes a string.

    Whereas percent_encode_sequence handles taking a dict/sequence and
    producing a percent encoded string, this function deals only with
    taking a string (not a dict/sequence) and percent encoding it.

    """
    if not isinstance(input_str, string_types):
        input_str = text_type(input_str)
    return quote(text_type(input_str).encode('utf-8'), safe=safe)
Esempio n. 5
0
 def _normalize_url_path(self, path):
     normalized_path = quote(normalize_url_path(path), safe='/~')
     return normalized_path