Esempio n. 1
0
    def upload_file(self, file_name):
        did, app_id, response = pre_proc(self.response, access_vault=VAULT_ACCESS_WR)
        if response is not None:
            return response

        _, resp_err = v2_wrapper(self.ipfs_files.upload_file_with_path)(did, app_id, file_name)
        if resp_err:
            return resp_err

        return self.response.response_ok()
Esempio n. 2
0
    def delete(self):
        did, app_id, content, response = post_json_param_pre_proc(self.response, "path", access_vault=VAULT_ACCESS_DEL)
        if response is not None:
            return response

        _, resp_err = v2_wrapper(self.ipfs_files.delete_file_with_path)(did, app_id, content.get('path'))
        if resp_err:
            return resp_err

        return self.response.response_ok()
Esempio n. 3
0
    def get_property(self):
        did, app_id, content, response = get_pre_proc(self.response, "path", access_vault=VAULT_ACCESS_R)
        if response is not None:
            return response

        metadata, resp_err = v2_wrapper(self.ipfs_files.get_file_metadata)(did, app_id, content['path'])
        if resp_err:
            return resp_err
        data = HiveFile.get_info_by_metadata(metadata)

        return self.response.response_ok(data)
Esempio n. 4
0
    def file_hash(self):
        did, app_id, content, response = get_pre_proc(self.response, "path", access_vault=VAULT_ACCESS_R)
        if response is not None:
            return response

        metadata, resp_err = v2_wrapper(self.ipfs_files.get_file_metadata)(did, app_id, content['path'])
        if resp_err:
            return resp_err
        data = {"SHA256": metadata[COL_IPFS_FILES_SHA256]}

        return self.response.response_ok(data)
Esempio n. 5
0
    def move(self, is_copy):
        did, app_id, content, response = post_json_param_pre_proc(self.response, "src_path", "dst_path",
                                                                  access_vault=VAULT_ACCESS_WR)
        if response is not None:
            return response

        _, resp_err = v2_wrapper(self.ipfs_files.move_copy_file)(
            did, app_id, content.get('src_path'), content.get('dst_path'), is_copy=is_copy
        )
        if resp_err:
            return resp_err

        return self.response.response_ok()
Esempio n. 6
0
    def list_files(self):
        did, app_id = did_auth()
        if (did is None) or (app_id is None):
            return self.response.response_err(UNAUTHORIZED, "auth failed")

        r, msg = can_access_vault(did, VAULT_ACCESS_R)
        if r != SUCCESS:
            return self.response.response_err(r, msg)

        docs, resp_err = v2_wrapper(self.ipfs_files.list_folder_with_path)(did, app_id, request.args.get('path'))
        if resp_err:
            return resp_err
        file_info_list = list(map(lambda d: HiveFile.get_info_by_metadata(d), docs))

        return self.response.response_ok({"file_info_list": file_info_list})
Esempio n. 7
0
    def download_file(self):
        resp = Response()
        did, app_id = did_auth()
        if (did is None) or (app_id is None):
            resp.status_code = UNAUTHORIZED
            return resp
        r, msg = can_access_vault(did, VAULT_ACCESS_R)
        if r != SUCCESS:
            resp.status_code = r
            return resp

        data, resp_err = v2_wrapper(self.ipfs_files.download_file_with_path)(did, app_id, request.args.get('path'))
        if resp_err:
            return resp_err

        return data
    def run_script_download(self, transaction_id):
        row_id, target_did, target_app_did, file_name, err = self.run_script_fileapi_setup(
            transaction_id, "download")
        if err:
            logging.debug(err[1])
            return self.response.response_err(err[0], err[1])

        data, resp_err = v2_wrapper(self.ipfs_files.download_file_with_path)(
            target_did, target_app_did, file_name)
        if resp_err:
            return resp_err

        err_message = self.run_script_fileapi_teardown(row_id, target_did,
                                                       target_app_did,
                                                       "download")
        if err_message:
            logging.debug(err_message)
            return self.response.response_err(INTERNAL_SERVER_ERROR,
                                              err_message)

        return data
Esempio n. 9
0
def run_executable_file_hash(did, app_did, target_did, target_app_did,
                             executable_body, params):
    r, msg = can_access_vault(target_did, VAULT_ACCESS_R)
    if r != SUCCESS:
        return None, msg

    executable_body_path = executable_body.get("path", "")
    name = ""
    if executable_body_path.startswith(f"{SCRIPTING_EXECUTABLE_PARAMS}."):
        v = executable_body_path.replace(f"{SCRIPTING_EXECUTABLE_PARAMS}.", "")
        try:
            v = params[v]
        except Exception as e:
            return None, f"Exception: {str(e)}"
        name = v

    metadata, resp_err = v2_wrapper(IpfsFiles().get_file_metadata)(
        target_did, target_app_did, name)
    if resp_err:
        return None, f'Exception: Could not get the hash of the file. Status={resp_err[1]} Error={resp_err[0]}'
    data = {"SHA256": metadata[COL_IPFS_FILES_SHA256]}

    return data, None