def execute(self): cli.check_vault_access(self.script.user_did, VAULT_ACCESS_R) body = self.get_populated_body() logging.info( f'get file properties: is_ipfs={self.is_ipfs}, path={body["path"]}' ) if self.is_ipfs: doc = self.ipfs_files.get_file_metadata(self.get_target_did(), self.get_target_app_did(), body['path']) return self.get_output_data({ "type": "file" if doc[COL_IPFS_FILES_IS_FILE] else "folder", "name": body['path'], "size": doc[SIZE], "last_modify": doc['modified'] }) full_path, stat = self.script.scripting\ .get_files().get_file_stat_by_did(self.get_target_did(), self.get_target_app_did(), body['path']) return self.get_output_data({ "type": "file" if full_path.is_file() else "folder", "name": body['path'], "size": stat.st_size, "last_modify": stat.st_mtime })
def _create_transaction(self, permission, action_type): cli.check_vault_access(self.get_target_did(), permission) body = self.get_populated_body() anonymous_url = '' if self.is_ipfs: if action_type == 'download': metadata = self.ipfs_files.get_file_metadata( self.get_target_did(), self.get_target_app_did(), body['path']) anonymous_url = self.ipfs_files.get_ipfs_file_access_url( metadata) else: _, err = query_upload_get_filepath(self.get_target_did(), self.get_target_app_did(), body['path']) if err: raise BadRequestException( msg='Cannot get file full path with error message: ' + str(err)) # INFO: Do not consider run script twice. data = cli.insert_one( self.get_target_did(), self.get_target_app_did(), SCRIPTING_SCRIPT_TEMP_TX_COLLECTION, { "document": { "file_name": body['path'], "fileapi_type": action_type }, 'anonymous': self.script.anonymous_app and self.script.anonymous_user }, create_on_absence=True) if not data.get('inserted_id', None): raise BadRequestException('Cannot retrieve the transaction ID.') update_used_storage_for_mongodb_data( self.get_target_did(), get_mongo_database_size(self.get_target_did(), self.get_target_app_did())) result = { "transaction_id": jwt.encode( { "row_id": data.get('inserted_id', None), "target_did": self.get_target_did(), "target_app_did": self.get_target_app_did() }, hive_setting.DID_STOREPASS, algorithm='HS256') } if action_type == 'download' and self.is_ipfs and self.script.anonymous_app and self.script.anonymous_user: result['anonymous_url'] = anonymous_url return result
def execute(self): cli.check_vault_access(self.get_target_did(), VAULT_ACCESS_R) options = populate_options_find_many( self.body) if 'options' in self.body else {} return self.get_output_data({ "items": cli.find_many(self.get_target_did(), self.get_target_app_did(), self.get_collection_name(), self.get_populated_filter(), options) })
def execute(self): cli.check_vault_access(self.get_target_did(), VAULT_ACCESS_DEL) data = cli.delete_one(self.get_target_did(), self.get_target_app_did(), self.get_collection_name(), self.get_populated_filter()) update_used_storage_for_mongodb_data( self.get_did(), get_mongo_database_size(self.get_target_did(), self.get_target_app_did())) return self.get_output_data(data)
def execute(self): cli.check_vault_access(self.script.user_did, VAULT_ACCESS_R) body = self.get_populated_body() logging.info( f'get file hash: is_ipfs={self.is_ipfs}, path={body["path"]}') if self.is_ipfs: doc = self.ipfs_files.get_file_metadata(self.get_target_did(), self.get_target_app_did(), body['path']) return self.get_output_data({"SHA256": doc[COL_IPFS_FILES_SHA256]}) data, err = query_hash(self.get_target_did(), self.get_target_app_did(), body['path']) if err: raise BadRequestException( 'Failed to get file hash code with error message: ' + str(err)) return self.get_output_data(data)
def execute(self): cli.check_vault_access(self.get_target_did(), VAULT_ACCESS_WR) document = self.get_document() msg = populate_with_params_values(self.get_did(), self.get_app_id(), document, self.get_params()) if msg: raise BadRequestException( msg='Cannot get parameter value for the executable document: ' + msg) data = cli.insert_one(self.get_target_did(), self.get_target_app_did(), self.get_collection_name(), document, populate_options_insert_one(self.body)) update_used_storage_for_mongodb_data( self.get_did(), get_mongo_database_size(self.get_target_did(), self.get_target_app_did())) return self.get_output_data(data)
def check_auth_and_vault(permission=None): user_did, app_did = check_auth() cli.check_vault_access(user_did, permission) return user_did, app_did