From 5cbf5365c52d39927f7fdaf1a0084d3ed0452b77 Mon Sep 17 00:00:00 2001 From: Charles Hendrie Date: Sat, 8 Oct 2016 19:06:20 -0500 Subject: [PATCH] Active S3 destination plugin (#433) * Activate the AWS S3 destination plugin Add the AWS S3 destination plugin to the list of available Lemur plugins. Update the S3 destination plugin's "accountNumber" option to be of type 'str' to handle account numbers starting with zeros. Update Lemur's utils for parsing certificates to correctly encode the X509 certificates before loading for python3. * Add S3 destination plugin test Added simple test to verify S3 destination plugin is available. --- lemur/common/utils.py | 2 +- lemur/plugins/lemur_aws/plugin.py | 4 ++-- lemur/plugins/lemur_aws/tests/test_plugin.py | 6 ++++++ setup.py | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lemur/common/utils.py b/lemur/common/utils.py index 6934b9a5..dae5e1f9 100644 --- a/lemur/common/utils.py +++ b/lemur/common/utils.py @@ -40,4 +40,4 @@ def parse_certificate(body): if isinstance(body, bytes): return x509.load_pem_x509_certificate(body, default_backend()) return x509.load_pem_x509_certificate(bytes(body, 'utf8'), default_backend()) - return x509.load_pem_x509_certificate(str(body), default_backend()) + return x509.load_pem_x509_certificate(body.encode('utf-8'), default_backend()) diff --git a/lemur/plugins/lemur_aws/plugin.py b/lemur/plugins/lemur_aws/plugin.py index d5c24f15..dfee63e6 100644 --- a/lemur/plugins/lemur_aws/plugin.py +++ b/lemur/plugins/lemur_aws/plugin.py @@ -210,7 +210,7 @@ class S3DestinationPlugin(DestinationPlugin): }, { 'name': 'accountNumber', - 'type': 'int', + 'type': 'str', 'required': True, 'validation': '/^[0-9]{12,12}$/', 'helpMessage': 'A valid AWS account number with permission to access S3', @@ -257,7 +257,7 @@ class S3DestinationPlugin(DestinationPlugin): super(S3DestinationPlugin, self).__init__(*args, **kwargs) def upload(self, name, body, private_key, cert_chain, options, **kwargs): - account_number = self.get_option('accountId', options) + account_number = self.get_option('accountNumber', options) encrypt = self.get_option('encrypt', options) bucket = self.get_option('bucket', options) key = self.get_option('key', options) diff --git a/lemur/plugins/lemur_aws/tests/test_plugin.py b/lemur/plugins/lemur_aws/tests/test_plugin.py index e69de29b..95e4c9a4 100644 --- a/lemur/plugins/lemur_aws/tests/test_plugin.py +++ b/lemur/plugins/lemur_aws/tests/test_plugin.py @@ -0,0 +1,6 @@ + +def test_get_certificates(app): + from lemur.plugins.base import plugins + + p = plugins.get('aws-s3') + assert p diff --git a/setup.py b/setup.py index b1ee874f..031e302c 100644 --- a/setup.py +++ b/setup.py @@ -174,6 +174,7 @@ setup( 'acme_issuer = lemur.plugins.lemur_acme.plugin:ACMEIssuerPlugin', 'aws_destination = lemur.plugins.lemur_aws.plugin:AWSDestinationPlugin', 'aws_source = lemur.plugins.lemur_aws.plugin:AWSSourcePlugin', + 'aws_s3 = lemur.plugins.lemur_aws.plugin:S3DestinationPlugin', 'email_notification = lemur.plugins.lemur_email.plugin:EmailNotificationPlugin', 'slack_notification = lemur.plugins.lemur_slack.plugin:SlackNotificationPlugin', 'java_truststore_export = lemur.plugins.lemur_java.plugin:JavaTruststoreExportPlugin',