Plugin base classes: update method signatures & fix raise (#598)

This way IDEs can verify method overrides in subclasses, otherwise these
are flagged as erroneous.

Changed base classes to properly raise NotImplementedError; previously
they would cause "TypeError: exceptions must derive from BaseException"

Also fixed exception handling in sources.service.clean().
This commit is contained in:
Marti Raudsepp 2016-12-14 23:42:29 +02:00 committed by kevgliss
parent 1eb3d563c6
commit b327963925
7 changed files with 20 additions and 20 deletions

View File

@ -94,7 +94,7 @@ it can treat any issuer plugin as both a source of creating new certificates as
The `IssuerPlugin` exposes two functions:: The `IssuerPlugin` exposes two functions::
def create_certificate(self, options): def create_certificate(self, csr, issuer_options):
# requests.get('a third party') # requests.get('a third party')
Lemur will pass a dictionary of all possible options for certificate creation. Including a valid CSR, and the raw options associated with the request. Lemur will pass a dictionary of all possible options for certificate creation. Including a valid CSR, and the raw options associated with the request.
@ -145,7 +145,7 @@ in the plugins base class like so::
The DestinationPlugin requires only one function to be implemented:: The DestinationPlugin requires only one function to be implemented::
def upload(self, cert, private_key, cert_chain, options, **kwargs): def upload(self, name, body, private_key, cert_chain, options, **kwargs):
# request.post('a third party') # request.post('a third party')
Additionally the DestinationPlugin allows the plugin author to add additional options Additionally the DestinationPlugin allows the plugin author to add additional options
@ -202,7 +202,7 @@ The second is `ExpirationNotificationPlugin`, this object inherits from `Notific
You will most likely want to base your plugin on, if you want to add new channels for expiration notices (Slack, Hipcat, Jira, etc.). It adds default options that are required by You will most likely want to base your plugin on, if you want to add new channels for expiration notices (Slack, Hipcat, Jira, etc.). It adds default options that are required by
all expiration notifications (interval, unit). This interface expects for the child to define the following function:: all expiration notifications (interval, unit). This interface expects for the child to define the following function::
def send(self): def send(self, notification_type, message, targets, options, **kwargs):
# request.post("some alerting infrastructure") # request.post("some alerting infrastructure")
@ -225,7 +225,7 @@ The `SourcePlugin` object has one default option of `pollRate`. This controls th
The `SourcePlugin` object requires implementation of one function:: The `SourcePlugin` object requires implementation of one function::
def get_certificates(self, **kwargs): def get_certificates(self, options, **kwargs):
# request.get("some source of certificates") # request.get("some source of certificates")

View File

@ -13,5 +13,5 @@ class DestinationPlugin(Plugin):
type = 'destination' type = 'destination'
requires_key = True requires_key = True
def upload(self): def upload(self, name, body, private_key, cert_chain, options, **kwargs):
raise NotImplemented raise NotImplementedError

View File

@ -17,5 +17,5 @@ class ExportPlugin(Plugin):
type = 'export' type = 'export'
requires_key = True requires_key = True
def export(self): def export(self, body, chain, key, options, **kwargs):
raise NotImplemented raise NotImplementedError

View File

@ -16,8 +16,8 @@ class IssuerPlugin(Plugin):
""" """
type = 'issuer' type = 'issuer'
def create_certificate(self): def create_certificate(self, csr, issuer_options):
raise NotImplementedError raise NotImplementedError
def create_authority(self): def create_authority(self, options):
raise NotImplemented raise NotImplementedError

View File

@ -12,5 +12,5 @@ from lemur.plugins.base import Plugin
class MetricPlugin(Plugin): class MetricPlugin(Plugin):
type = 'metric' type = 'metric'
def submit(self, *args, **kwargs): def submit(self, metric_name, metric_type, metric_value, metric_tags=None, options=None):
raise NotImplemented raise NotImplementedError

View File

@ -22,14 +22,14 @@ class SourcePlugin(Plugin):
} }
] ]
def get_certificates(self): def get_certificates(self, options, **kwargs):
raise NotImplemented raise NotImplementedError
def get_endpoints(self): def get_endpoints(self, options, **kwargs):
raise NotImplemented raise NotImplementedError
def clean(self): def clean(self, options, **kwargs):
raise NotImplemented raise NotImplementedError
@property @property
def options(self): def options(self):

View File

@ -198,7 +198,7 @@ def clean(source):
try: try:
certificates = s.clean(source.options) certificates = s.clean(source.options)
except NotImplemented: except NotImplementedError:
current_app.logger.warning("Cannot clean source: {0}, source plugin does not implement 'clean()'".format( current_app.logger.warning("Cannot clean source: {0}, source plugin does not implement 'clean()'".format(
source.label source.label
)) ))