From 43d3aa20ff6ea49fde6be78b5ca8588180fad57a Mon Sep 17 00:00:00 2001 From: chenzuoqing Date: Wed, 8 Dec 2021 14:33:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 2 +- src/{asset => api}/__init__.py | 0 src/{ => api}/routes.py | 6 +-- src/{asset/views => api/v1}/__init__.py | 0 src/{asset/routes.py => api/v1/asset.py} | 7 ++- src/{project/routes.py => api/v1/project.py} | 14 ++---- src/{project => controller}/__init__.py | 0 .../views => controller/asset}/__init__.py | 0 .../views => controller/asset}/views.py | 44 +++++++++---------- src/controller/project/__init__.py | 0 .../views => controller/project}/operation.py | 10 ++--- .../views => controller/project}/views.py | 4 +- src/models/__init__.py | 0 src/models/asset/__init__.py | 1 + src/{ => models}/asset/fields.py | 1 + src/{ => models}/asset/models.py | 1 + src/models/project/__init__.py | 0 src/{ => models}/project/fields.py | 10 ++--- src/{ => models}/project/models.py | 2 +- src/service/__init__.py | 0 20 files changed, 48 insertions(+), 54 deletions(-) rename src/{asset => api}/__init__.py (100%) rename src/{ => api}/routes.py (81%) rename src/{asset/views => api/v1}/__init__.py (100%) rename src/{asset/routes.py => api/v1/asset.py} (89%) rename src/{project/routes.py => api/v1/project.py} (71%) rename src/{project => controller}/__init__.py (100%) rename src/{project/views => controller/asset}/__init__.py (100%) rename src/{asset/views => controller/asset}/views.py (91%) create mode 100644 src/controller/project/__init__.py rename src/{project/views => controller/project}/operation.py (96%) rename src/{project/views => controller/project}/views.py (88%) create mode 100644 src/models/__init__.py create mode 100644 src/models/asset/__init__.py rename src/{ => models}/asset/fields.py (98%) rename src/{ => models}/asset/models.py (98%) create mode 100644 src/models/project/__init__.py rename src/{ => models}/project/fields.py (92%) rename src/{ => models}/project/models.py (99%) create mode 100644 src/service/__init__.py diff --git a/app.py b/app.py index c8fa703..5e69d1a 100644 --- a/app.py +++ b/app.py @@ -7,7 +7,7 @@ from flask.logging import default_handler sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) from database.mongodb import initialize_db -from routes import blueprint_api +from api.routes import blueprint_api from settings.dev import LOGGING from settings.common import INSTANCE, VERSION from common.utils import make_response diff --git a/src/asset/__init__.py b/src/api/__init__.py similarity index 100% rename from src/asset/__init__.py rename to src/api/__init__.py diff --git a/src/routes.py b/src/api/routes.py similarity index 81% rename from src/routes.py rename to src/api/routes.py index 0a86620..ff527cb 100644 --- a/src/routes.py +++ b/src/api/routes.py @@ -1,7 +1,7 @@ from flask import Blueprint -from project.routes import project_v1 -# from project.routes import project_v2 -from asset.routes import asset_v1 +from api.v1.asset import asset as asset_v1 +from api.v1.project import project as project_v1 + blueprint_api = Blueprint('api-main', __name__, url_prefix='/api') diff --git a/src/asset/views/__init__.py b/src/api/v1/__init__.py similarity index 100% rename from src/asset/views/__init__.py rename to src/api/v1/__init__.py diff --git a/src/asset/routes.py b/src/api/v1/asset.py similarity index 89% rename from src/asset/routes.py rename to src/api/v1/asset.py index 5bbaf6c..2e63243 100644 --- a/src/asset/routes.py +++ b/src/api/v1/asset.py @@ -1,14 +1,13 @@ from flask import Blueprint from flask_restful import Api -from asset.views import views - +from controller.asset import views # 当前app的蓝图,以app名为前缀 -asset_v1 = Blueprint('asset', __name__, url_prefix="/asset") +asset = Blueprint('asset', __name__, url_prefix="/asset") # 增加路由 -api = Api(asset_v1) +api = Api(asset) api.add_resource(views.HostViews, '/host/', endpoint="host") api.add_resource(views.HostDetailViews, '/host//', endpoint="host-detail") diff --git a/src/project/routes.py b/src/api/v1/project.py similarity index 71% rename from src/project/routes.py rename to src/api/v1/project.py index a4ea2be..3250181 100644 --- a/src/project/routes.py +++ b/src/api/v1/project.py @@ -1,14 +1,14 @@ from flask import Blueprint from flask_restful import Api -from project.views import views, operation +from controller.project import views, operation # 当前app的蓝图,以app名为前缀 -project_v1 = Blueprint('project', __name__, url_prefix="/project") +project = Blueprint('project', __name__, url_prefix="/project") # 增加路由 -api = Api(project_v1) +api = Api(project) # 项目模型的视图 api.add_resource(views.ProjectViews, '/item/', endpoint="project") api.add_resource(views.ProjectDetailViews, '/item//', endpoint="project-detail") @@ -25,11 +25,3 @@ api.add_resource(operation.ServerSyncView, '/server/sync/', endpoint="server-syn # 机器信息 api.add_resource(operation.AgentInfo, '/agent/info//', endpoint="agent-info") - - -# # 接口版本v2 -# project_v2 = Blueprint('project', __name__, url_prefix="/project") -# # 增加路由 -# api = Api(project_v2) -# # 项目模型的视图 -# api.add_resource(views.ProjectViews, '/item/', endpoint="project_v2") diff --git a/src/project/__init__.py b/src/controller/__init__.py similarity index 100% rename from src/project/__init__.py rename to src/controller/__init__.py diff --git a/src/project/views/__init__.py b/src/controller/asset/__init__.py similarity index 100% rename from src/project/views/__init__.py rename to src/controller/asset/__init__.py diff --git a/src/asset/views/views.py b/src/controller/asset/views.py similarity index 91% rename from src/asset/views/views.py rename to src/controller/asset/views.py index f40685f..50bb5e7 100644 --- a/src/asset/views/views.py +++ b/src/controller/asset/views.py @@ -2,8 +2,8 @@ import datetime from flask_restful import reqparse -from asset import fields -from asset import models +from models.asset import fields as assetField +from models.asset import models as assetModel from common.views import ListCreateViewSet, DetailViewSet @@ -38,8 +38,8 @@ class HostParse: class HostViews(HostParse, ListCreateViewSet): - model = models.Host - fields = fields.HostFields + model = assetModel.Host + fields = assetField.HostFields def __init__(self): self.init_parse() @@ -49,8 +49,8 @@ class HostViews(HostParse, ListCreateViewSet): class HostDetailViews(HostParse, DetailViewSet): - model = models.Host - fields = fields.HostFields + model = assetModel.Host + fields = assetField.HostFields def __init__(self): self.init_parse() @@ -72,8 +72,8 @@ class DatabaseServerParse: class MySQLInstanceViews(DatabaseServerParse, ListCreateViewSet): - model = models.MySQLInstance - fields = fields.MySQLInstanceFields + model = assetModel.MySQLInstance + fields = assetField.MySQLInstanceFields def __init__(self): self.init_parse() @@ -91,8 +91,8 @@ class MySQLInstanceViews(DatabaseServerParse, ListCreateViewSet): class MySQLInstanceDetail(DatabaseServerParse, DetailViewSet): - model = models.MySQLInstance - fields = fields.MySQLInstanceFields + model = assetModel.MySQLInstance + fields = assetField.MySQLInstanceFields def __init__(self): """对象修改的参数解析""" @@ -111,8 +111,8 @@ class MySQLInstanceDetail(DatabaseServerParse, DetailViewSet): class RedisInstanceViews(DatabaseServerParse, ListCreateViewSet): - model = models.RedisInstance - fields = fields.RedisInstanceFields + model = assetModel.RedisInstance + fields = assetField.RedisInstanceFields def __init__(self): self.init_parse() @@ -128,8 +128,8 @@ class RedisInstanceViews(DatabaseServerParse, ListCreateViewSet): class RedisInstanceDetail(DatabaseServerParse, DetailViewSet): - model = models.RedisInstance - fields = fields.RedisInstanceFields + model = assetModel.RedisInstance + fields = assetField.RedisInstanceFields def __init__(self): self.init_parse() @@ -158,8 +158,8 @@ class MiddlewareParse: class NginxInstanceViews(MiddlewareParse, ListCreateViewSet): - model = models.NginxInstance - fields = fields.NginxInstanceFields + model = assetModel.NginxInstance + fields = assetField.NginxInstanceFields def __init__(self): self.init_parse() @@ -172,8 +172,8 @@ class NginxInstanceViews(MiddlewareParse, ListCreateViewSet): class NginxInstanceDetail(MiddlewareParse, DetailViewSet): - model = models.NginxInstance - fields = fields.NginxInstanceFields + model = assetModel.NginxInstance + fields = assetField.NginxInstanceFields def __init__(self): self.init_parse() @@ -186,8 +186,8 @@ class NginxInstanceDetail(MiddlewareParse, DetailViewSet): class CDNViews(ListCreateViewSet): - model = models.CDN - fields = fields.CDNFields + model = assetModel.CDN + fields = assetField.CDNFields uniq_fields = ("domain",) def __init__(self): @@ -200,8 +200,8 @@ class CDNViews(ListCreateViewSet): class CDNDetail(DetailViewSet): - model = models.CDN - fields = fields.CDNFields + model = assetModel.CDN + fields = assetField.CDNFields uniq_fields = ("domain",) def __init__(self): diff --git a/src/controller/project/__init__.py b/src/controller/project/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/project/views/operation.py b/src/controller/project/operation.py similarity index 96% rename from src/project/views/operation.py rename to src/controller/project/operation.py index 2d514fe..bed67c8 100644 --- a/src/project/views/operation.py +++ b/src/controller/project/operation.py @@ -1,12 +1,12 @@ import datetime from flask import current_app as app -from flask_restful import reqparse, Resource, marshal, fields as F +from flask_restful import reqparse, marshal, fields as F -from asset.models import Host -from asset.fields import HostFields -from project import fields -from project.models import Project, Channel, Server, Version +from models.asset.models import Host +from models.asset.fields import HostFields +from models.project import fields +from models.project.models import Project, Channel, Server, Version from common.views import CreateMixin, RetrieveMixin from common.permission import token_header_required from common.utils import make_response diff --git a/src/project/views/views.py b/src/controller/project/views.py similarity index 88% rename from src/project/views/views.py rename to src/controller/project/views.py index ea845a8..af251d5 100644 --- a/src/project/views/views.py +++ b/src/controller/project/views.py @@ -1,7 +1,7 @@ """数据模型常规增删查改的接口""" -from project import fields -from project.models import Project, Channel, Server +from models.project import fields +from models.project.models import Project, Channel, Server from common.views import ListMixin, CreateMixin, ListCreateViewSet, DetailViewSet diff --git a/src/models/__init__.py b/src/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/models/asset/__init__.py b/src/models/asset/__init__.py new file mode 100644 index 0000000..b6e690f --- /dev/null +++ b/src/models/asset/__init__.py @@ -0,0 +1 @@ +from . import * diff --git a/src/asset/fields.py b/src/models/asset/fields.py similarity index 98% rename from src/asset/fields.py rename to src/models/asset/fields.py index 1435cb1..203d369 100644 --- a/src/asset/fields.py +++ b/src/models/asset/fields.py @@ -86,6 +86,7 @@ CDNFields = { "id": fields.String, "domain": fields.String, "data": fields.Raw, + "manage": fields.String, "tags": fields.List(fields.String), "labels": fields.Raw, } diff --git a/src/asset/models.py b/src/models/asset/models.py similarity index 98% rename from src/asset/models.py rename to src/models/asset/models.py index aabbb22..5a19a19 100644 --- a/src/asset/models.py +++ b/src/models/asset/models.py @@ -98,6 +98,7 @@ class NginxInstance(Middleware): class CDN(DocumentBase): """cdn域名""" domain = mongo.StringField(max_length=256, required=True) # cdn域名 + manage = mongo.StringField(max_length=128, default="") data = mongo.DictField(default=dict) # 标记和标签 tags = mongo.ListField(mongo.StringField(), default=list) # tags 默认是空列表 diff --git a/src/models/project/__init__.py b/src/models/project/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/project/fields.py b/src/models/project/fields.py similarity index 92% rename from src/project/fields.py rename to src/models/project/fields.py index a8c75ff..c9116a9 100644 --- a/src/project/fields.py +++ b/src/models/project/fields.py @@ -3,7 +3,7 @@ project marshal fields """ from flask_restful import fields -from asset.fields import HostSimpleFields +from models.asset.fields import HostSimpleFields ProjectFields = { "id": fields.String, @@ -81,19 +81,19 @@ AgentServerFields = { "spid": fields.String, "agent": fields.String, "is_cross": fields.Boolean, - # "channel_id": fields.String, + # "channel_id": serializer.String, "project": fields.String, "project_name": fields.String, "project_fork": fields.String, "public_ip": fields.String, "private_ip": fields.String, - # "host_id": fields.String, + # "host_id": serializer.String, "domain": fields.String, "port": fields.Integer, "version": fields.Nested(VersionFields), "status": fields.String, "weight": fields.Integer, "slot": fields.Integer, - # "tags": fields.List(fields.String), - # "labels": fields.Raw, + # "tags": serializer.List(serializer.String), + # "labels": serializer.Raw, } diff --git a/src/project/models.py b/src/models/project/models.py similarity index 99% rename from src/project/models.py rename to src/models/project/models.py index 87e7930..3001368 100644 --- a/src/project/models.py +++ b/src/models/project/models.py @@ -4,7 +4,7 @@ from settings import common from common.document import DocumentBase from common.validator import isalnum, is_hex_string -from asset.models import Host +from models.asset.models import Host class Project(DocumentBase): diff --git a/src/service/__init__.py b/src/service/__init__.py new file mode 100644 index 0000000..e69de29