lemur/lemur/defaults/views.py

81 lines
2.3 KiB
Python
Raw Normal View History

2015-09-05 00:52:56 +02:00
"""
.. module: lemur.defaults.views
:copyright: (c) 2018 by Netflix Inc., see AUTHORS for more
2015-09-05 00:52:56 +02:00
:license: Apache, see LICENSE for more details.
"""
from flask import current_app, Blueprint
2016-11-23 06:11:20 +01:00
from flask_restful import Api
2015-09-05 00:52:56 +02:00
from lemur.common.schema import validate_schema
from lemur.authorities.service import get_by_name
2015-09-05 00:52:56 +02:00
from lemur.auth.service import AuthenticatedResource
from lemur.defaults.schemas import default_output_schema
2015-09-05 00:52:56 +02:00
2019-05-16 16:57:02 +02:00
mod = Blueprint("default", __name__)
2015-09-05 00:52:56 +02:00
api = Api(mod)
class LemurDefaults(AuthenticatedResource):
""" Defines the 'defaults' endpoint """
2019-05-16 16:57:02 +02:00
2015-09-05 00:52:56 +02:00
def __init__(self):
super(LemurDefaults)
@validate_schema(None, default_output_schema)
2015-09-05 00:52:56 +02:00
def get(self):
"""
.. http:get:: /defaults
Returns defaults needed to generate CSRs
**Example request**:
.. sourcecode:: http
GET /defaults 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
{
"country": "US",
"state": "CA",
"location": "Los Gatos",
"organization": "Netflix",
2018-04-12 00:56:00 +02:00
"organizationalUnit": "Operations",
"dnsProviders": [{"name": "test", ...}, {...}],
2015-09-05 00:52:56 +02:00
}
:reqheader Authorization: OAuth token to authenticate
:statuscode 200: no error
:statuscode 403: unauthenticated
"""
2019-05-16 16:57:02 +02:00
default_authority = get_by_name(
current_app.config.get("LEMUR_DEFAULT_AUTHORITY")
)
2015-09-05 00:52:56 +02:00
return dict(
2019-05-16 16:57:02 +02:00
country=current_app.config.get("LEMUR_DEFAULT_COUNTRY"),
state=current_app.config.get("LEMUR_DEFAULT_STATE"),
location=current_app.config.get("LEMUR_DEFAULT_LOCATION"),
organization=current_app.config.get("LEMUR_DEFAULT_ORGANIZATION"),
organizational_unit=current_app.config.get(
"LEMUR_DEFAULT_ORGANIZATIONAL_UNIT"
),
issuer_plugin=current_app.config.get("LEMUR_DEFAULT_ISSUER_PLUGIN"),
2018-04-12 00:56:00 +02:00
authority=default_authority,
2015-09-05 00:52:56 +02:00
)
2016-11-21 23:29:20 +01:00
2019-05-16 16:57:02 +02:00
api.add_resource(LemurDefaults, "/defaults", endpoint="default")