Exemple #1
0
 def _init_regional_endpoint_data(self, obj):
     if "regional_endpoints" not in obj:
         return
     self._regional_endpoint_data = obj["regional_endpoints"]
     for code, product_data in iteritems(obj["regional_endpoints"]):
         for region_id, endpoint in iteritems(product_data):
             self.put_endpoint_entry(self._make_endpoint_entry_key(code, region_id), endpoint)
Exemple #2
0
def build_canonical_headers(headers, header_begin):
    result = ""
    unsort_map = dict()
    for (key, value) in iteritems(headers):
        if key.lower().startswith(header_begin):
            unsort_map[key.lower()] = value
    sort_map = sorted(iteritems(unsort_map), key=lambda d: d[0])
    for (key, value) in sort_map:
        result += key + ":" + value
        result += HEADER_SEPARATOR
    return result
Exemple #3
0
 def get_signed_header(self, region_id=None, ak=None, secret=None):
     headers = {}
     for headerKey, headerValue in iteritems(self.get_headers()):
         if headerKey.startswith("x-acs-") or headerKey.startswith(
                 "x-sdk-"):
             headers[headerKey] = headerValue
     return headers
Exemple #4
0
def replace_occupied_parameters(uri_pattern, paths):
    result = uri_pattern
    if paths is not None:
        for (key, value) in iteritems(paths):
            target = "[" + key + "]"
            result = result.replace(target, value)
    return result
    def _init_global_endpoint_data(self, obj):
        if "global_endpoints" not in obj:
            return

        global_endpoints = obj["global_endpoints"]
        for location_service_code, endpoint in iteritems(global_endpoints):
            self.put_endpoint_entry(self._make_endpoint_entry_key(location_service_code), endpoint)
def _handle_param_aliases(params, aliases):
    for key, value in iteritems(aliases):
        if key in params:
            if value in params:
                raise ClientException(ERROR_INVALID_PARAMETER,
                                      "Param {0} is already set.".format(value))
            params[value] = params[key]
            del params[key]
Exemple #7
0
def __compose_string_to_sign(method, queries):
    sorted_parameters = sorted(iteritems(queries),
                               key=lambda queries: queries[0])
    sorted_query_string = __pop_standard_urlencode(
        urlencode(sorted_parameters))
    canonicalized_query_string = __pop_standard_urlencode(
        pathname2url(sorted_query_string))
    string_to_sign = method + "&%2F&" + canonicalized_query_string
    return string_to_sign
 def status_verify(self, instance):
     request = DescribeInstancesRequest()
     request.set_InstanceIds(json.dumps([instance.instance_id]))
     response = self.client.do_action_with_exception(request)
     obj = json.loads(response.decode('utf-8'))['Instances']['Instance'][0]
     for key, value in iteritems(obj):
         attr_name = self._convert_camel_to_snake(key)
         self.assertTrue(hasattr(instance, attr_name),
                         "instance has no " + attr_name)
         self.assertEqual(obj[key], getattr(instance, attr_name))
def request_helper(client, request, **params):
    for key, value in iteritems(params):
        set_name = 'set_' + key
        if hasattr(request, set_name):
            func = getattr(request, set_name)
            func(value)
        else:
            raise Exception(
                "{0} has no parameter named {1}.".format(request.__class__.__name__, key))
    response = client.do_action_with_exception(request)
    return json.loads(response.decode('utf-8'))
Exemple #10
0
def __build_query_string(uri, queries):
    sorted_map = sorted(iteritems(queries), key=lambda queries: queries[0])
    if len(sorted_map) > 0:
        uri += "?"
        for (k, v) in sorted_map:
            uri += k
            if v is not None:
                uri += "="
                uri += v
            uri += roa_signature_composer.QUERY_SEPARATOR
    if uri.find(roa_signature_composer.QUERY_SEPARATOR) >= 0:
        uri = uri[0:(len(uri) - 1)]
    return uri
def _param_expand_to_json(params, rules, singular=True):
    for key, value in iteritems(rules):
        # key is like: instance_id or instance_ids
        # value is like: InstanceIds
        if key in params:
            if singular:
                to_add = [params[key]]
            else:
                to_add = params[key]
                _assert_is_list_but_not_string(to_add, key)
            del params[key]

            if value in params:
                raise ClientException(ERROR_INVALID_PARAMETER,
                                      "Param {0} is already set.".format(value))
            params[value] = json.dumps(to_add)
Exemple #12
0
def __build_query_string(uri, queries):
    uri_parts = uri.split("?")
    if len(uri_parts) > 1 and uri_parts[1] is not None:
        queries[uri_parts[1]] = None
    query_builder = uri_parts[0]
    sorted_map = sorted(iteritems(queries), key=lambda queries: queries[0])
    if len(sorted_map) > 0:
        query_builder += "?"
    for (k, v) in sorted_map:
        query_builder += k
        if v is not None:
            query_builder += "="
            query_builder += str(v)
        query_builder += QUERY_SEPARATOR
    if query_builder.endswith(QUERY_SEPARATOR):
        query_builder = query_builder[0:(len(query_builder) - 1)]
    return query_builder
Exemple #13
0
def get_encode_str(params):
    """
    transforms parameters to encoded string
    :param params: dict parameters
    :return: string
    """
    list_params = sorted(iteritems(params), key=lambda d: d[0])
    encode_str = urlencode(list_params)
    if sys.stdin.encoding is None:
        res = quote(encode_str.decode('cp936').encode('utf8'), '')
    else:
        res = quote(
            encode_str.decode(
                sys.stdin.encoding).encode('utf8'), '')
    res = res.replace("+", "%20")
    res = res.replace("*", "%2A")
    res = res.replace("%7E", "~")
    return res
Exemple #14
0
 def _assign_attributes(self, attrs):
     for key, value in iteritems(attrs):
         setattr(self, _convert_name_from_camel_case_to_snake_case(key),
                 value)