def _receive_dir(access, local_dir_path, listing):
    with open(access) as f:
        access = json.load(f)

    if listing is None:
        raise ListingError('red-connector-http receive-dir requires listing.')

    with open(listing) as f:
        listing = json.load(f)

    listing = deepcopy(listing)

    build_path(access['url'], listing, 'complete_url')
    build_path(local_dir_path, listing, 'complete_path')

    http_method = http_method_func(access, 'GET')
    auth_method = auth_method_obj(access)

    verify = True
    if access.get('disableSSLVerification'):
        verify = False

    if not os.path.exists(local_dir_path):
        os.mkdir(local_dir_path)

    fetch_directory(listing, http_method, auth_method, verify)
Esempio n. 2
0
def _receive_file(access, local_file_path):
    with open(access) as f:
        access = json.load(f)

    http_method = http_method_func(access, 'GET')
    auth_method = auth_method_obj(access)

    verify = True
    if access.get('disableSSLVerification'):
        verify = False

    r = http_method(access['url'],
                    auth=auth_method,
                    verify=verify,
                    timeout=DEFAULT_TIMEOUT)
    r.raise_for_status()
    try:
        data = r.json()
    except JSONDecodeError as e:
        raise JSONDecodeError(
            'Could not parse the http response as json object. Failed with the following message:\n'
            .format(str(e)), e.doc, e.pos)

    with open(local_file_path, 'w') as f:
        json.dump(data, f)
Esempio n. 3
0
def _receive_file(access, local_file_path):
    with open(access) as f:
        access = json.load(f)

    http_method = http_method_func(access, 'GET')
    auth_method = auth_method_obj(access)

    verify = True
    if access.get('disableSSLVerification'):
        verify = False

    fetch_file(local_file_path, access['url'], http_method, auth_method,
               verify)
Esempio n. 4
0
def _send_file(access, local_file_path):
    with open(access) as f:
        access = json.load(f)

    http_method = http_method_func(access, 'POST')
    auth_method = auth_method_obj(access)

    verify = True
    if access.get('disableSSLVerification'):
        verify = False

    with open(local_file_path, 'rb') as f:
        r = http_method(access['url'],
                        data=f,
                        auth=auth_method,
                        verify=verify,
                        timeout=DEFAULT_TIMEOUT)
        r.raise_for_status()
def _receive_dir(access, local_dir_path, listing):
    with open(access) as f:
        access = json.load(f)

    http_method = http_method_func(access, 'GET')
    auth_method = auth_method_obj(access)

    verify = True
    if access.get('disableSSLVerification'):
        verify = False

    tmp_dir_path = tempfile.mkdtemp()
    tmp_file_path = os.path.join(tmp_dir_path, 'archive')

    fetch_file(tmp_file_path, access['url'], http_method, auth_method, verify)

    shutil.unpack_archive(tmp_file_path, local_dir_path, access['archiveFormat'])
    shutil.rmtree(tmp_dir_path)