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)
Exemplo n.º 2
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()
Exemplo n.º 3
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)
Exemplo n.º 4
0
 def create_http_connection(self):
     """
     create an HTTP connection with our name as the host
     """
     return HTTPConnection(
         compute_collection_hostname(self._collection_name),
         self._config.user_name,
         self._config.auth_key,
         self._config.auth_key_id
     )
Exemplo n.º 5
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"))
Exemplo n.º 7
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"))
Exemplo n.º 10
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
Exemplo n.º 12
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"))
Exemplo n.º 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))
def start_collection_request(identity, 
                             method, 
                             collection_name, 
                             path, 
                             response_consumer=None, 
                             body_producer=None,
                             additional_headers=None,
                             valid_http_status=frozenset([httplib.OK, ])):
    """
    start an HTTP(S) request for a specific collection
    return a deferred that fires with the response
    """
    hostname = compute_collection_hostname(collection_name)
    return start_request(identity, 
                         method, 
                         hostname, 
                         path, 
                         response_consumer, 
                         body_producer,
                         additional_headers,
                         valid_http_status)
Exemplo n.º 15
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))
Exemplo n.º 16
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()