예제 #1
0
def _retrieve_key(args, identity, ncl_dict):
    method = "GET"

    hostname = compute_collection_hostname(ncl_dict["collection_name"])
    if identity is None:
        http_connection = UnAuthHTTPConnection(hostname)
    else:
        http_connection = HTTPConnection(hostname,
                                         identity.user_name,
                                         identity.auth_key,
                                         identity.auth_key_id)

    kwargs = {
    }

    uri = compute_uri("data", ncl_dict["key"], **kwargs)

    response = http_connection.request(method, 
                                       uri, 
                                       body=None)

    while True:
        data = response.read(_read_buffer_size)
        if len(data) == 0:
            break
        sys.stdout.buffer.write(data)

    http_connection.close()
예제 #2
0
def _retrieve_key_to_string(collection_name, key_name):
    http_connection = \
        UnAuthHTTPConnection(compute_collection_hostname(collection_name))

    kwargs = {
        "version_identifier": None,
    }
    headers = {}
    expected_status = OK

    method = "GET"
    uri = compute_uri("data", key_name, **kwargs)

    response = http_connection.request(method,
                                       uri,
                                       body=None,
                                       headers=headers,
                                       expected_status=expected_status)

    body_list = list()
    while True:
        data = response.read(_read_buffer_size)
        if len(data) == 0:
            break
        body_list.append(data)

    http_connection.close()

    return b"".join(body_list)
def _retrieve_key_to_string(collection_name, key_name):
    http_connection = \
        UnAuthHTTPConnection(compute_collection_hostname(collection_name))

    kwargs = {"version_identifier"    : None, }
    headers = {}
    expected_status = OK

    method = "GET"
    uri = compute_uri("data", key_name, **kwargs)

    response = http_connection.request(method, 
                                       uri, 
                                       body=None, 
                                       headers=headers,
                                       expected_status=expected_status)
        
    body_list = list()
    while True:
        data = response.read(_read_buffer_size)
        if len(data) == 0:
            break
        body_list.append(data)

    http_connection.close()

    return b"".join(body_list)
예제 #4
0
def _delete_key(collection_name, key_name):
    http_connection = \
        UnAuthHTTPConnection(compute_collection_hostname(collection_name))

    kwargs = dict()

    method = "DELETE"
    uri = compute_uri("data", key_name, **kwargs)

    response = http_connection.request(method, uri, body=None)

    data = response.read()
    http_connection.close()
    return json.loads(data.decode("utf-8"))
def _delete_key(collection_name, key_name):
    http_connection = \
        UnAuthHTTPConnection(compute_collection_hostname(collection_name))

    kwargs = dict()

    method = "DELETE"
    uri = compute_uri("data", key_name, **kwargs)

    response = http_connection.request(method, uri, body=None)
    
    data = response.read()
    http_connection.close()
    return json.loads(data.decode("utf-8"))
예제 #6
0
def _archive_key_from_string(collection_name, key_name, data):
    http_connection = \
        UnAuthHTTPConnection(compute_collection_hostname(collection_name))

    kwargs = {"conjoined_identifier": None}

    method = "POST"
    uri = compute_uri("data", key_name, **kwargs)

    response = http_connection.request(method, uri, body=data)

    response_str = response.read()
    http_connection.close()

    return json.loads(response_str.decode("utf-8"))
def _archive_key_from_string(collection_name, key_name, data):
    http_connection = \
        UnAuthHTTPConnection(compute_collection_hostname(collection_name))

    kwargs = {"conjoined_identifier"  : None}

    method = "POST"
    uri = compute_uri("data", key_name, **kwargs)

    response = http_connection.request(method, uri, body=data)
    
    response_str = response.read()
    http_connection.close()

    return json.loads(response_str.decode("utf-8"))
def _list_keys(collection_name):
    http_connection = \
        UnAuthHTTPConnection(compute_collection_hostname(collection_name))

    method = "GET"

    kwargs = {"max_keys" : 1000, }

    uri = compute_uri("data/", **kwargs)

    response = http_connection.request(method, uri)
    
    data = response.read()
    http_connection.close()
    return json.loads(data.decode("utf-8"))
예제 #9
0
def _head_key(collection_name, key_name):
    http_connection = \
        UnAuthHTTPConnection(compute_collection_hostname(collection_name))

    kwargs = dict()

    method = "HEAD"
    uri = compute_uri("data", key_name, **kwargs)

    response = http_connection.request(method, uri, body=None)

    _ = response.read()
    headers = response.getheaders()
    http_connection.close()

    return headers
def _head_key(collection_name, key_name):
    http_connection = \
        UnAuthHTTPConnection(compute_collection_hostname(collection_name))

    kwargs = dict()

    method = "HEAD"
    uri = compute_uri("data", key_name, **kwargs)

    response = http_connection.request(method, uri, body=None)
    
    _ = response.read()
    headers = response.getheaders()
    http_connection.close()

    return headers
예제 #11
0
def _list_keys(collection_name):
    http_connection = \
        UnAuthHTTPConnection(compute_collection_hostname(collection_name))

    method = "GET"

    kwargs = {
        "max_keys": 1000,
    }

    uri = compute_uri("data/", **kwargs)

    response = http_connection.request(method, uri)

    data = response.read()
    http_connection.close()
    return json.loads(data.decode("utf-8"))
예제 #12
0
def _list_keys(args, identity, ncl_dict):
    method = "GET"

    hostname = compute_collection_hostname(ncl_dict["collection_name"])
    if identity is None:
        http_connection = UnAuthHTTPConnection(hostname)
    else:
        http_connection = HTTPConnection(hostname,
                                         identity.user_name,
                                         identity.auth_key,
                                         identity.auth_key_id)

    kwargs = {
        "max_keys" : _max_keys,
    }
    if "prefix" in ncl_dict and ncl_dict["prefix"] != "" and \
        ncl_dict["prefix"] is not None: 
        kwargs["prefix"] = ncl_dict["prefix"]
    if "marker" in ncl_dict and ncl_dict["marker"] != "" and \
        ncl_dict["marker"] is not None: 
        kwargs["marker"] = ncl_dict["marker"]
    if "delimiter" in ncl_dict and ncl_dict["delimiter"] != "" and \
        ncl_dict["delimiter"] is not None: 
        kwargs["delimiter"] = ncl_dict["delimiter"]

    uri = compute_uri("data/", **kwargs)

    response = http_connection.request(method, uri)
    
    data = response.read()
    http_connection.close()
    data_dict = json.loads(data.decode("utf-8"))

    if "key_data" in data_dict:
        for key_entry in data_dict["key_data"]:
            print(key_entry["key"])
    elif "prefixes" in data_dict:
        for prefix in data_dict["prefixes"]:
            print(prefix)
    else:
        raise ValueError("Unexpected return value {0}".format(data_dict))
예제 #13
0
def _list_keys(args, identity, ncl_dict):
    method = "GET"

    hostname = compute_collection_hostname(ncl_dict["collection_name"])
    if identity is None:
        http_connection = UnAuthHTTPConnection(hostname)
    else:
        http_connection = HTTPConnection(hostname, identity.user_name,
                                         identity.auth_key,
                                         identity.auth_key_id)

    kwargs = {
        "max_keys": _max_keys,
    }
    if "prefix" in ncl_dict and ncl_dict["prefix"] != "" and \
        ncl_dict["prefix"] is not None:
        kwargs["prefix"] = ncl_dict["prefix"]
    if "marker" in ncl_dict and ncl_dict["marker"] != "" and \
        ncl_dict["marker"] is not None:
        kwargs["marker"] = ncl_dict["marker"]
    if "delimiter" in ncl_dict and ncl_dict["delimiter"] != "" and \
        ncl_dict["delimiter"] is not None:
        kwargs["delimiter"] = ncl_dict["delimiter"]

    uri = compute_uri("data/", **kwargs)

    response = http_connection.request(method, uri)

    data = response.read()
    http_connection.close()
    data_dict = json.loads(data.decode("utf-8"))

    if "key_data" in data_dict:
        for key_entry in data_dict["key_data"]:
            print(key_entry["key"])
    elif "prefixes" in data_dict:
        for prefix in data_dict["prefixes"]:
            print(prefix)
    else:
        raise ValueError("Unexpected return value {0}".format(data_dict))
예제 #14
0
def _retrieve_key(args, identity, ncl_dict):
    method = "GET"

    hostname = compute_collection_hostname(ncl_dict["collection_name"])
    if identity is None:
        http_connection = UnAuthHTTPConnection(hostname)
    else:
        http_connection = HTTPConnection(hostname, identity.user_name,
                                         identity.auth_key,
                                         identity.auth_key_id)

    kwargs = {}

    uri = compute_uri("data", ncl_dict["key"], **kwargs)

    response = http_connection.request(method, uri, body=None)

    while True:
        data = response.read(_read_buffer_size)
        if len(data) == 0:
            break
        sys.stdout.buffer.write(data)

    http_connection.close()