254 duplication certificate name (#319)

This commit is contained in:
kevgliss
2016-05-16 15:59:40 -07:00
parent 62b61ed980
commit 1763a1a717
11 changed files with 22 additions and 20 deletions

View File

@ -53,8 +53,6 @@ def create_name(issuer, not_before, not_after, subject, san):
not_after=not_after.strftime('%Y%m%d')
)
# NOTE we may want to give more control over naming
# aws doesn't allow special chars except '-'
disallowed_chars = ''.join(c for c in map(chr, range(256)) if not c.isalnum())
disallowed_chars = disallowed_chars.replace("-", "")
disallowed_chars = disallowed_chars.replace(".", "")
@ -64,7 +62,13 @@ def create_name(issuer, not_before, not_after, subject, san):
temp = temp.replace(c, "")
# white space is silly too
return temp.replace(" ", "-")
final = temp.replace(" ", "-")
# we don't want any overlapping certificate names
if Certificate.query.filter(Certificate.name == final).all():
final += '-1'
return final
def get_signing_algorithm(cert):

View File

@ -129,7 +129,7 @@ class CertificateUploadInputSchema(LemurInputSchema):
class CertificateExportInputSchema(LemurInputSchema):
export = fields.Nested(PluginInputSchema)
plugin = fields.Nested(PluginInputSchema)
certificate_input_schema = CertificateInputSchema()

View File

@ -675,7 +675,7 @@ class CertificateExport(AuthenticatedResource):
self.reqparse = reqparse.RequestParser()
super(CertificateExport, self).__init__()
@validate_schema(None, certificate_export_input_schema)
@validate_schema(certificate_export_input_schema, None)
def post(self, certificate_id, data=None):
"""
.. http:post:: /certificates/1/export
@ -743,11 +743,10 @@ class CertificateExport(AuthenticatedResource):
"""
cert = service.get(certificate_id)
role = role_service.get_by_name(cert.owner)
permission = UpdateCertificatePermission(certificate_id, getattr(role, 'name', None))
options = data['export']['plugin']['plugin_options']
plugin = data['export']['plugin']
options = data['plugin']['plugin_options']
plugin = data['plugin']['plugin_object']
if plugin.requires_key:
if permission.can():