2015-07-11 02:09:22 +02:00
|
|
|
"""
|
|
|
|
.. module: lemur.plugins.views
|
|
|
|
:platform: Unix
|
|
|
|
:synopsis: This module contains all of the accounts view code.
|
|
|
|
:copyright: (c) 2015 by Netflix Inc., see AUTHORS for more
|
|
|
|
:license: Apache, see LICENSE for more details.
|
|
|
|
.. moduleauthor:: Kevin Glisson <kglisson@netflix.com>
|
|
|
|
"""
|
|
|
|
from flask import Blueprint
|
2016-11-23 06:11:20 +01:00
|
|
|
from flask_restful import Api, reqparse
|
2015-07-11 02:09:22 +02:00
|
|
|
from lemur.auth.service import AuthenticatedResource
|
|
|
|
|
|
|
|
|
2016-05-13 23:35:38 +02:00
|
|
|
from lemur.schemas import plugins_output_schema, plugin_output_schema
|
|
|
|
from lemur.common.schema import validate_schema
|
2015-07-11 02:09:22 +02:00
|
|
|
from lemur.plugins.base import plugins
|
|
|
|
|
|
|
|
mod = Blueprint('plugins', __name__)
|
|
|
|
api = Api(mod)
|
|
|
|
|
|
|
|
|
|
|
|
class PluginsList(AuthenticatedResource):
|
|
|
|
""" Defines the 'plugins' endpoint """
|
|
|
|
def __init__(self):
|
|
|
|
self.reqparse = reqparse.RequestParser()
|
|
|
|
super(PluginsList, self).__init__()
|
|
|
|
|
2016-05-13 23:35:38 +02:00
|
|
|
@validate_schema(None, plugins_output_schema)
|
2015-07-11 02:09:22 +02:00
|
|
|
def get(self):
|
|
|
|
"""
|
|
|
|
.. http:get:: /plugins
|
|
|
|
|
|
|
|
The current plugin list
|
|
|
|
|
|
|
|
**Example request**:
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
|
|
GET /plugins HTTP/1.1
|
|
|
|
Host: example.com
|
|
|
|
Accept: application/json, text/javascript
|
|
|
|
|
|
|
|
**Example response**:
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
Vary: Accept
|
|
|
|
Content-Type: text/javascript
|
|
|
|
|
|
|
|
{
|
|
|
|
"items": [
|
|
|
|
{
|
|
|
|
"id": 2,
|
|
|
|
"accountNumber": 222222222,
|
|
|
|
"label": "account2",
|
2015-07-30 02:13:06 +02:00
|
|
|
"description": "this is a thing"
|
2015-07-11 02:09:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"accountNumber": 11111111111,
|
|
|
|
"label": "account1",
|
2015-07-30 02:13:06 +02:00
|
|
|
"description": "this is a thing"
|
2015-07-11 02:09:22 +02:00
|
|
|
},
|
|
|
|
]
|
|
|
|
"total": 2
|
|
|
|
}
|
|
|
|
|
|
|
|
:reqheader Authorization: OAuth token to authenticate
|
|
|
|
:statuscode 200: no error
|
|
|
|
"""
|
2015-07-30 02:13:06 +02:00
|
|
|
self.reqparse.add_argument('type', type=str, location='args')
|
|
|
|
args = self.reqparse.parse_args()
|
|
|
|
|
|
|
|
if args['type']:
|
|
|
|
return list(plugins.all(plugin_type=args['type']))
|
|
|
|
|
2015-10-02 22:46:13 +02:00
|
|
|
return list(plugins.all())
|
2015-07-11 02:09:22 +02:00
|
|
|
|
|
|
|
|
2015-07-30 02:13:06 +02:00
|
|
|
class Plugins(AuthenticatedResource):
|
2016-12-14 18:29:04 +01:00
|
|
|
""" Defines the 'plugins' endpoint """
|
2015-07-11 02:09:22 +02:00
|
|
|
def __init__(self):
|
2015-07-30 02:13:06 +02:00
|
|
|
super(Plugins, self).__init__()
|
2015-07-11 02:09:22 +02:00
|
|
|
|
2016-05-13 23:35:38 +02:00
|
|
|
@validate_schema(None, plugin_output_schema)
|
2015-07-30 02:13:06 +02:00
|
|
|
def get(self, name):
|
2015-07-11 02:09:22 +02:00
|
|
|
"""
|
2015-07-30 02:13:06 +02:00
|
|
|
.. http:get:: /plugins/<name>
|
2015-07-11 02:09:22 +02:00
|
|
|
|
|
|
|
The current plugin list
|
|
|
|
|
|
|
|
**Example request**:
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
2015-07-30 02:13:06 +02:00
|
|
|
GET /plugins HTTP/1.1
|
2015-07-11 02:09:22 +02:00
|
|
|
Host: example.com
|
|
|
|
Accept: application/json, text/javascript
|
|
|
|
|
|
|
|
**Example response**:
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
Vary: Accept
|
|
|
|
Content-Type: text/javascript
|
|
|
|
|
|
|
|
{
|
2015-07-30 02:13:06 +02:00
|
|
|
"accountNumber": 222222222,
|
|
|
|
"label": "account2",
|
|
|
|
"description": "this is a thing"
|
2015-07-11 02:09:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
:reqheader Authorization: OAuth token to authenticate
|
|
|
|
:statuscode 200: no error
|
|
|
|
"""
|
2015-07-30 02:13:06 +02:00
|
|
|
return plugins.get(name)
|
|
|
|
|
2015-07-11 02:09:22 +02:00
|
|
|
|
|
|
|
api.add_resource(PluginsList, '/plugins', endpoint='plugins')
|
2015-07-30 02:13:06 +02:00
|
|
|
api.add_resource(Plugins, '/plugins/<name>', endpoint='pluginName')
|