Source code for muffineer.api
"""
Let's get this party started!
"""
import falcon
import logging
from muffineer.config import YamlConfig
from muffineer.middlewares.json_handling import JSONTranslator, RequireJSON
from muffineer.resources.bitbucket import BitbucketEventResource
from muffineer.resources.gogs import GogsEventResource
logger = logging.getLogger(__name__)
# Falcon follows the REST architectural style, meaning (among
# other things) that you think in terms of resources and state
# transitions, which map to HTTP verbs.
[docs]class HealthCheck(object):
"""Create HealthCheck class."""
[docs] def on_get(self, req, resp):
"""Respond on GET request to map endpoint."""
resp.status = falcon.HTTP_200
logger.info('Finished operations on /health GET Request.')
[docs]def create(config=None):
config = YamlConfig(config)
# falcon.API instances are callable WSGI apps
app = falcon.API(middleware=[JSONTranslator(), RequireJSON()])
# Resources are represented by long-lived class instances
health_check = HealthCheck()
bitbucket_events = BitbucketEventResource()
gogs_events = GogsEventResource()
# things will handle all requests to the '/things' URL path
app.add_route('/health', health_check)
app.add_route('/bitbucket/events', bitbucket_events)
app.add_route('/gogs/events', gogs_events)
return app