Replacement refactor. (#631)

* Deprecating replacement keyword.

* Def renaming.
This commit is contained in:
kevgliss
2016-12-26 11:09:50 -08:00
committed by GitHub
parent 46f8ebd136
commit ce75bba2c3
8 changed files with 47 additions and 37 deletions

View File

@ -115,7 +115,7 @@ class Certificate(db.Model):
self.notifications = kwargs.get('notifications', [])
self.description = kwargs.get('description')
self.roles = list(set(kwargs.get('roles', [])))
self.replaces = kwargs.get('replacements', [])
self.replaces = kwargs.get('replaces', [])
self.rotation = kwargs.get('rotation')
self.signing_algorithm = defaults.signing_algorithm(cert)
self.bits = defaults.bitstrength(cert)

View File

@ -54,7 +54,8 @@ class CertificateInputSchema(CertificateCreationSchema):
destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True)
notifications = fields.Nested(AssociatedNotificationSchema, missing=[], many=True)
replacements = fields.Nested(AssociatedCertificateSchema, missing=[], many=True)
replaces = fields.Nested(AssociatedCertificateSchema, missing=[], many=True)
replacements = fields.Nested(AssociatedCertificateSchema, missing=[], many=True) # deprecated
roles = fields.Nested(AssociatedRoleSchema, missing=[], many=True)
csr = fields.String(validate=validators.csr)
@ -76,18 +77,28 @@ class CertificateInputSchema(CertificateCreationSchema):
validators.dates(data)
@pre_load
def ensure_dates(self, data):
def load_data(self, data):
if data.get('replacements'):
data['replaces'] = data['replacements'] # TODO remove when field is deprecated
return missing.convert_validity_years(data)
class CertificateEditInputSchema(CertificateSchema):
notify = fields.Boolean()
owner = fields.String()
destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True)
notifications = fields.Nested(AssociatedNotificationSchema, missing=[], many=True)
replacements = fields.Nested(AssociatedCertificateSchema, missing=[], many=True)
replaces = fields.Nested(AssociatedCertificateSchema, missing=[], many=True)
replacements = fields.Nested(AssociatedCertificateSchema, missing=[], many=True) # deprecated
roles = fields.Nested(AssociatedRoleSchema, missing=[], many=True)
@pre_load
def load_data(self, data):
if data.get('replacements'):
data['replaces'] = data['replacements'] # TODO remove when field is deprecated
return data
@post_load
def enforce_notifications(self, data):
"""
@ -113,13 +124,13 @@ class CertificateNestedOutputSchema(LemurOutputSchema):
name = fields.String()
# Note aliasing is the first step in deprecating these fields.
cn = fields.String()
cn = fields.String() # deprecated
common_name = fields.String(attribute='cn')
not_after = fields.DateTime()
not_after = fields.DateTime() # deprecated
validity_end = ArrowDateTime(attribute='not_after')
not_before = fields.DateTime()
not_before = fields.DateTime() # deprecated
validity_start = ArrowDateTime(attribute='not_before')
owner = fields.Email()
@ -175,7 +186,7 @@ class CertificateOutputSchema(LemurOutputSchema):
authority = fields.Nested(AuthorityNestedOutputSchema)
roles = fields.Nested(RoleNestedOutputSchema, many=True)
endpoints = fields.Nested(EndpointNestedOutputSchema, many=True, missing=[])
replaced = fields.Nested(CertificateNestedOutputSchema, many=True)
replaced_by = fields.Nested(CertificateNestedOutputSchema, many=True, attribute='replaced')
class CertificateUploadInputSchema(CertificateCreationSchema):
@ -188,7 +199,7 @@ class CertificateUploadInputSchema(CertificateCreationSchema):
destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True)
notifications = fields.Nested(AssociatedNotificationSchema, missing=[], many=True)
replacements = fields.Nested(AssociatedCertificateSchema, missing=[], many=True)
replaces = fields.Nested(AssociatedCertificateSchema, missing=[], many=True)
roles = fields.Nested(AssociatedRoleSchema, missing=[], many=True)
@validates_schema
@ -209,7 +220,7 @@ class CertificateNotificationOutputSchema(LemurOutputSchema):
owner = fields.Email()
user = fields.Nested(UserNestedOutputSchema)
validity_end = ArrowDateTime(attribute='not_after')
replaced = fields.Nested(CertificateNestedOutputSchema, many=True)
replaced_by = fields.Nested(CertificateNestedOutputSchema, many=True, attribute='replaced')
endpoints = fields.Nested(EndpointNestedOutputSchema, many=True, missing=[])