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