Source code for q2_sdk.extensions.Admin.extension

"""
Admin Extension provides an interface to do server level operations
"""

import os
from q2_sdk.core.http_handlers.base_handler import Q2BaseRequestHandler
from q2_sdk.core.request_handler.templating import LocalAssetLoader
from q2_sdk.core.configuration import settings


[docs] class AdminHandler(Q2BaseRequestHandler):
[docs] async def get(self): """UI interface for interacting with this endpoint""" recent_keys = self.vault.RECENT_KEYS sftp_dirs = [] mount_dir = settings.SFTP_DIRECTORY if mount_dir and os.path.exists(mount_dir): max_depth = 1 depth = 1 for path, directories, _ in mount_dir.walk(): if depth <= max_depth: prefix = ( f"{path.relative_to(mount_dir)}/" if path != mount_dir else "" ) sftp_dirs.extend([f"{prefix}{d}" for d in directories]) depth += 1 html = self.get_template( "index.html.jinja2", { "recent_keys": recent_keys, "sftp_dir": {"mount_dir": mount_dir, "children": sorted(sftp_dirs)}, }, ) html = LocalAssetLoader(self.templater, html).expand_local_sources() self.write(html)