Clean refactor (#635)
* Adding rotation to the UI. * Removing spinkit dependency. * refactoring source cleaning
This commit is contained in:
@ -16,14 +16,14 @@ from lemur.plugins.lemur_aws.sts import sts_client
|
||||
|
||||
def retry_throttled(exception):
|
||||
"""
|
||||
Determiens if this exception is due to throttling
|
||||
Determines if this exception is due to throttling
|
||||
:param exception:
|
||||
:return:
|
||||
"""
|
||||
if isinstance(exception, botocore.exceptions.ClientError):
|
||||
if exception.response['Error']['Code'] == 'LoadBalancerNotFound':
|
||||
return True
|
||||
return False
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def is_valid(listener_tuple):
|
||||
|
@ -6,7 +6,24 @@
|
||||
:license: Apache, see LICENSE for more details.
|
||||
.. moduleauthor:: Kevin Glisson <kglisson@netflix.com>
|
||||
"""
|
||||
import botocore
|
||||
|
||||
from retrying import retry
|
||||
|
||||
from lemur.plugins.lemur_aws.sts import assume_service
|
||||
from lemur.plugins.lemur_aws.sts import sts_client
|
||||
|
||||
|
||||
def retry_throttled(exception):
|
||||
"""
|
||||
Determines if this exception is due to throttling
|
||||
:param exception:
|
||||
:return:
|
||||
"""
|
||||
if isinstance(exception, botocore.exceptions.ClientError):
|
||||
if exception.response['Error']['Code'] == 'NoSuchEntity':
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def get_name_from_arn(arn):
|
||||
@ -33,15 +50,17 @@ def upload_cert(account_number, name, body, private_key, cert_chain=None):
|
||||
cert_chain=str(cert_chain))
|
||||
|
||||
|
||||
def delete_cert(account_number, cert_name):
|
||||
@sts_client('iam')
|
||||
@retry(retry_on_exception=retry_throttled, stop_max_attempt_number=7, wait_exponential_multiplier=1000)
|
||||
def delete_cert(cert_name, **kwargs):
|
||||
"""
|
||||
Delete a certificate from AWS
|
||||
|
||||
:param account_number:
|
||||
:param cert_name:
|
||||
:return:
|
||||
"""
|
||||
return assume_service(account_number, 'iam').delete_server_cert(cert_name)
|
||||
client = kwargs.pop('client')
|
||||
client.delete_server_certificate(ServerCertificateName=cert_name)
|
||||
|
||||
|
||||
def get_all_server_certs(account_number):
|
||||
|
@ -261,21 +261,9 @@ class AWSSourcePlugin(SourcePlugin):
|
||||
else:
|
||||
elb.attach_certificate(endpoint.name, endpoint.port, arn, account_number=account_number, region=region)
|
||||
|
||||
def clean(self, options, **kwargs):
|
||||
def clean(self, certificate, options, **kwargs):
|
||||
account_number = self.get_option('accountNumber', options)
|
||||
certificates = self.get_certificates(options)
|
||||
endpoints = self.get_endpoints(options)
|
||||
|
||||
orphaned = []
|
||||
for certificate in certificates:
|
||||
for endpoint in endpoints:
|
||||
if certificate['name'] == endpoint['certificate_name']:
|
||||
break
|
||||
else:
|
||||
orphaned.append(certificate['name'])
|
||||
iam.delete_cert(account_number, certificate)
|
||||
|
||||
return orphaned
|
||||
iam.delete_cert(certificate.name, account_number=account_number)
|
||||
|
||||
|
||||
class S3DestinationPlugin(DestinationPlugin):
|
||||
|
@ -56,6 +56,7 @@ def sts_client(service, service_type='client'):
|
||||
kwargs.pop('account_number'),
|
||||
current_app.config.get('LEMUR_INSTANCE_PROFILE', 'Lemur')
|
||||
)
|
||||
|
||||
# TODO add user specific information to RoleSessionName
|
||||
role = sts.assume_role(RoleArn=arn, RoleSessionName='lemur')
|
||||
|
||||
|
Reference in New Issue
Block a user