Files
AirlockTools/AirlockTools_Client.py
T

84 lines
2.6 KiB
Python

# Copyright (C) 2025 James Brotosky, Brandon Wickline
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#TODO Continue implementing logger
#TODO Add input sanitation and CSV injection prevention
#TODO Continue OTP and Local approval rewrites
#TODO Explore pywin32
#TODO Fix Requirements.txt
#TODO Create Generic system_config.json for gitea
import os
import sys
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', ".."))
sys.path.append(project_root)
import asyncio
import logging
import dotenv
import urllib3
import utils.menus as menus
from services.API import AirlockAPIWrapper
from services.security import getAPI
from services.TaskQueue import AsyncTaskQueue
from utils.setup import setup
urllib3.disable_warnings(
urllib3.exceptions.InsecureRequestWarning
)
async def main():
#Determine working directory, setup directory, configure logging, sent env, get API and URL if not already stored
working_dir = await setup()
logger = logging.getLogger(__name__)
logger.debug("🔍 Logging test: this should appear in both console and file.")
dotenv.load_dotenv(dotenv_path=working_dir / ".env")
queue = AsyncTaskQueue(worker_count = 3)
await queue.start_workers()
try:
url = os.getenv("URL")
username = os.getenv("USERNAME")
if not url:
raise ValueError("Missing URL in environment variables.")
if not username:
raise ValueError("Missing USERNAME in environment variables.")
logger.debug(f"Retrieved URL: {url}")
logger.debug(f"Retrieved Username: {username}")
except ValueError as e:
logger.error(f"Configuration error: {e}", exc_info=True)
raise
if username:
api = AirlockAPIWrapper(
base_url=str(os.getenv("URL")),
api_key = await getAPI(username, "AirlockTools"), # pyright: ignore[reportArgumentType]
)
await menus.menu_main(api, queue)
if __name__ == "__main__":
asyncio.run(main())