From 20215d4aaebc5105f56a4a411e2d4a1d437c8b90 Mon Sep 17 00:00:00 2001 From: chenzuoqing Date: Thu, 2 Dec 2021 16:54:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=A0=E9=81=93=E3=80=81=E5=8C=BA=E6=9C=8D?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=96=B0=E5=A2=9E=E6=98=AF=E5=90=A6=E4=B8=BA?= =?UTF-8?q?=E8=B7=A8=E6=9C=8D=E5=AD=97=E6=AE=B5=EF=BC=8C=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- settings/common.py | 10 ++++++++++ settings/dev.py | 5 ----- src/project/fields.py | 2 ++ src/project/models.py | 14 +++++++++++++- 4 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 settings/common.py diff --git a/settings/common.py b/settings/common.py new file mode 100644 index 0000000..f76d8d3 --- /dev/null +++ b/settings/common.py @@ -0,0 +1,10 @@ + +# API static token 允许请求的静态token +X_TOKEN_SET = ( + "51ab21fa323a11eca1af000c2993d583", # +) + +# 跨服spid集合 +CROSS_SPID_SET = ( + "000", "111", "222", "333", "444" +) diff --git a/settings/dev.py b/settings/dev.py index 3f83f97..5ff1965 100644 --- a/settings/dev.py +++ b/settings/dev.py @@ -13,11 +13,6 @@ MONGODB_SETTINGS = { 'host': 'mongodb://admin:111111@10.2.2.10:27017/ops_api?authSource=admin', } -# API static token 允许请求的静态token -X_TOKEN_SET = ( - "51ab21fa323a11eca1af000c2993d583", # -) - LOGGING = { 'version': 1, 'disable_existing_loggers': True, diff --git a/src/project/fields.py b/src/project/fields.py index 7c4f236..f41a397 100644 --- a/src/project/fields.py +++ b/src/project/fields.py @@ -44,6 +44,7 @@ ChannelFields = { "project": fields.Nested(ProjectSimpleField), "name": fields.String, "spid": fields.String, + "is_cross": fields.Boolean, "version": fields.Nested(VersionFields), "repository": fields.String, "branch": fields.String, @@ -79,6 +80,7 @@ AgentServerFields = { "num": fields.Integer, "spid": fields.String, "agent": fields.String, + "is_cross": fields.Boolean, # "channel_id": fields.String, "project": fields.String, "public_ip": fields.String, diff --git a/src/project/models.py b/src/project/models.py index 08b48b7..e5730a3 100644 --- a/src/project/models.py +++ b/src/project/models.py @@ -1,6 +1,7 @@ import mongoengine as mongo -from common.document import DocumentBase +from settings import common +from common.document import DocumentBase from common.validator import isalnum from asset.models import Host @@ -58,6 +59,11 @@ class Channel(DocumentBase): created = mongo.DateTimeField() + @property + def is_cross(self): + """渠道 spid 在 CROSS_SPID_SET,表示跨服""" + return self.spid in common.CROSS_SPID_SET + class Server(DocumentBase): """服务""" @@ -128,3 +134,9 @@ class Server(DocumentBase): if self.host: return self.host.id return "" + + @property + def is_cross(self): + if self.channel: + return self.channel.is_cross + return False