抽出需要加密字段的视图
This commit is contained in:
parent
b1f7c6081b
commit
94aaa33611
|
@ -13,7 +13,6 @@ from common.permission import session_or_token_required
|
||||||
from common.utils import abort_response
|
from common.utils import abort_response
|
||||||
from controller.asset import parsers
|
from controller.asset import parsers
|
||||||
from common.crypto import quick_crypto
|
from common.crypto import quick_crypto
|
||||||
from settings.common import SECRET_KEY
|
|
||||||
|
|
||||||
logger = logging.getLogger("views")
|
logger = logging.getLogger("views")
|
||||||
|
|
||||||
|
@ -64,14 +63,6 @@ class MySQLInstanceViews(parsers.DatabaseServerParse, ListMixin, EncryptRequired
|
||||||
self.request_parse.add_argument("core", required=True, type=int, location='json')
|
self.request_parse.add_argument("core", required=True, type=int, location='json')
|
||||||
super(MySQLInstanceViews, self).__init__()
|
super(MySQLInstanceViews, self).__init__()
|
||||||
|
|
||||||
def pre_create(self, args):
|
|
||||||
"""加密保存密码,若提交了密码,必须加密存储"""
|
|
||||||
args = super().pre_create(args)
|
|
||||||
if "password" in args:
|
|
||||||
password = args.get("password")
|
|
||||||
args["password"] = quick_crypto(password)
|
|
||||||
return args
|
|
||||||
|
|
||||||
|
|
||||||
class MySQLInstanceDetail(parsers.DatabaseServerParse, RetrieveMixin, DestroyMixin, EncryptRequiredUpdateView):
|
class MySQLInstanceDetail(parsers.DatabaseServerParse, RetrieveMixin, DestroyMixin, EncryptRequiredUpdateView):
|
||||||
model = assetModel.MySQLInstance
|
model = assetModel.MySQLInstance
|
||||||
|
@ -94,15 +85,6 @@ class MySQLInstanceDetail(parsers.DatabaseServerParse, RetrieveMixin, DestroyMix
|
||||||
self.request_parse.add_argument("core", required=False, type=int, location='json')
|
self.request_parse.add_argument("core", required=False, type=int, location='json')
|
||||||
super(MySQLInstanceDetail, self).__init__()
|
super(MySQLInstanceDetail, self).__init__()
|
||||||
|
|
||||||
def pre_update(self, obj: assetModel.MySQLInstance, args: dict):
|
|
||||||
"""加密保存密码,若提交了密码,必须加密存储"""
|
|
||||||
data = super().pre_update(obj, args)
|
|
||||||
if "password" in data:
|
|
||||||
password = data.get("password")
|
|
||||||
if password != obj.password:
|
|
||||||
data["password"] = quick_crypto(password)
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
class DatabaseViews(parsers.DatabaseParse, Resource):
|
class DatabaseViews(parsers.DatabaseParse, Resource):
|
||||||
model = assetModel.DatabaseServer
|
model = assetModel.DatabaseServer
|
||||||
|
@ -220,14 +202,6 @@ class RedisInstanceViews(parsers.DatabaseServerParse, ListMixin, EncryptRequired
|
||||||
self.request_parse.add_argument("replicas", required=False, type=int, location='json')
|
self.request_parse.add_argument("replicas", required=False, type=int, location='json')
|
||||||
super(RedisInstanceViews, self).__init__()
|
super(RedisInstanceViews, self).__init__()
|
||||||
|
|
||||||
def pre_create(self, args):
|
|
||||||
"""加密保存密码,若提交了密码,必须加密存储"""
|
|
||||||
args = super().pre_create(args)
|
|
||||||
if "password" in args:
|
|
||||||
password = args.get("password")
|
|
||||||
args["password"] = quick_crypto(password)
|
|
||||||
return args
|
|
||||||
|
|
||||||
|
|
||||||
class RedisInstanceDetail(parsers.DatabaseServerParse, DestroyMixin, RetrieveMixin, EncryptRequiredUpdateView):
|
class RedisInstanceDetail(parsers.DatabaseServerParse, DestroyMixin, RetrieveMixin, EncryptRequiredUpdateView):
|
||||||
model = assetModel.RedisInstance
|
model = assetModel.RedisInstance
|
||||||
|
|
Loading…
Reference in New Issue