目录结构调整

This commit is contained in:
chenzuoqing 2021-12-08 14:33:17 +08:00
parent 58d8cdf3d5
commit 43d3aa20ff
20 changed files with 48 additions and 54 deletions

2
app.py
View File

@ -7,7 +7,7 @@ from flask.logging import default_handler
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from database.mongodb import initialize_db from database.mongodb import initialize_db
from routes import blueprint_api from api.routes import blueprint_api
from settings.dev import LOGGING from settings.dev import LOGGING
from settings.common import INSTANCE, VERSION from settings.common import INSTANCE, VERSION
from common.utils import make_response from common.utils import make_response

View File

@ -1,7 +1,7 @@
from flask import Blueprint from flask import Blueprint
from project.routes import project_v1 from api.v1.asset import asset as asset_v1
# from project.routes import project_v2 from api.v1.project import project as project_v1
from asset.routes import asset_v1
blueprint_api = Blueprint('api-main', __name__, url_prefix='/api') blueprint_api = Blueprint('api-main', __name__, url_prefix='/api')

View File

@ -1,14 +1,13 @@
from flask import Blueprint from flask import Blueprint
from flask_restful import Api from flask_restful import Api
from asset.views import views from controller.asset import views
# 当前app的蓝图以app名为前缀 # 当前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.HostViews, '/host/', endpoint="host")
api.add_resource(views.HostDetailViews, '/host/<string:pk>/', endpoint="host-detail") api.add_resource(views.HostDetailViews, '/host/<string:pk>/', endpoint="host-detail")

View File

@ -1,14 +1,14 @@
from flask import Blueprint from flask import Blueprint
from flask_restful import Api from flask_restful import Api
from project.views import views, operation from controller.project import views, operation
# 当前app的蓝图以app名为前缀 # 当前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.ProjectViews, '/item/', endpoint="project")
api.add_resource(views.ProjectDetailViews, '/item/<string:pk>/', endpoint="project-detail") api.add_resource(views.ProjectDetailViews, '/item/<string:pk>/', endpoint="project-detail")
@ -25,11 +25,3 @@ api.add_resource(operation.ServerSyncView, '/server/sync/', endpoint="server-syn
# 机器信息 # 机器信息
api.add_resource(operation.AgentInfo, '/agent/info/<string:agent_id>/', endpoint="agent-info") api.add_resource(operation.AgentInfo, '/agent/info/<string:agent_id>/', 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")

View File

@ -2,8 +2,8 @@ import datetime
from flask_restful import reqparse from flask_restful import reqparse
from asset import fields from models.asset import fields as assetField
from asset import models from models.asset import models as assetModel
from common.views import ListCreateViewSet, DetailViewSet from common.views import ListCreateViewSet, DetailViewSet
@ -38,8 +38,8 @@ class HostParse:
class HostViews(HostParse, ListCreateViewSet): class HostViews(HostParse, ListCreateViewSet):
model = models.Host model = assetModel.Host
fields = fields.HostFields fields = assetField.HostFields
def __init__(self): def __init__(self):
self.init_parse() self.init_parse()
@ -49,8 +49,8 @@ class HostViews(HostParse, ListCreateViewSet):
class HostDetailViews(HostParse, DetailViewSet): class HostDetailViews(HostParse, DetailViewSet):
model = models.Host model = assetModel.Host
fields = fields.HostFields fields = assetField.HostFields
def __init__(self): def __init__(self):
self.init_parse() self.init_parse()
@ -72,8 +72,8 @@ class DatabaseServerParse:
class MySQLInstanceViews(DatabaseServerParse, ListCreateViewSet): class MySQLInstanceViews(DatabaseServerParse, ListCreateViewSet):
model = models.MySQLInstance model = assetModel.MySQLInstance
fields = fields.MySQLInstanceFields fields = assetField.MySQLInstanceFields
def __init__(self): def __init__(self):
self.init_parse() self.init_parse()
@ -91,8 +91,8 @@ class MySQLInstanceViews(DatabaseServerParse, ListCreateViewSet):
class MySQLInstanceDetail(DatabaseServerParse, DetailViewSet): class MySQLInstanceDetail(DatabaseServerParse, DetailViewSet):
model = models.MySQLInstance model = assetModel.MySQLInstance
fields = fields.MySQLInstanceFields fields = assetField.MySQLInstanceFields
def __init__(self): def __init__(self):
"""对象修改的参数解析""" """对象修改的参数解析"""
@ -111,8 +111,8 @@ class MySQLInstanceDetail(DatabaseServerParse, DetailViewSet):
class RedisInstanceViews(DatabaseServerParse, ListCreateViewSet): class RedisInstanceViews(DatabaseServerParse, ListCreateViewSet):
model = models.RedisInstance model = assetModel.RedisInstance
fields = fields.RedisInstanceFields fields = assetField.RedisInstanceFields
def __init__(self): def __init__(self):
self.init_parse() self.init_parse()
@ -128,8 +128,8 @@ class RedisInstanceViews(DatabaseServerParse, ListCreateViewSet):
class RedisInstanceDetail(DatabaseServerParse, DetailViewSet): class RedisInstanceDetail(DatabaseServerParse, DetailViewSet):
model = models.RedisInstance model = assetModel.RedisInstance
fields = fields.RedisInstanceFields fields = assetField.RedisInstanceFields
def __init__(self): def __init__(self):
self.init_parse() self.init_parse()
@ -158,8 +158,8 @@ class MiddlewareParse:
class NginxInstanceViews(MiddlewareParse, ListCreateViewSet): class NginxInstanceViews(MiddlewareParse, ListCreateViewSet):
model = models.NginxInstance model = assetModel.NginxInstance
fields = fields.NginxInstanceFields fields = assetField.NginxInstanceFields
def __init__(self): def __init__(self):
self.init_parse() self.init_parse()
@ -172,8 +172,8 @@ class NginxInstanceViews(MiddlewareParse, ListCreateViewSet):
class NginxInstanceDetail(MiddlewareParse, DetailViewSet): class NginxInstanceDetail(MiddlewareParse, DetailViewSet):
model = models.NginxInstance model = assetModel.NginxInstance
fields = fields.NginxInstanceFields fields = assetField.NginxInstanceFields
def __init__(self): def __init__(self):
self.init_parse() self.init_parse()
@ -186,8 +186,8 @@ class NginxInstanceDetail(MiddlewareParse, DetailViewSet):
class CDNViews(ListCreateViewSet): class CDNViews(ListCreateViewSet):
model = models.CDN model = assetModel.CDN
fields = fields.CDNFields fields = assetField.CDNFields
uniq_fields = ("domain",) uniq_fields = ("domain",)
def __init__(self): def __init__(self):
@ -200,8 +200,8 @@ class CDNViews(ListCreateViewSet):
class CDNDetail(DetailViewSet): class CDNDetail(DetailViewSet):
model = models.CDN model = assetModel.CDN
fields = fields.CDNFields fields = assetField.CDNFields
uniq_fields = ("domain",) uniq_fields = ("domain",)
def __init__(self): def __init__(self):

View File

View File

@ -1,12 +1,12 @@
import datetime import datetime
from flask import current_app as app 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 models.asset.models import Host
from asset.fields import HostFields from models.asset.fields import HostFields
from project import fields from models.project import fields
from project.models import Project, Channel, Server, Version from models.project.models import Project, Channel, Server, Version
from common.views import CreateMixin, RetrieveMixin from common.views import CreateMixin, RetrieveMixin
from common.permission import token_header_required from common.permission import token_header_required
from common.utils import make_response from common.utils import make_response

View File

@ -1,7 +1,7 @@
"""数据模型常规增删查改的接口""" """数据模型常规增删查改的接口"""
from project import fields from models.project import fields
from project.models import Project, Channel, Server from models.project.models import Project, Channel, Server
from common.views import ListMixin, CreateMixin, ListCreateViewSet, DetailViewSet from common.views import ListMixin, CreateMixin, ListCreateViewSet, DetailViewSet

0
src/models/__init__.py Normal file
View File

View File

@ -0,0 +1 @@
from . import *

View File

@ -86,6 +86,7 @@ CDNFields = {
"id": fields.String, "id": fields.String,
"domain": fields.String, "domain": fields.String,
"data": fields.Raw, "data": fields.Raw,
"manage": fields.String,
"tags": fields.List(fields.String), "tags": fields.List(fields.String),
"labels": fields.Raw, "labels": fields.Raw,
} }

View File

@ -98,6 +98,7 @@ class NginxInstance(Middleware):
class CDN(DocumentBase): class CDN(DocumentBase):
"""cdn域名""" """cdn域名"""
domain = mongo.StringField(max_length=256, required=True) # cdn域名 domain = mongo.StringField(max_length=256, required=True) # cdn域名
manage = mongo.StringField(max_length=128, default="")
data = mongo.DictField(default=dict) data = mongo.DictField(default=dict)
# 标记和标签 # 标记和标签
tags = mongo.ListField(mongo.StringField(), default=list) # tags 默认是空列表 tags = mongo.ListField(mongo.StringField(), default=list) # tags 默认是空列表

View File

View File

@ -3,7 +3,7 @@ project marshal fields
""" """
from flask_restful import fields from flask_restful import fields
from asset.fields import HostSimpleFields from models.asset.fields import HostSimpleFields
ProjectFields = { ProjectFields = {
"id": fields.String, "id": fields.String,
@ -81,19 +81,19 @@ AgentServerFields = {
"spid": fields.String, "spid": fields.String,
"agent": fields.String, "agent": fields.String,
"is_cross": fields.Boolean, "is_cross": fields.Boolean,
# "channel_id": fields.String, # "channel_id": serializer.String,
"project": fields.String, "project": fields.String,
"project_name": fields.String, "project_name": fields.String,
"project_fork": fields.String, "project_fork": fields.String,
"public_ip": fields.String, "public_ip": fields.String,
"private_ip": fields.String, "private_ip": fields.String,
# "host_id": fields.String, # "host_id": serializer.String,
"domain": fields.String, "domain": fields.String,
"port": fields.Integer, "port": fields.Integer,
"version": fields.Nested(VersionFields), "version": fields.Nested(VersionFields),
"status": fields.String, "status": fields.String,
"weight": fields.Integer, "weight": fields.Integer,
"slot": fields.Integer, "slot": fields.Integer,
# "tags": fields.List(fields.String), # "tags": serializer.List(serializer.String),
# "labels": fields.Raw, # "labels": serializer.Raw,
} }

View File

@ -4,7 +4,7 @@ from settings import common
from common.document import DocumentBase from common.document import DocumentBase
from common.validator import isalnum, is_hex_string from common.validator import isalnum, is_hex_string
from asset.models import Host from models.asset.models import Host
class Project(DocumentBase): class Project(DocumentBase):

0
src/service/__init__.py Normal file
View File