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.notifications = kwargs.get('notifications', [])
|
||||||
self.description = kwargs.get('description')
|
self.description = kwargs.get('description')
|
||||||
self.roles = list(set(kwargs.get('roles', [])))
|
self.roles = list(set(kwargs.get('roles', [])))
|
||||||
self.replaces = kwargs.get('replacements', [])
|
self.replaces = kwargs.get('replaces', [])
|
||||||
self.rotation = kwargs.get('rotation')
|
self.rotation = kwargs.get('rotation')
|
||||||
self.signing_algorithm = defaults.signing_algorithm(cert)
|
self.signing_algorithm = defaults.signing_algorithm(cert)
|
||||||
self.bits = defaults.bitstrength(cert)
|
self.bits = defaults.bitstrength(cert)
|
||||||
|
|
|
@ -54,7 +54,8 @@ class CertificateInputSchema(CertificateCreationSchema):
|
||||||
|
|
||||||
destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True)
|
destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True)
|
||||||
notifications = fields.Nested(AssociatedNotificationSchema, 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)
|
roles = fields.Nested(AssociatedRoleSchema, missing=[], many=True)
|
||||||
|
|
||||||
csr = fields.String(validate=validators.csr)
|
csr = fields.String(validate=validators.csr)
|
||||||
|
@ -76,18 +77,28 @@ class CertificateInputSchema(CertificateCreationSchema):
|
||||||
validators.dates(data)
|
validators.dates(data)
|
||||||
|
|
||||||
@pre_load
|
@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)
|
return missing.convert_validity_years(data)
|
||||||
|
|
||||||
|
|
||||||
class CertificateEditInputSchema(CertificateSchema):
|
class CertificateEditInputSchema(CertificateSchema):
|
||||||
notify = fields.Boolean()
|
notify = fields.Boolean()
|
||||||
owner = fields.String()
|
owner = fields.String()
|
||||||
|
|
||||||
destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True)
|
destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True)
|
||||||
notifications = fields.Nested(AssociatedNotificationSchema, 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)
|
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
|
@post_load
|
||||||
def enforce_notifications(self, data):
|
def enforce_notifications(self, data):
|
||||||
"""
|
"""
|
||||||
|
@ -113,13 +124,13 @@ class CertificateNestedOutputSchema(LemurOutputSchema):
|
||||||
name = fields.String()
|
name = fields.String()
|
||||||
|
|
||||||
# Note aliasing is the first step in deprecating these fields.
|
# Note aliasing is the first step in deprecating these fields.
|
||||||
cn = fields.String()
|
cn = fields.String() # deprecated
|
||||||
common_name = fields.String(attribute='cn')
|
common_name = fields.String(attribute='cn')
|
||||||
|
|
||||||
not_after = fields.DateTime()
|
not_after = fields.DateTime() # deprecated
|
||||||
validity_end = ArrowDateTime(attribute='not_after')
|
validity_end = ArrowDateTime(attribute='not_after')
|
||||||
|
|
||||||
not_before = fields.DateTime()
|
not_before = fields.DateTime() # deprecated
|
||||||
validity_start = ArrowDateTime(attribute='not_before')
|
validity_start = ArrowDateTime(attribute='not_before')
|
||||||
|
|
||||||
owner = fields.Email()
|
owner = fields.Email()
|
||||||
|
@ -175,7 +186,7 @@ class CertificateOutputSchema(LemurOutputSchema):
|
||||||
authority = fields.Nested(AuthorityNestedOutputSchema)
|
authority = fields.Nested(AuthorityNestedOutputSchema)
|
||||||
roles = fields.Nested(RoleNestedOutputSchema, many=True)
|
roles = fields.Nested(RoleNestedOutputSchema, many=True)
|
||||||
endpoints = fields.Nested(EndpointNestedOutputSchema, many=True, missing=[])
|
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):
|
class CertificateUploadInputSchema(CertificateCreationSchema):
|
||||||
|
@ -188,7 +199,7 @@ class CertificateUploadInputSchema(CertificateCreationSchema):
|
||||||
|
|
||||||
destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True)
|
destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True)
|
||||||
notifications = fields.Nested(AssociatedNotificationSchema, 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)
|
roles = fields.Nested(AssociatedRoleSchema, missing=[], many=True)
|
||||||
|
|
||||||
@validates_schema
|
@validates_schema
|
||||||
|
@ -209,7 +220,7 @@ class CertificateNotificationOutputSchema(LemurOutputSchema):
|
||||||
owner = fields.Email()
|
owner = fields.Email()
|
||||||
user = fields.Nested(UserNestedOutputSchema)
|
user = fields.Nested(UserNestedOutputSchema)
|
||||||
validity_end = ArrowDateTime(attribute='not_after')
|
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=[])
|
endpoints = fields.Nested(EndpointNestedOutputSchema, many=True, missing=[])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -110,12 +110,12 @@
|
||||||
<td width="32px"></td>
|
<td width="32px"></td>
|
||||||
<td width="16px"></td>
|
<td width="16px"></td>
|
||||||
<td style="line-height:1.2">
|
<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>
|
<br>
|
||||||
<span style="font-family:Roboto-Regular,Helvetica,Arial,sans-serif;font-size:13px;color:#727272">
|
<span style="font-family:Roboto-Regular,Helvetica,Arial,sans-serif;font-size:13px;color:#727272">
|
||||||
<br>{{ certificate.replaced[0].owner }}
|
<br>{{ certificate.replacedBy[0].owner }}
|
||||||
<br>{{ certificate.replaced[0].validityEnd | time }}
|
<br>{{ certificate.replacedBy[0].validityEnd | time }}
|
||||||
<a href="https://{{ hostname }}/#/certificates/{{ certificate.replaced[0].name }}" target="_blank">Details</a>
|
<a href="https://{{ hostname }}/#/certificates/{{ certificate.replacedBy[0].name }}" target="_blank">Details</a>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -328,7 +328,6 @@ angular.module('lemur')
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
PluginService.getByType('destination').then(function (plugins) {
|
PluginService.getByType('destination').then(function (plugins) {
|
||||||
$scope.plugins = plugins;
|
$scope.plugins = plugins;
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,23 +4,23 @@
|
||||||
</label>
|
</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<div class="input-group">
|
<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"
|
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="Lemur will mark any certificates being replaced as 'inactive'"
|
||||||
uib-tooltip-trigger="focus" uib-tooltip-placement="top" typeahead-wait-ms="500">
|
uib-tooltip-trigger="focus" uib-tooltip-placement="top" typeahead-wait-ms="500">
|
||||||
<span class="input-group-btn">
|
<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">
|
<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.replacements.length || 0 }}</span>
|
<span class="badge">{{ certificate.replaces.length || 0 }}</span>
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr ng-repeat="replacement in certificate.replacements track by $index">
|
<tr ng-repeat="replaces in certificate.replaces track by $index">
|
||||||
<td><a class="btn btn-sm btn-info">{{ replacement.name }}</a></td>
|
<td><a class="btn btn-sm btn-info">{{ replaces.name }}</a></td>
|
||||||
<td><span class="text-muted">{{ replacement.description }}</span></td>
|
<td><span class="text-muted">{{ replaces.description }}</span></td>
|
||||||
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -81,15 +81,15 @@ angular.module('lemur')
|
||||||
removeDestination: function (index) {
|
removeDestination: function (index) {
|
||||||
this.destinations.splice(index, 1);
|
this.destinations.splice(index, 1);
|
||||||
},
|
},
|
||||||
attachReplacement: function (replacement) {
|
attachReplaces: function (replaces) {
|
||||||
this.selectedReplacement = null;
|
this.selectedReplaces = null;
|
||||||
if (this.replacements === undefined) {
|
if (this.replaces === undefined) {
|
||||||
this.replacements = [];
|
this.replaces = [];
|
||||||
}
|
}
|
||||||
this.replacements.push(replacement);
|
this.replaces.push(replaces);
|
||||||
},
|
},
|
||||||
removeReplacement: function (index) {
|
removeReplaces: function (index) {
|
||||||
this.replacements.splice(index, 1);
|
this.replaces.splice(index, 1);
|
||||||
},
|
},
|
||||||
attachNotification: function (notification) {
|
attachNotification: function (notification) {
|
||||||
this.selectedNotification = null;
|
this.selectedNotification = null;
|
||||||
|
@ -169,9 +169,9 @@ angular.module('lemur')
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
CertificateService.getReplacements = function (certificate) {
|
CertificateService.getReplaces = function (certificate) {
|
||||||
return certificate.getList('replacements').then(function (replacements) {
|
return certificate.getList('replaces').then(function (replaces) {
|
||||||
certificate.replacements = replacements;
|
certificate.replaces = replaces;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -170,9 +170,9 @@
|
||||||
<uib-tab>
|
<uib-tab>
|
||||||
<uib-tab-heading>Replaces</uib-tab-heading>
|
<uib-tab-heading>Replaces</uib-tab-heading>
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
<li class="list-group-item" ng-repeat="replacement in certificate.replaces">
|
<li class="list-group-item" ng-repeat="replaces in certificate.replaces">
|
||||||
<strong>{{ replacement.name }}</strong>
|
<strong>{{ replaces.name }}</strong>
|
||||||
<p>{{ replacement.description}}</p>
|
<p>{{ replaces.description}}</p>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</uib-tab>
|
</uib-tab>
|
||||||
|
|
|
@ -153,7 +153,7 @@ def test_certificate_input_schema(client, authority):
|
||||||
assert data['country'] == 'US'
|
assert data['country'] == 'US'
|
||||||
assert data['location'] == 'Los Gatos'
|
assert data['location'] == 'Los Gatos'
|
||||||
|
|
||||||
assert len(data.keys()) == 16
|
assert len(data.keys()) == 17
|
||||||
|
|
||||||
|
|
||||||
def test_certificate_input_with_extensions(client, authority):
|
def test_certificate_input_with_extensions(client, authority):
|
||||||
|
|
Loading…
Reference in New Issue