CanarieAPI documentation¶
CanarieAPI: Self describing REST service for Canarie registry¶
Provides documentation details, status monitoring and statistics reporting of services and platforms within the registered configuration.
Docker image available on DockerHub at pavics/canarieapi
.
Refer to installation and usage to run the application locally.
User’s guide¶
Usage¶
Create a custom canarieapi/configuration.py
file similar to canarieapi/default_configuration.py
and define
the environment variable CANARIE_API_CONFIG_FN
pointing to it in order to use your desired configurations.
Run the CanarieAPI
using gunicorn
:
cd <CanarieAPI-root>/canarieapi
../bin/gunicorn -b 0.0.0.0:2000 --workers 1 --log-level=DEBUG --timeout 30 -k gevent wsgi
Package information¶
Installation¶
At the command line:
conda activate canarieapi # or any other means of environment activation of your choice
make install
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at francois-xavier.derue@crim.ca.
If you are reporting a bug, please include:
Your operating system name and version.
Any details about your local setup that might be helpful in troubleshooting.
Detailed steps to reproduce the bug.
Write Documentation¶
Magpie could always use more documentation, whether as part of the official Magpie docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at francois-xavier.derue@crim.ca.
If you are proposing a feature:
Explain in detail how it would work.
Keep the scope as narrow as possible, to make it easier to implement.
Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up CanarieAPI for local development.
Clone the CanarieAPI repo from GitHub.
git clone https://github.com/Ouranosinc/CanarieAPI
Install your local copy and use a virtualenv. Assuming you have virtualenv installed, this is how you set up your fork for local development:
$ cd CanarieAPI/ $ virtualenv -p python 3.5 env $ source env/bin/activate.csh $ python setup.py develop
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 CanarieAPI tests $ python setup.py test $ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git commit -m "Your detailed description of your changes."
Submit a pull request to the author.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
The pull request should include tests.
If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
The tests should work for the specifid version of Python for this project.
Credits¶
Development Lead¶
David Byrns <david.byrns@crim.ca>
Contributors¶
Francis Charette-Migneault <francis.charette-migneault@crim.ca>
API Reference¶
This page contains auto-generated API reference documentation 1.
canarieapi
¶
Submodules¶
canarieapi.__meta__
¶canarieapi.api
¶This module defines the generic REST API for platforms and services as defined by the CANARIE API specification.
|
Generate error response for raised exceptions. |
|
|
|
|
Handle HTML errors from an external response. |
|
|
Info route required by CANARIE. |
|
Obtain all monitoring statuses for the requested service or platform. |
|
Stats route required by CANARIE. |
|
Extra route to know service status. |
|
#Handle simple requests required by CANARIE. |
|
Disconnect database. |
- canarieapi.api.handle_exceptions(exception_instance: Exception) flask.typing.ResponseReturnValue [source]¶
Generate error response for raised exceptions.
- Parameters
exception_instance – Exception instance.
- canarieapi.api.extern_html_error_handler(status_code_str: str) flask.typing.ResponseReturnValue [source]¶
Handle HTML errors from an external response.
Handle errors that occur externally provided that Apache is configured so that it uses this route for handling errors.
For this add this line for each handled HTML errors in the Apache configuration:
ErrorDocument 400 <Rest root>/400
- canarieapi.api.information(route_name: str, api_type: canarieapi.utility_rest.APIType) flask.typing.ResponseReturnValue [source]¶
Info route required by CANARIE.
- canarieapi.api.get_monitoring_statuses(route_name: str) Dict[str, StatusInfo] [source]¶
Obtain all monitoring statuses for the requested service or platform.
- canarieapi.api.stats(route_name: str, api_type: canarieapi.utility_rest.APIType) flask.typing.ResponseReturnValue [source]¶
Stats route required by CANARIE.
- canarieapi.api.status(route_name: str, api_type: canarieapi.utility_rest.APIType) flask.typing.ResponseReturnValue [source]¶
Extra route to know service status.
canarieapi.app_object
¶canarieapi.default_configuration
¶To have the programs in the package override the values with the values found in this file, you need to set the environment variable named “CANARIE_API_CONFIG_FN” to the path of your own copy before launching the program.
canarieapi.logparser
¶
|
|
|
|
|
|
|
canarieapi.monitoring
¶
|
|
|
|
|
- canarieapi.monitoring.check_service(request: RequestConfig, response: ResponseConfig) Tuple[canarieapi.status.Status, str] [source]¶
canarieapi.reverse_proxied
¶This module implements a middleware that makes the Flask application work seamlessly behind a reverse proxy.
Class which implements a middleware so |
canarieapi.schema
¶
|
canarieapi.status
¶canarieapi.utility_rest
¶This module is a collection of utility functions used mainly by the rest_route module and which are placed here to keep the rest_route module as clean as possible.
Matches one of the items provided. |
|
Check if the request type is of type JSON considering both the |
|
Set the default response Media-Type, with fallback to JSON. |
|
Return the config for the particular service/platform associated with the given route name. |
|
Check if the route name is a value amongst known services/platforms in the configuration. |
|
Get the API title to be shown in rendered html page. |
Provide a valid response for the CANARIE API request based on the service route. |
|
|
Make an error response based on the request type and given information. |
|
Get a connection to an existing database. |
|
Initialize a database from a schema. |
- canarieapi.utility_rest.request_wants_json() bool [source]¶
Check if the request type is of type JSON considering both the
Accept
header andf
query parameter.The default Media-Type
*/*
will be interpreted as JSON. Omitting a preferred type entirely will also default to JSON.
- canarieapi.utility_rest.set_html_as_default_response() None [source]¶
Set the default response Media-Type, with fallback to JSON.
By default, if the accepted mimetypes contains /, JSON format will be used. By calling this function, the / mimetype will be changed explicitly into text/html so that it becomes the mimetype used by default. This is useful for automatically rendering HTML by web browsers that do not provide explicitly the desired mimetype.
- canarieapi.utility_rest.get_config(route_name: str, api_type: APIType) JSON [source]¶
Return the config for the particular service/platform associated with the given route name.
- Parameters
route_name – Route name of the service/platform coming from the URL e.g. : [‘pavics’, ‘node’, ‘bias’, etc.]
api_type – Api type of the route which must be one of platform or service
- Raises
Exception if the route is unknown
- canarieapi.utility_rest.validate_route(route_name: str, api_type: APIType) None [source]¶
Check if the route name is a value amongst known services/platforms in the configuration.
- Parameters
route_name – Route name of the service/platform coming from the URL e.g. : [‘pavics’, ‘node’, ‘bias’, etc.]
api_type – Api type of the route which must be one of platform or service
- Raises
Exception if the route is unknown
- canarieapi.utility_rest.get_api_title(route_name: str, api_type: APIType) str [source]¶
Get the API title to be shown in rendered html page.
- Parameters
route_name – Route name of the service/platform coming from the URL e.g. : [‘pavics’, ‘node’, ‘bias’, etc.]
api_type – Api type of the route which must be one of platform or service
- Returns
An API title
- canarieapi.utility_rest.get_canarie_api_response(route_name: str, api_type: APIType, api_request: str) flask.typing.ResponseReturnValue [source]¶
Provide a valid response for the CANARIE API request based on the service route.
- Parameters
route_name – Route name of the service/platform coming from the URL e.g. : [‘pavics’, ‘node’, ‘bias’, etc.]
api_type – Api type of the route which must be one of platform or service
api_request – The request specified in the URL
- Returns
A valid HTML response
- canarieapi.utility_rest.make_error_response(http_status: Optional[int] = None, http_status_response: Optional[str] = None) Tuple[Union[flask.Response, str], int] [source]¶
Make an error response based on the request type and given information.
- Parameters
http_status – HTTP status
http_status_response – Standard message associated with a status code. Obtained via
http.client.responses
if not provided.
- canarieapi.utility_rest.get_db() sqlite3.Connection [source]¶
Get a connection to an existing database.
If the database does not exist, create a connection to local sqlite3 file. If the local sqlite3 file doesn’t exist, initialize it using a schema.
Stores the established connection in the application’s global context to reuse it whenever required.
- canarieapi.utility_rest.init_db(database: sqlite3.Connection) None [source]¶
Initialize a database from a schema.
- class canarieapi.utility_rest.AnyIntConverter(mapping: werkzeug.routing.Map, *items: Union[int, str])[source]¶
Bases:
werkzeug.routing.BaseConverter
Matches one of the items provided.
Items must be integer and comma separated with a space to avoid confusion with floating point value in the parser.
For example:
1, 2, 3
And not:
1,2,3
Since it would parse as float 1,2 and 3.
canarieapi.wsgi
¶- 1
Created with sphinx-autoapi