Buckets:
AnonymousSpottedToad/human_verified_bucket / codebase /python /JeanExtreme002_Dokku-API /src /api /services /apps.py
| import asyncio | |
| import json | |
| import logging | |
| import re | |
| from abc import ABC | |
| from typing import Any, Dict, List, Optional, Tuple | |
| from fastapi import HTTPException | |
| from sqlalchemy.ext.asyncio import AsyncSession | |
| from src.api.models import ( | |
| App, | |
| AsyncSessionLocal, | |
| create_resource, | |
| delete_resource, | |
| get_app_deployment_token, | |
| get_resources, | |
| get_shared_app_users, | |
| rename_resource, | |
| share_app, | |
| unshare_app, | |
| ) | |
| from src.api.schemas import UserSchema | |
| from src.api.services.databases import DatabaseService | |
| from src.api.tools.resource import ResourceName, check_shared_app | |
| from src.api.tools.ssh import run_command | |
| from src.config import Config | |
| def parse_apps_list(text: str): | |
| """ | |
| Extract the list of apps from a formatted string. | |
| """ | |
| lines = text.strip().split("\n") | |
| apps = [ | |
| line.strip() for line in lines if line.strip() and not line.startswith("=====>") | |
| ] | |
| return apps | |
| def parse_ps_report(text: str) -> Dict: | |
| lines = text.strip().splitlines() | |
| result = {} | |
| for line in lines: | |
| if line.startswith("=====>"): | |
| continue | |
| match = re.match(r"^\s*(.+?)\s{2,}(.+)$", line) | |
| key = ( | |
| match.group(1).strip().strip(":").lower().replace(" ", "_") | |
| if match | |
| else line.strip() | |
| ) | |
| value = match.group(2).strip() if match else "" | |
| result[key] = value | |
| return result | |
| def parse_network_info(session_user: UserSchema, text: str) -> Dict: | |
| result = {} | |
| lines = text.strip().split("\n") | |
| for line in lines: | |
| if "=====>" in line: | |
| continue | |
| if ":" in line: | |
| key, value = line.split(":", 1) | |
| key = key.strip().lower().replace(" ", "_") | |
| result[key] = value.strip() | |
| network = result.get("network_attach_post_create") | |
| if not network: | |
| network = result.get("network_attach_post_deploy") | |
| if not network: | |
| network = result.get("network_computed_attach_post_create") | |
| if not network: | |
| network = result.get("network_computed_attach_post_deploy") | |
| if not network: | |
| network = result.get("network_computed_initial_network") | |
| if network: | |
| network = ResourceName(session_user, network, from_system=True) | |
| return {"network": str(network) if network else None} | |
| def parse_port_mappings(text: str) -> List: | |
| lines = text.strip().splitlines() | |
| ports = [] | |
| for line in lines: | |
| parts = line.strip().split() | |
| if len(parts) == 3: | |
| scheme, host_port, container_port = parts | |
| ports.append( | |
| { | |
| "protocol": scheme, | |
| "origin": int(host_port), | |
| "dest": int(container_port), | |
| } | |
| ) | |
| return ports | |
| def get_user_id_from_app(name) -> Optional[int]: | |
| id = name.split("-", maxsplit=1)[0] | |
| try: | |
| return int(id) | |
| except ValueError: | |
| return None | |
| def get_raw_app(name): | |
| if Config.API_USE_PER_USER_RESOURCE_NAMES: | |
| return name.split("-", maxsplit=1)[-1] | |
| return name | |
| def parse_xxd_to_bytes(text: str) -> bytes: | |
| """ | |
| Convert standard `xxd` output into raw bytes. | |
| Handles default xxd format lines like: | |
| "00000000: 25504446 2d312e33 0a25e2e3 cf... ........" | |
| by extracting hex columns before the double-space ASCII separator. | |
| Falls back to extracting all 2-hex-digit tokens if needed. | |
| """ | |
| lines = text.strip().splitlines() | |
| hex_chunks = [] | |
| for line in lines: | |
| line = line.rstrip() | |
| if not line: | |
| continue | |
| if ":" not in line: | |
| # skip non-data lines | |
| continue | |
| try: | |
| after = line.split(":", 1)[1] | |
| # hex column is before two spaces that precede ASCII area | |
| hex_part = after.split(" ", 1)[0] | |
| hex_str = hex_part.replace(" ", "") | |
| if hex_str: | |
| hex_chunks.append(hex_str) | |
| except Exception: | |
| continue | |
| if hex_chunks: | |
| hex_data = "".join(hex_chunks) | |
| try: | |
| return bytes.fromhex(hex_data) | |
| except ValueError: | |
| pass | |
| # Fallback: collect all byte-sized hex tokens | |
| tokens = re.findall(r"\b[0-9a-fA-F]{2}\b", text) | |
| return bytes(int(t, 16) for t in tokens) | |
| class AppService(ABC): | |
| staticmethod | |
| async def app_exists(session_user: UserSchema, app_name: str) -> Tuple[bool, Any]: | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| return False, f"App {app_name} does not exist on the API" | |
| return await run_command(f"apps:exists {app_name}") | |
| async def create_app( | |
| session_user: UserSchema, | |
| app_name: str, | |
| db_session: AsyncSession, | |
| clone_from: Optional[str] = None, | |
| ) -> Tuple[bool, Any]: | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| clone_from = ( | |
| ResourceName(session_user, clone_from).for_system() if clone_from else None | |
| ) | |
| if clone_from: | |
| _, message = await run_command(f"apps:exists {clone_from}") | |
| if ( | |
| clone_from not in session_user.apps | |
| or "does not exist" in message.lower() | |
| ): | |
| raise HTTPException( | |
| status_code=404, detail=f"App '{clone_from}' does not exist" | |
| ) | |
| _, message = await run_command(f"apps:exists {app_name}") | |
| if "does not exist" not in message.lower(): | |
| raise HTTPException(status_code=403, detail="App already exists") | |
| await create_resource(session_user.email, app_name, App, db_session) | |
| if clone_from: | |
| success, message = await run_command(f"apps:clone {clone_from} {app_name}") | |
| else: | |
| success, message = await run_command(f"apps:create {app_name}") | |
| return success, message | |
| async def get_shared_app_users( | |
| session_user: UserSchema, app_name: str, db_session: AsyncSession | |
| ) -> Tuple[bool, Any]: | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| results = await get_shared_app_users(app_name, db_session) | |
| return True, results | |
| async def list_apps_shared_with( | |
| session_user: UserSchema, db_session: AsyncSession | |
| ) -> Tuple[bool, Any]: | |
| app_names = list(session_user.apps) | |
| results = await asyncio.gather( | |
| *[get_shared_app_users(app_name, db_session) for app_name in app_names] | |
| ) | |
| return True, { | |
| app_name: users for app_name, users in zip(app_names, results) if users | |
| } | |
| async def unshare_app( | |
| session_user: UserSchema, app_name: str, email: str, db_session: AsyncSession | |
| ) -> Tuple[bool, Any]: | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| await unshare_app(app_name, email, db_session) | |
| return True, None | |
| async def share_app( | |
| session_user: UserSchema, | |
| app_name: str, | |
| target_email: str, | |
| db_session: AsyncSession, | |
| ) -> Tuple[bool, Any]: | |
| if session_user.email == target_email: | |
| raise HTTPException( | |
| status_code=400, detail="You cannot share the application with yourself" | |
| ) | |
| system_app_name = ResourceName(session_user, app_name).for_system() | |
| if system_app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| await share_app( | |
| session_user, system_app_name, app_name, target_email, db_session | |
| ) | |
| return True, None | |
| async def rename_app( | |
| session_user: UserSchema, | |
| app_name: str, | |
| new_app_name: str, | |
| db_session: AsyncSession, | |
| ) -> Tuple[bool, Any]: | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| new_app_name = ResourceName(session_user, new_app_name).for_system() | |
| _, message = await run_command(f"apps:exists {new_app_name}") | |
| if "does not exist" not in message.lower(): | |
| raise HTTPException(status_code=403, detail="App already exists") | |
| async def run_rename_in_background(): | |
| try: | |
| await run_command(f"apps:rename {app_name} {new_app_name}") | |
| raw_new_app_name = get_raw_app(new_app_name) | |
| async with AsyncSessionLocal() as task_session: | |
| await rename_resource( | |
| session_user.email, | |
| app_name, | |
| new_app_name, | |
| raw_new_app_name, | |
| App, | |
| task_session, | |
| ) | |
| except Exception: | |
| logging.exception("apps:rename background task failed") | |
| asyncio.create_task(run_rename_in_background()) | |
| return True, None | |
| async def get_deployment_token( | |
| session_user: UserSchema, | |
| app_name: str, | |
| db_session: AsyncSession, | |
| ) -> Tuple[bool, Any]: | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| deploy_token = await get_app_deployment_token(app_name, db_session) | |
| return True, deploy_token | |
| async def delete_app( | |
| session_user: UserSchema, | |
| app_name: str, | |
| db_session: AsyncSession, | |
| ) -> Tuple[bool, Any]: | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| await delete_resource(session_user.email, app_name, App, db_session) | |
| return await run_command(f"--force apps:destroy {app_name}") | |
| async def set_owner( | |
| session_user: UserSchema, app_name: str, db_session: AsyncSession | |
| ) -> Tuple[bool, Any]: | |
| _, message = await run_command(f"apps:exists {app_name}") | |
| if "does not exist" in message.lower(): | |
| raise HTTPException(status_code=404, detail="App does not exist on Dokku") | |
| system_app_name = ResourceName(session_user, app_name).for_system() | |
| if system_app_name not in session_user.apps: | |
| await create_resource(session_user.email, system_app_name, App, db_session) | |
| await run_command(f"apps:rename {app_name} {system_app_name}") | |
| return True, None | |
| async def unset_owner( | |
| session_user: UserSchema, app_name: str, db_session: AsyncSession | |
| ) -> Tuple[bool, Any]: | |
| system_app_name = ResourceName(session_user, app_name).for_system() | |
| if system_app_name in session_user.apps: | |
| await delete_resource(session_user.email, system_app_name, App, db_session) | |
| await run_command(f"apps:rename {system_app_name} {app_name}") | |
| return True, None | |
| async def execute_command( | |
| session_user: UserSchema, | |
| app_name: str, | |
| container_type: str, | |
| command: str, | |
| shared_by: Optional[str] = None, | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| return await run_command(f"enter {app_name} {container_type} {command}") | |
| async def get_app_url( | |
| session_user: UserSchema, app_name: str, shared_by: Optional[str] = None | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| return await run_command(f"url {app_name}") | |
| async def get_app_info( | |
| session_user: UserSchema, app_name: str, shared_by: Optional[str] = None | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| success, message = await run_command(f"ps:inspect {app_name}") | |
| result = {} | |
| if success: | |
| result["data"] = json.loads(message) | |
| result["info_origin"] = "inspect" | |
| else: | |
| success, message = await run_command(f"ps:report {app_name}") | |
| result["data"] = parse_ps_report(message) if success else None | |
| result["info_origin"] = "report" if success else None | |
| result["raw_name"] = app_name | |
| return success, result | |
| async def list_apps( | |
| session_user: UserSchema, return_info: bool = True | |
| ) -> Tuple[bool, Any]: | |
| result = {} | |
| tasks = [] | |
| app_names = [] | |
| if not return_info: | |
| for app_name in session_user.apps: | |
| app_name = str(ResourceName(session_user, app_name, from_system=True)) | |
| result[app_name] = {} | |
| return True, result | |
| for app_name in session_user.apps: | |
| app_name = str(ResourceName(session_user, app_name, from_system=True)) | |
| app_names.append(app_name) | |
| tasks.append(AppService.get_app_info(session_user, app_name)) | |
| app_infos = await asyncio.gather(*tasks, return_exceptions=True) | |
| for name, info in zip(app_names, app_infos): | |
| result[name] = {} if isinstance(info, Exception) else info[1] | |
| return True, result | |
| async def list_shared_apps( | |
| session_user: UserSchema, return_info: bool = True | |
| ) -> Tuple[bool, Any]: | |
| result = {} | |
| tasks = [] | |
| app_names = [] | |
| if not return_info: | |
| for author_email, app_name in session_user.shared_apps: | |
| result[f"{author_email}:{app_name}"] = {} | |
| return True, result | |
| for author_email, app_name in session_user.shared_apps: | |
| app_names.append(f"{author_email}:{app_name}") | |
| tasks.append( | |
| AppService.get_app_info(session_user, app_name, shared_by=author_email) | |
| ) | |
| app_infos = await asyncio.gather(*tasks, return_exceptions=True) | |
| for name, info in zip(app_names, app_infos): | |
| result[name] = {} if isinstance(info, Exception) else info[1] | |
| return True, result | |
| async def get_logs( | |
| session_user: UserSchema, | |
| app_name: str, | |
| n_lines: int = 2000, | |
| shared_by: Optional[str] = None, | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| return await run_command(f"logs {app_name} --num {n_lines}") | |
| async def start_app( | |
| session_user: UserSchema, app_name: str, shared_by: Optional[str] = None | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| return await run_command(f"ps:start {app_name}") | |
| async def stop_app( | |
| session_user: UserSchema, app_name: str, shared_by: Optional[str] = None | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| return await run_command(f"ps:stop {app_name}") | |
| async def restart_app( | |
| session_user: UserSchema, app_name: str, shared_by: Optional[str] = None | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| return await run_command(f"ps:restart {app_name}") | |
| async def rebuild_app( | |
| session_user: UserSchema, app_name: str, shared_by: Optional[str] = None | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| return await run_command(f"ps:rebuild {app_name}") | |
| async def get_builder( | |
| session_user: UserSchema, app_name: str, shared_by: Optional[str] = None | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| success, message = await run_command(f"builder:report {app_name}") | |
| if not success: | |
| return False, message | |
| result = {} | |
| lines = message.strip().split("\n") | |
| for line in lines: | |
| if ":" in line: | |
| key, value = line.split(":", maxsplit=1) | |
| key = key.strip().lower().replace(" ", "_") | |
| result[key] = value.strip() | |
| return True, result | |
| async def set_builder( | |
| session_user: UserSchema, | |
| app_name: str, | |
| builder: str, | |
| shared_by: Optional[str] = None, | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| available_builders = ["herokuish", "dockerfile", "lambda", "pack"] | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| if builder not in available_builders: | |
| message = ( | |
| f"Invalid builder. Available builders: {', '.join(available_builders)}" | |
| ) | |
| raise HTTPException( | |
| status_code=400, | |
| detail=message, | |
| ) | |
| return await run_command(f"builder:set {app_name} selected {builder}") | |
| async def get_network( | |
| session_user: UserSchema, app_name: str, shared_by: Optional[str] = None | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| success, message = await run_command(f"network:report {app_name}") | |
| if not success: | |
| return False, message | |
| return True, parse_network_info(session_user, message) | |
| async def list_port_mappings( | |
| session_user: UserSchema, | |
| app_name: str, | |
| use_proxy: bool = False, | |
| shared_by: Optional[str] = None, | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| if use_proxy: | |
| success, message = await run_command(f"proxy:ports {app_name}") | |
| else: | |
| success, message = await run_command(f"ports:list {app_name}") | |
| if "no port mappings" in message.lower(): | |
| return True, [] | |
| if not success: | |
| return False, message | |
| return True, parse_port_mappings(message) | |
| async def add_port_mapping( | |
| session_user: UserSchema, | |
| app_name: str, | |
| origin_port: int, | |
| dest_port: int, | |
| protocol: str, | |
| use_proxy: bool = False, | |
| shared_by: Optional[str] = None, | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| if use_proxy: | |
| return await run_command( | |
| f"proxy:ports-add {app_name} {protocol}:{origin_port}:{dest_port}" | |
| ) | |
| else: | |
| return await run_command( | |
| f"ports:add {app_name} {protocol}:{origin_port}:{dest_port}" | |
| ) | |
| async def remove_port_mapping( | |
| session_user: UserSchema, | |
| app_name: str, | |
| origin_port: int, | |
| dest_port: int, | |
| protocol: str, | |
| use_proxy: bool = False, | |
| shared_by: Optional[str] = None, | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| if use_proxy: | |
| return await run_command( | |
| f"proxy:ports-remove {app_name} {protocol}:{origin_port}:{dest_port}" | |
| ) | |
| else: | |
| return await run_command( | |
| f"ports:remove {app_name} {protocol}:{origin_port}:{dest_port}" | |
| ) | |
| async def get_linked_databases( | |
| session_user: UserSchema, | |
| app_name: str, | |
| shared_by: Optional[str] = None, | |
| ) -> Tuple[bool, Any]: | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| sys_app_name = ResourceName(session_user, app_name).for_system() | |
| if sys_app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| result = {} | |
| for db_name in session_user.services: | |
| plugin_name, db_name = db_name.split(":", maxsplit=1) | |
| db_name = str(ResourceName(session_user, db_name, from_system=True)) | |
| success, data = await DatabaseService.get_linked_apps( | |
| session_user, plugin_name, db_name | |
| ) | |
| if success and app_name in data: | |
| result[plugin_name] = result.get(plugin_name, []) + [ | |
| db_name, | |
| ] | |
| return True, result | |
| async def list_storage( | |
| session_user: UserSchema, | |
| app_name: str, | |
| ) -> Tuple[bool, Any]: | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| success, result = await run_command(f"storage:list {app_name}") | |
| return success, (result.split("\n") if result else []) | |
| async def mount_storage( | |
| session_user: UserSchema, | |
| app_name: str, | |
| directory: str, | |
| ) -> Tuple[bool, Any]: | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| app_dir = f"{Config.VOLUME_DIR}/{app_name}" | |
| return await run_command(f"storage:mount {app_name} {app_dir}:{directory}") | |
| async def unmount_storage( | |
| session_user: UserSchema, | |
| app_name: str, | |
| directory: str, | |
| ) -> Tuple[bool, Any]: | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| app_dir = f"{Config.VOLUME_DIR}/{app_name}" | |
| return await run_command(f"storage:unmount {app_name} {app_dir}:{directory}") | |
| async def download_file( | |
| session_user: UserSchema, | |
| app_name: str, | |
| filename: str, | |
| shared_by: Optional[str] = None, | |
| ) -> Tuple[bool, Any]: | |
| """ | |
| Run `xxd {filename}` inside the app's web container and reconstruct bytes. | |
| Returns (success, bytes) on success, else (False, error_message). | |
| """ | |
| session_user = await check_shared_app(session_user, app_name, shared_by) | |
| app_name = ResourceName(session_user, app_name).for_system() | |
| if app_name not in session_user.apps: | |
| raise HTTPException(status_code=404, detail="App does not exist") | |
| success, output = await run_command(f"enter {app_name} web xxd {filename}") | |
| if not success: | |
| return False, output | |
| try: | |
| data = parse_xxd_to_bytes(output) | |
| return True, data | |
| except Exception as error: | |
| return False, f"Failed to parse xxd output: {error}" | |
| async def sync_dokku_with_api_database(db_session: AsyncSession) -> None: | |
| if not Config.API_USE_PER_USER_RESOURCE_NAMES: | |
| logging.warning( | |
| "[sync_dokku_w_network_database]::Not implemented on API_USE_PER_USER_RESOURCE_NAMES=false..." | |
| ) | |
| return | |
| success, message = await run_command("apps:list", use_log=False) | |
| if not success: | |
| logging.warning("Could not recover apps list to sync with database") | |
| return | |
| logging.warning("[sync_dokku_w_app_database]::Syncing Dokku...") | |
| apps = parse_apps_list(message) | |
| apps = {name: True for name in apps if get_user_id_from_app(name) is not None} | |
| db_apps = await get_resources(App, offset=0, limit=None, db_session=db_session) | |
| for app in db_apps: | |
| apps.pop(app["name"], None) | |
| for app_name in apps: | |
| logging.warning( | |
| f"[sync_dokku_w_app_database]:{app_name}::Destroying unused application..." | |
| ) | |
| await run_command(f"--force apps:destroy {app_name}", use_log=False) | |
| logging.warning("[sync_dokku_w_app_database]::Sync complete.") | |
Xet Storage Details
- Size:
- 27.3 kB
- Xet hash:
- 3c3c2392d6e769c92dd5584feb32cebcb36b21766446ed2d52bbe48c687d93c2
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.