secret_domain.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. from flask_marshmallow import Marshmallow
  2. from marshmallow import fields, post_load
  3. ma = Marshmallow()
  4. class GenLabelForm:
  5. """
  6. 生成密码标签请求体
  7. """
  8. def __init__(self, info):
  9. self.info = info
  10. class GenLabelResp:
  11. """
  12. 生成密码标签响应体
  13. """
  14. def __init__(self, code, msg, label, cert):
  15. self.code = code
  16. self.msg = msg
  17. self.label = label
  18. self.cert = cert
  19. class VerifyLabelForm:
  20. """
  21. 验证密码标签请求体
  22. """
  23. def __init__(self, label, info, cert):
  24. self.label = label
  25. self.info = info
  26. self.cert = cert
  27. class VerifyLabelResp:
  28. """
  29. 验证密码标签响应体
  30. """
  31. def __init__(self, code, msg):
  32. self.msg = msg
  33. self.code = code
  34. # 定义 Owner 类
  35. class Owner:
  36. def __init__(self, name, id):
  37. self.name = name
  38. self.id = id
  39. # 定义 Info 类
  40. class Info:
  41. def __init__(self, owner, model):
  42. self.owner = owner
  43. self.model = model
  44. # 定义 Model 类
  45. class Model:
  46. def __init__(self, name, id, version, date):
  47. self.name = name
  48. self.id = id
  49. self.version = version
  50. self.date = date
  51. # 定义 OwnerSchema
  52. class OwnerSchema(ma.Schema):
  53. name = fields.String()
  54. id = fields.String()
  55. @post_load
  56. def make_owner(self, object, **kwargs):
  57. return Owner(**object)
  58. # 定义 ModelSchema
  59. class ModelSchema(ma.Schema):
  60. name = fields.String()
  61. id = fields.String()
  62. version = fields.String()
  63. date = fields.String()
  64. @post_load
  65. def make_model(self, object, **kwargs):
  66. return Model(**object)
  67. # 定义 InfoSchema
  68. class InfoSchema(ma.Schema):
  69. owner = fields.Nested(OwnerSchema)
  70. model = fields.Nested(ModelSchema)
  71. @post_load
  72. def make_info(self, object, **kwargs):
  73. return Info(**object)
  74. class GenLabelFormSchema(ma.Schema):
  75. info = fields.Nested(InfoSchema)
  76. @post_load
  77. def make_label(self, object, **kwargs):
  78. return GenLabelForm(**object)
  79. class GenLabelRespSchema(ma.Schema):
  80. code = fields.Integer()
  81. msg = fields.String()
  82. label = fields.String()
  83. cert = fields.String()
  84. @post_load
  85. def make_label_resp(self, object, **kwargs):
  86. return GenLabelResp(**object)
  87. class VerifyLabelFormSchema(ma.Schema):
  88. label = fields.String()
  89. info = fields.String()
  90. cert = fields.String()
  91. @post_load
  92. def make_verify_label(self, object, **kwargs):
  93. return VerifyLabelForm(**object)
  94. class VerifyLabelRespSchema(ma.Schema):
  95. code = fields.Integer()
  96. msg = fields.String()
  97. @post_load
  98. def make_verify_label_resp(self, object, **kwargs):
  99. return VerifyLabelResp(**object)