diff --git a/appmanage_new/README.md b/apphub/README.md old mode 100644 new mode 100755 similarity index 95% rename from appmanage_new/README.md rename to apphub/README.md index 156b85bb..532e4cc4 --- a/appmanage_new/README.md +++ b/apphub/README.md @@ -1,11 +1,17 @@ -## run app : uvicorn src.main:app --reload --port 9999 --log-level error -## run nginx proxy manager doc:docker run -p 9091:8080 -e SWAGGER_JSON=/foo/api.swagger.json -v /data/websoft9/appmanage_new/docs/:/foo swaggerapi/swagger-ui -## supervisorctl -## supervisorctl reload -## supervisorctl update -## supervisorctl status -# gitea_token: da7b9891a0bc71b5026b389c11ed13238c9a3866 +# cli +## apphub +''' +Usage: apphub [OPTIONS] COMMAND [ARGS]... + +Options: + --help Show this message and exit. + +Commands: + genkey Generate a new API key + getconfig Get a config value + setconfig Set a config value +''' # 项目结构 ## src diff --git a/appmanage_new/src/__init__.py b/apphub/build/lib/cli/__init__.py similarity index 100% rename from appmanage_new/src/__init__.py rename to apphub/build/lib/cli/__init__.py diff --git a/apphub/build/lib/cli/apphub_cli.py b/apphub/build/lib/cli/apphub_cli.py new file mode 100644 index 00000000..cf49cfca --- /dev/null +++ b/apphub/build/lib/cli/apphub_cli.py @@ -0,0 +1,36 @@ +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) + +import click +from src.services.apikey_manager import APIKeyManager +from src.services.settings_manager import SettingsManager + +@click.group() +def cli(): + pass + +@cli.command() +def genkey(): + """Generate a new API key""" + key = APIKeyManager().generate_key() + click.echo(f"{key}") + +@cli.command() +@click.option('--section',required=True, help='The section name') +@click.option('--key', required=True, help='The key name') +@click.option('--value', required=True,help='The value of the key') +def setconfig(section, key, value): + """Set a config value""" + SettingsManager().write_section(section, key, value) + +@cli.command() +@click.option('--section',required=True, help='The section name') +@click.option('--key', required=True, help='The key name') +def getconfig(section, key): + """Get a config value""" + value = SettingsManager().read_section(section, key) + click.echo(f"{value}") + +if __name__ == "__main__": + cli() \ No newline at end of file diff --git a/appmanage_new/src/api/v1/__init__.py b/apphub/build/lib/src/__init__.py similarity index 100% rename from appmanage_new/src/api/v1/__init__.py rename to apphub/build/lib/src/__init__.py diff --git a/appmanage_new/src/api/v1/routers/__init__.py b/apphub/build/lib/src/cli/__init__.py similarity index 100% rename from appmanage_new/src/api/v1/routers/__init__.py rename to apphub/build/lib/src/cli/__init__.py diff --git a/apphub/build/lib/src/cli/apphub_cli.py b/apphub/build/lib/src/cli/apphub_cli.py new file mode 100644 index 00000000..5de42392 --- /dev/null +++ b/apphub/build/lib/src/cli/apphub_cli.py @@ -0,0 +1,28 @@ +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) + +import click +from src.services.apikey_manager import APIKeyManager +from src.services.settings_manager import SettingsManager + +@click.group() +def cli(): + pass + +@cli.command() +def genkey(): + """Generate a new API key""" + key = APIKeyManager().generate_key() + click.echo(f"{key}") + +@cli.command() +@click.option('--section',required=True, help='The section name') +@click.option('--key', required=True, help='The key name') +@click.option('--value', required=True,help='The value of the key') +def setconfig(section, key, value): + """Set a config value""" + SettingsManager().write_section(section, key, value) + +if __name__ == "__main__": + cli() \ No newline at end of file diff --git a/appmanage_new/src/main.py b/apphub/build/lib/src/main.py similarity index 100% rename from appmanage_new/src/main.py rename to apphub/build/lib/src/main.py diff --git a/appmanage_new/docs/MAINTAINERS.md b/apphub/docs/MAINTAINERS.md old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/docs/MAINTAINERS.md rename to apphub/docs/MAINTAINERS.md diff --git a/appmanage_new/docs/api.swagger.json b/apphub/docs/api.swagger.json old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/docs/api.swagger.json rename to apphub/docs/api.swagger.json diff --git a/appmanage_new/docs/architecture.md b/apphub/docs/architecture.md old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/docs/architecture.md rename to apphub/docs/architecture.md diff --git a/appmanage_new/docs/developer.md b/apphub/docs/developer.md old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/docs/developer.md rename to apphub/docs/developer.md diff --git a/appmanage_new/docs/image/archi.png b/apphub/docs/image/archi.png old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/docs/image/archi.png rename to apphub/docs/image/archi.png diff --git a/appmanage_new/docs/notes/PRD.md b/apphub/docs/notes/PRD.md old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/docs/notes/PRD.md rename to apphub/docs/notes/PRD.md diff --git a/appmanage_new/docs/notes/research.md b/apphub/docs/notes/research.md old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/docs/notes/research.md rename to apphub/docs/notes/research.md diff --git a/appmanage_new/docs/notes/软件工厂.md b/apphub/docs/notes/软件工厂.md old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/docs/notes/软件工厂.md rename to apphub/docs/notes/软件工厂.md diff --git a/appmanage_new/docs/plugin-developer.md b/apphub/docs/plugin-developer.md old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/docs/plugin-developer.md rename to apphub/docs/plugin-developer.md diff --git a/appmanage_new/docs/recruit.md b/apphub/docs/recruit.md old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/docs/recruit.md rename to apphub/docs/recruit.md diff --git a/appmanage_new/docs/user.md b/apphub/docs/user.md old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/docs/user.md rename to apphub/docs/user.md diff --git a/appmanage_new/requirements.txt b/apphub/requirements.txt old mode 100644 new mode 100755 similarity index 83% rename from appmanage_new/requirements.txt rename to apphub/requirements.txt index f619a347..a612d257 --- a/appmanage_new/requirements.txt +++ b/apphub/requirements.txt @@ -4,4 +4,5 @@ keyring keyrings.alt requests GitPython -PyJWT \ No newline at end of file +PyJWT +click \ No newline at end of file diff --git a/apphub/setup.py b/apphub/setup.py new file mode 100644 index 00000000..1082b764 --- /dev/null +++ b/apphub/setup.py @@ -0,0 +1,16 @@ +from setuptools import find_packages, setup + +setup( + name='apphub', + version='0.2', + packages=find_packages(where='src'), + package_dir={'': 'src'}, + install_requires=[ + 'click', + ], + entry_points={ + 'console_scripts': [ + 'apphub=cli.apphub_cli:cli', + ], + }, +) diff --git a/appmanage_new/src/config/system.ini b/apphub/src/__init__.py old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/src/config/system.ini rename to apphub/src/__init__.py diff --git a/appmanage_new/tests/README.md b/apphub/src/api/v1/__init__.py old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/tests/README.md rename to apphub/src/api/v1/__init__.py diff --git a/apphub/src/api/v1/routers/__init__.py b/apphub/src/api/v1/routers/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/appmanage_new/src/api/v1/routers/app.py b/apphub/src/api/v1/routers/app.py old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/src/api/v1/routers/app.py rename to apphub/src/api/v1/routers/app.py diff --git a/appmanage_new/src/api/v1/routers/proxy.py b/apphub/src/api/v1/routers/proxy.py old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/src/api/v1/routers/proxy.py rename to apphub/src/api/v1/routers/proxy.py diff --git a/apphub/src/api/v1/routers/settings.py b/apphub/src/api/v1/routers/settings.py new file mode 100755 index 00000000..c4f06561 --- /dev/null +++ b/apphub/src/api/v1/routers/settings.py @@ -0,0 +1,52 @@ +from fastapi import APIRouter, Query,Path +from src.schemas.appSettings import AppSettings +from src.schemas.errorResponse import ErrorResponse +from typing import List + +from src.services.settings_manager import SettingsManager + +router = APIRouter() + +@router.get("/settings", + summary="Get settings", + description="Get settings", + responses={ + 200: {"model": AppSettings}, + 400: {"model": ErrorResponse}, + 500: {"model": ErrorResponse}, + } + ) +def get_settings(): + return SettingsManager().read_all() + +@router.get( + "/settings/{section}", + summary="Get settings", + description="Get settings by section", + responses={ + 200: {"model": AppSettings}, + 400: {"model": ErrorResponse}, + 500: {"model": ErrorResponse}, + } + ) +def get_setting_by_section( + section: str = Path(..., description="Section name to update settings from"), +): + return SettingsManager().read_section(section) + +@router.put( + "/settings/{section}", + summary="Update Settings", + description="Update settings", + responses={ + 200: {"model": AppSettings}, + 400: {"model": ErrorResponse}, + 500: {"model": ErrorResponse}, + } + ) +def update_settings( + section: str = Path(..., description="Section name to update settings from"), + key: str = Query(..., description="Key name to update settings from"), + value: str = Query(..., description="Key value to update settings from"), +): + return SettingsManager().write_section(section,key,value) \ No newline at end of file diff --git a/apphub/src/apphub.egg-info/PKG-INFO b/apphub/src/apphub.egg-info/PKG-INFO new file mode 100644 index 00000000..bc6a0c19 --- /dev/null +++ b/apphub/src/apphub.egg-info/PKG-INFO @@ -0,0 +1,3 @@ +Metadata-Version: 2.1 +Name: apphub +Version: 0.2 diff --git a/apphub/src/apphub.egg-info/SOURCES.txt b/apphub/src/apphub.egg-info/SOURCES.txt new file mode 100644 index 00000000..d26bf7f9 --- /dev/null +++ b/apphub/src/apphub.egg-info/SOURCES.txt @@ -0,0 +1,16 @@ +README.md +setup.py +/websoft9/apphub/src/apphub.egg-info/PKG-INFO +/websoft9/apphub/src/apphub.egg-info/SOURCES.txt +/websoft9/apphub/src/apphub.egg-info/dependency_links.txt +/websoft9/apphub/src/apphub.egg-info/entry_points.txt +/websoft9/apphub/src/apphub.egg-info/requires.txt +/websoft9/apphub/src/apphub.egg-info/top_level.txt +src/apphub.egg-info/PKG-INFO +src/apphub.egg-info/SOURCES.txt +src/apphub.egg-info/dependency_links.txt +src/apphub.egg-info/entry_points.txt +src/apphub.egg-info/requires.txt +src/apphub.egg-info/top_level.txt +src/cli/__init__.py +src/cli/apphub_cli.py \ No newline at end of file diff --git a/apphub/src/apphub.egg-info/dependency_links.txt b/apphub/src/apphub.egg-info/dependency_links.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/apphub/src/apphub.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/apphub/src/apphub.egg-info/entry_points.txt b/apphub/src/apphub.egg-info/entry_points.txt new file mode 100644 index 00000000..e365cb8a --- /dev/null +++ b/apphub/src/apphub.egg-info/entry_points.txt @@ -0,0 +1,2 @@ +[console_scripts] +apphub = cli.apphub_cli:cli diff --git a/apphub/src/apphub.egg-info/requires.txt b/apphub/src/apphub.egg-info/requires.txt new file mode 100644 index 00000000..dca9a909 --- /dev/null +++ b/apphub/src/apphub.egg-info/requires.txt @@ -0,0 +1 @@ +click diff --git a/apphub/src/apphub.egg-info/top_level.txt b/apphub/src/apphub.egg-info/top_level.txt new file mode 100644 index 00000000..573c0c4f --- /dev/null +++ b/apphub/src/apphub.egg-info/top_level.txt @@ -0,0 +1 @@ +cli diff --git a/apphub/src/cli/__init__.py b/apphub/src/cli/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/apphub/src/cli/apphub.egg-info/PKG-INFO b/apphub/src/cli/apphub.egg-info/PKG-INFO new file mode 100644 index 00000000..91a0261c --- /dev/null +++ b/apphub/src/cli/apphub.egg-info/PKG-INFO @@ -0,0 +1,3 @@ +Metadata-Version: 2.1 +Name: apphub +Version: 0.1 diff --git a/apphub/src/cli/apphub.egg-info/SOURCES.txt b/apphub/src/cli/apphub.egg-info/SOURCES.txt new file mode 100644 index 00000000..a51b5671 --- /dev/null +++ b/apphub/src/cli/apphub.egg-info/SOURCES.txt @@ -0,0 +1,7 @@ +setup.py +apphub.egg-info/PKG-INFO +apphub.egg-info/SOURCES.txt +apphub.egg-info/dependency_links.txt +apphub.egg-info/entry_points.txt +apphub.egg-info/requires.txt +apphub.egg-info/top_level.txt \ No newline at end of file diff --git a/apphub/src/cli/apphub.egg-info/dependency_links.txt b/apphub/src/cli/apphub.egg-info/dependency_links.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/apphub/src/cli/apphub.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/apphub/src/cli/apphub.egg-info/entry_points.txt b/apphub/src/cli/apphub.egg-info/entry_points.txt new file mode 100644 index 00000000..2439a0a3 --- /dev/null +++ b/apphub/src/cli/apphub.egg-info/entry_points.txt @@ -0,0 +1,2 @@ +[console_scripts] +apphub = cli.apphub_cli:main diff --git a/apphub/src/cli/apphub.egg-info/requires.txt b/apphub/src/cli/apphub.egg-info/requires.txt new file mode 100644 index 00000000..dca9a909 --- /dev/null +++ b/apphub/src/cli/apphub.egg-info/requires.txt @@ -0,0 +1 @@ +click diff --git a/apphub/src/cli/apphub.egg-info/top_level.txt b/apphub/src/cli/apphub.egg-info/top_level.txt new file mode 100644 index 00000000..573c0c4f --- /dev/null +++ b/apphub/src/cli/apphub.egg-info/top_level.txt @@ -0,0 +1 @@ +cli diff --git a/apphub/src/cli/apphub_cli.py b/apphub/src/cli/apphub_cli.py new file mode 100755 index 00000000..e176e3c4 --- /dev/null +++ b/apphub/src/cli/apphub_cli.py @@ -0,0 +1,36 @@ +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) + +import click +from src.services.apikey_manager import APIKeyManager +from src.services.settings_manager import SettingsManager + +@click.group() +def cli(): + pass + +@cli.command() +def genkey(): + """Generate a new API key""" + key = APIKeyManager().generate_key() + click.echo(f"{key}") + +@cli.command() +@click.option('--section',required=True, help='The section name') +@click.option('--key', required=True, help='The key name') +@click.option('--value', required=True,help='The value of the key') +def setconfig(section, key, value): + """Set a config value""" + SettingsManager().write_section(section, key, value) + +@cli.command() +@click.option('--section',required=True, help='The section name') +@click.option('--key', required=True, help='The key name') +def getconfig(section, key): + """Get a config value""" + value = SettingsManager().read_key(section, key) + click.echo(f"{value}") + +if __name__ == "__main__": + cli() \ No newline at end of file diff --git a/appmanage_new/src/config/config.ini b/apphub/src/config/config.ini old mode 100644 new mode 100755 similarity index 63% rename from appmanage_new/src/config/config.ini rename to apphub/src/config/config.ini index 10a5b7aa..6b0d06e8 --- a/appmanage_new/src/config/config.ini +++ b/apphub/src/config/config.ini @@ -2,23 +2,33 @@ [nginx_proxy_manager] base_url = http://websoft9-proxy:81/api user_name = help@websoft9.com -user_pwd = ECTKPRAWhij789yr +user_pwd = L2l6nuFu2jL0Rm8L +nike_name = admin #The config for gitea [gitea] base_url = http://websoft9-git:3000/api/v1 user_name = websoft9 -user_pwd = Rk9qOQ68Inf0 +user_pwd = XATY3rEgQ1bA #The config for portainer [portainer] base_url = http://websoft9-deployment:9000/api user_name = admin -user_pwd = ]}fU;XmVH].VI{Hh +user_pwd = fn9BrJhd)An8T8Ez #The path of docker library [docker_library] path = /websoft9/library/apps +#The path of app media [app_media] -path = /websoft9/media/json/ \ No newline at end of file +path = /websoft9/media/json/ + +#The value of api_key +[api_key] +key = + +#The config for cockpit +[cockpit] +port = 9090 \ No newline at end of file diff --git a/apphub/src/config/system.ini b/apphub/src/config/system.ini new file mode 100755 index 00000000..e69de29b diff --git a/appmanage_new/src/core/apiHelper.py b/apphub/src/core/apiHelper.py old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/src/core/apiHelper.py rename to apphub/src/core/apiHelper.py diff --git a/appmanage_new/src/core/config.py b/apphub/src/core/config.py old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/src/core/config.py rename to apphub/src/core/config.py diff --git a/appmanage_new/src/core/envHelper.py b/apphub/src/core/envHelper.py old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/src/core/envHelper.py rename to apphub/src/core/envHelper.py diff --git a/appmanage_new/src/core/exception.py b/apphub/src/core/exception.py old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/src/core/exception.py rename to apphub/src/core/exception.py diff --git a/appmanage_new/src/core/logger.py b/apphub/src/core/logger.py old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/src/core/logger.py rename to apphub/src/core/logger.py diff --git a/appmanage_new/src/external/gitea_api.py b/apphub/src/external/gitea_api.py old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/src/external/gitea_api.py rename to apphub/src/external/gitea_api.py diff --git a/appmanage_new/src/external/nginx_proxy_manager_api.py b/apphub/src/external/nginx_proxy_manager_api.py old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/src/external/nginx_proxy_manager_api.py rename to apphub/src/external/nginx_proxy_manager_api.py diff --git a/appmanage_new/src/external/portainer_api.py b/apphub/src/external/portainer_api.py old mode 100644 new mode 100755 similarity index 100% rename from appmanage_new/src/external/portainer_api.py rename to apphub/src/external/portainer_api.py diff --git a/apphub/src/main.py b/apphub/src/main.py new file mode 100755 index 00000000..3aae4a9f --- /dev/null +++ b/apphub/src/main.py @@ -0,0 +1,113 @@ +import logging +from fastapi import FastAPI, Request,Security,Depends +from fastapi.exceptions import RequestValidationError +from fastapi.responses import JSONResponse +from fastapi.staticfiles import StaticFiles +from src.api.v1.routers import app as api_app +from src.api.v1.routers import settings as api_settings +from src.api.v1.routers import proxy as api_proxy +from src.core.config import ConfigManager +from src.core.exception import CustomException +from src.core.logger import logger +from src.schemas.errorResponse import ErrorResponse +from fastapi.responses import HTMLResponse +from fastapi.security.api_key import APIKeyHeader + +uvicorn_logger = logging.getLogger("uvicorn") + +for handler in uvicorn_logger.handlers: + uvicorn_logger.removeHandler(handler) +for handler in logger._error_logger.handlers: + uvicorn_logger.addHandler(handler) + +uvicorn_logger.setLevel(logging.INFO) + +API_KEY = ConfigManager().get_value("api_key","key") +API_KEY_NAME = "api_key" +api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=False) + +async def verify_key(request: Request, api_key_header: str = Security(api_key_header)): + if request.url.path == "/docs": + return None + + if api_key_header is None: + raise CustomException( + status_code=400, + message="Invalid Request", + details="No API Key provided" + ) + + if api_key_header != API_KEY: + raise CustomException( + status_code=400, + message="Invalid Request", + details="Invalid API Key" + ) + + return api_key_header + + +app = FastAPI( + title="AppManae API", + description="This documentation describes the AppManage API.", + version="0.0.1", + docs_url=None, + dependencies=[Depends(verify_key)] + ) + +app.mount("/static", StaticFiles(directory="swagger-ui"), name="static") + +@app.get("/docs", response_class=HTMLResponse,include_in_schema=False,) +async def custom_swagger_ui_html(): + return """ + + +
+