Replacement refactor. (#631)
* Deprecating replacement keyword. * Def renaming.
This commit is contained in:
parent
46f8ebd136
commit
ce75bba2c3
|
@ -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)
|
||||
|
|
|
@ -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=[])
|
||||
|
||||
|
||||
|
|
|
@ -110,12 +110,12 @@
|
|||
<td width="32px"></td>
|
||||
<td width="16px"></td>
|
||||
<td style="line-height:1.2">
|
||||
<span style="font-family:Roboto-Regular,Helvetica,Arial,sans-serif;font-size:20px;color:#202020">{{ certificate.replaced.name }}</span>
|
||||
<span style="font-family:Roboto-Regular,Helvetica,Arial,sans-serif;font-size:20px;color:#202020">{{ certificate.replacedBy[0].name }}</span>
|
||||
<br>
|
||||
<span style="font-family:Roboto-Regular,Helvetica,Arial,sans-serif;font-size:13px;color:#727272">
|
||||
<br>{{ certificate.replaced[0].owner }}
|
||||
<br>{{ certificate.replaced[0].validityEnd | time }}
|
||||
<a href="https://{{ hostname }}/#/certificates/{{ certificate.replaced[0].name }}" target="_blank">Details</a>
|
||||
<br>{{ certificate.replacedBy[0].owner }}
|
||||
<br>{{ certificate.replacedBy[0].validityEnd | time }}
|
||||
<a href="https://{{ hostname }}/#/certificates/{{ certificate.replacedBy[0].name }}" target="_blank">Details</a>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -328,7 +328,6 @@ angular.module('lemur')
|
|||
}
|
||||
];
|
||||
|
||||
|
||||
PluginService.getByType('destination').then(function (plugins) {
|
||||
$scope.plugins = plugins;
|
||||
});
|
||||
|
|
|
@ -4,23 +4,23 @@
|
|||
</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="input-group">
|
||||
<input type="text" ng-model="certificate.selectedReplacement" placeholder="Certificate123..."
|
||||
<input type="text" ng-model="certificate.selectedReplaces" placeholder="Certificate123..."
|
||||
uib-typeahead="certificate.name for certificate in certificateService.findCertificatesByName($viewValue)" typeahead-loading="loadingCertificates"
|
||||
class="form-control input-md" typeahead-on-select="certificate.attachReplacement($item)"
|
||||
class="form-control input-md" typeahead-on-select="certificate.attachReplaces($item)"
|
||||
uib-tooltip="Lemur will mark any certificates being replaced as 'inactive'"
|
||||
uib-tooltip-trigger="focus" uib-tooltip-placement="top" typeahead-wait-ms="500">
|
||||
<span class="input-group-btn">
|
||||
<button ng-model="replacements.show" class="btn btn-md btn-default" uib-btn-checkbox btn-checkbox-true="1" btn-checkbox-false="0">
|
||||
<span class="badge">{{ certificate.replacements.length || 0 }}</span>
|
||||
<button ng-model="replaces.show" class="btn btn-md btn-default" uib-btn-checkbox btn-checkbox-true="1" btn-checkbox-false="0">
|
||||
<span class="badge">{{ certificate.replaces.length || 0 }}</span>
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
<table class="table">
|
||||
<tr ng-repeat="replacement in certificate.replacements track by $index">
|
||||
<td><a class="btn btn-sm btn-info">{{ replacement.name }}</a></td>
|
||||
<td><span class="text-muted">{{ replacement.description }}</span></td>
|
||||
<tr ng-repeat="replaces in certificate.replaces track by $index">
|
||||
<td><a class="btn btn-sm btn-info">{{ replaces.name }}</a></td>
|
||||
<td><span class="text-muted">{{ replaces.description }}</span></td>
|
||||
<td>
|
||||
<button type="button" ng-click="certificate.removeReplacement($index)" class="btn btn-danger btn-sm pull-right">Remove</button>
|
||||
<button type="button" ng-click="certificate.removeReplaces($index)" class="btn btn-danger btn-sm pull-right">Remove</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -81,15 +81,15 @@ angular.module('lemur')
|
|||
removeDestination: function (index) {
|
||||
this.destinations.splice(index, 1);
|
||||
},
|
||||
attachReplacement: function (replacement) {
|
||||
this.selectedReplacement = null;
|
||||
if (this.replacements === undefined) {
|
||||
this.replacements = [];
|
||||
attachReplaces: function (replaces) {
|
||||
this.selectedReplaces = null;
|
||||
if (this.replaces === undefined) {
|
||||
this.replaces = [];
|
||||
}
|
||||
this.replacements.push(replacement);
|
||||
this.replaces.push(replaces);
|
||||
},
|
||||
removeReplacement: function (index) {
|
||||
this.replacements.splice(index, 1);
|
||||
removeReplaces: function (index) {
|
||||
this.replaces.splice(index, 1);
|
||||
},
|
||||
attachNotification: function (notification) {
|
||||
this.selectedNotification = null;
|
||||
|
@ -169,9 +169,9 @@ angular.module('lemur')
|
|||
});
|
||||
};
|
||||
|
||||
CertificateService.getReplacements = function (certificate) {
|
||||
return certificate.getList('replacements').then(function (replacements) {
|
||||
certificate.replacements = replacements;
|
||||
CertificateService.getReplaces = function (certificate) {
|
||||
return certificate.getList('replaces').then(function (replaces) {
|
||||
certificate.replaces = replaces;
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -170,9 +170,9 @@
|
|||
<uib-tab>
|
||||
<uib-tab-heading>Replaces</uib-tab-heading>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item" ng-repeat="replacement in certificate.replaces">
|
||||
<strong>{{ replacement.name }}</strong>
|
||||
<p>{{ replacement.description}}</p>
|
||||
<li class="list-group-item" ng-repeat="replaces in certificate.replaces">
|
||||
<strong>{{ replaces.name }}</strong>
|
||||
<p>{{ replaces.description}}</p>
|
||||
</li>
|
||||
</ul>
|
||||
</uib-tab>
|
||||
|
|
|
@ -153,7 +153,7 @@ def test_certificate_input_schema(client, authority):
|
|||
assert data['country'] == 'US'
|
||||
assert data['location'] == 'Los Gatos'
|
||||
|
||||
assert len(data.keys()) == 16
|
||||
assert len(data.keys()) == 17
|
||||
|
||||
|
||||
def test_certificate_input_with_extensions(client, authority):
|
||||
|
|
Loading…
Reference in New Issue