|
2 | 2 | # Copyright 2016 LasLabs Inc. |
3 | 3 | # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). |
4 | 4 |
|
5 | | -import json |
6 | | - |
7 | 5 | from odoo import api, fields, models |
8 | 6 |
|
9 | 7 |
|
@@ -45,30 +43,20 @@ class ClouderCertificateRequest(models.Model): |
45 | 43 | default='rsa', |
46 | 44 | selection=lambda s: s.env['clouder.key.abstract']._get_algorithms(), |
47 | 45 | ) |
48 | | - computed = fields.Serialized( |
49 | | - compute="_compute_computed", |
| 46 | + api_object = fields.Binary( |
| 47 | + compute="_compute_api_object", |
50 | 48 | ) |
51 | 49 |
|
52 | 50 | @api.multi |
53 | | - def _compute_computed(self): |
| 51 | + def _compute_api_object(self): |
54 | 52 | """ It computes the keys required for the JSON request """ |
55 | 53 | for record in self: |
56 | | - record.computed = { |
57 | | - 'CN': record.name, |
58 | | - 'names': [ |
59 | | - name.computed for name in record.subject_info_ids |
60 | | - ], |
61 | | - 'hosts': [ |
62 | | - '%s:%s' % (h.host, h.port) for h in record.host_ids |
63 | | - ], |
64 | | - 'key': { |
65 | | - 'algo': record.algorithm, |
66 | | - 'size': record.strength, |
67 | | - }, |
68 | | - } |
69 | | - |
70 | | - @api.multi |
71 | | - def to_json(self): |
72 | | - """ It returns the JSON representation of this object """ |
73 | | - self.ensure_one() |
74 | | - return json.dumps(self.computed) |
| 54 | + record.computed = self.cfssl.CertificateRequest( |
| 55 | + CN=record.name, |
| 56 | + names=record.subject_info_ids.mapped('computed'), |
| 57 | + hosts=record.host_ids.mapped('computed'), |
| 58 | + key=self.cfssl.ConfigKey( |
| 59 | + algorithm=record.algorithm, |
| 60 | + strength=record.strength, |
| 61 | + ), |
| 62 | + ) |
0 commit comments