2015-06-22 22:47:27 +02:00
|
|
|
"""
|
|
|
|
.. module: lemur.domains.views
|
|
|
|
:platform: Unix
|
2018-05-29 19:18:16 +02:00
|
|
|
:copyright: (c) 2018 by Netflix Inc., see AUTHORS for more
|
2015-06-22 22:47:27 +02:00
|
|
|
: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 reqparse, Api
|
2015-06-22 22:47:27 +02:00
|
|
|
|
|
|
|
from lemur.domains import service
|
|
|
|
from lemur.auth.service import AuthenticatedResource
|
2015-12-31 00:11:08 +01:00
|
|
|
from lemur.auth.permissions import SensitiveDomainPermission
|
2015-06-22 22:47:27 +02:00
|
|
|
|
2016-05-16 20:09:50 +02:00
|
|
|
from lemur.common.schema import validate_schema
|
|
|
|
from lemur.common.utils import paginated_parser
|
2015-06-22 22:47:27 +02:00
|
|
|
|
2019-05-16 16:57:02 +02:00
|
|
|
from lemur.domains.schemas import (
|
|
|
|
domain_input_schema,
|
|
|
|
domain_output_schema,
|
|
|
|
domains_output_schema,
|
|
|
|
)
|
2015-06-22 22:47:27 +02:00
|
|
|
|
2019-05-16 16:57:02 +02:00
|
|
|
mod = Blueprint("domains", __name__)
|
2015-06-22 22:47:27 +02:00
|
|
|
api = Api(mod)
|
|
|
|
|
|
|
|
|
|
|
|
class DomainsList(AuthenticatedResource):
|
|
|
|
""" Defines the 'domains' endpoint """
|
2019-05-16 16:57:02 +02:00
|
|
|
|
2015-06-22 22:47:27 +02:00
|
|
|
def __init__(self):
|
|
|
|
super(DomainsList, self).__init__()
|
|
|
|
|
2016-05-16 20:09:50 +02:00
|
|
|
@validate_schema(None, domains_output_schema)
|
2015-06-22 22:47:27 +02:00
|
|
|
def get(self):
|
|
|
|
"""
|
|
|
|
.. http:get:: /domains
|
|
|
|
|
|
|
|
The current domain list
|
|
|
|
|
|
|
|
**Example request**:
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
|
|
GET /domains 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": 1,
|
|
|
|
"name": "www.example.com",
|
2015-12-31 00:11:08 +01:00
|
|
|
"sensitive": false
|
2015-06-22 22:47:27 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 2,
|
|
|
|
"name": "www.example2.com",
|
2015-12-31 00:11:08 +01:00
|
|
|
"sensitive": false
|
2015-06-22 22:47:27 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
"total": 2
|
|
|
|
}
|
|
|
|
|
|
|
|
:query sortBy: field to sort on
|
2016-12-14 18:29:04 +01:00
|
|
|
:query sortDir: asc or desc
|
2016-01-29 20:47:16 +01:00
|
|
|
:query page: int default is 1
|
|
|
|
:query filter: key value pair format is k;v
|
2016-06-03 17:28:09 +02:00
|
|
|
:query count: count number. default is 10
|
2015-06-22 22:47:27 +02:00
|
|
|
:reqheader Authorization: OAuth token to authenticate
|
|
|
|
:statuscode 200: no error
|
|
|
|
:statuscode 403: unauthenticated
|
|
|
|
"""
|
|
|
|
parser = paginated_parser.copy()
|
|
|
|
args = parser.parse_args()
|
|
|
|
return service.render(args)
|
|
|
|
|
2016-05-16 20:09:50 +02:00
|
|
|
@validate_schema(domain_input_schema, domain_output_schema)
|
|
|
|
def post(self, data=None):
|
2015-12-31 00:11:08 +01:00
|
|
|
"""
|
|
|
|
.. http:post:: /domains
|
|
|
|
|
|
|
|
The current domain list
|
|
|
|
|
|
|
|
**Example request**:
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
|
|
GET /domains HTTP/1.1
|
|
|
|
Host: example.com
|
|
|
|
Accept: application/json, text/javascript
|
|
|
|
|
|
|
|
{
|
|
|
|
"name": "www.example.com",
|
|
|
|
"sensitive": false
|
|
|
|
}
|
|
|
|
|
|
|
|
**Example response**:
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
Vary: Accept
|
|
|
|
Content-Type: text/javascript
|
|
|
|
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"name": "www.example.com",
|
|
|
|
"sensitive": false
|
|
|
|
}
|
|
|
|
|
|
|
|
:query sortBy: field to sort on
|
2016-12-14 18:29:04 +01:00
|
|
|
:query sortDir: asc or desc
|
2016-01-29 20:47:16 +01:00
|
|
|
:query page: int default is 1
|
|
|
|
:query filter: key value pair format is k;v
|
2016-06-03 17:28:09 +02:00
|
|
|
:query count: count number default is 10
|
2015-12-31 00:11:08 +01:00
|
|
|
:reqheader Authorization: OAuth token to authenticate
|
|
|
|
:statuscode 200: no error
|
|
|
|
:statuscode 403: unauthenticated
|
|
|
|
"""
|
2019-05-16 16:57:02 +02:00
|
|
|
return service.create(data["name"], data["sensitive"])
|
2015-12-31 00:11:08 +01:00
|
|
|
|
2015-06-22 22:47:27 +02:00
|
|
|
|
|
|
|
class Domains(AuthenticatedResource):
|
|
|
|
def __init__(self):
|
|
|
|
self.reqparse = reqparse.RequestParser()
|
|
|
|
super(Domains, self).__init__()
|
|
|
|
|
2016-05-16 20:09:50 +02:00
|
|
|
@validate_schema(None, domain_output_schema)
|
2015-06-22 22:47:27 +02:00
|
|
|
def get(self, domain_id):
|
|
|
|
"""
|
|
|
|
.. http:get:: /domains/1
|
|
|
|
|
|
|
|
Fetch one domain
|
|
|
|
|
|
|
|
**Example request**:
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
|
|
GET /domains 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
|
|
|
|
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"name": "www.example.com",
|
2015-12-31 00:11:08 +01:00
|
|
|
"sensitive": false
|
2015-06-22 22:47:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
:reqheader Authorization: OAuth token to authenticate
|
|
|
|
:statuscode 200: no error
|
|
|
|
:statuscode 403: unauthenticated
|
|
|
|
"""
|
|
|
|
return service.get(domain_id)
|
|
|
|
|
2016-05-16 20:09:50 +02:00
|
|
|
@validate_schema(domain_input_schema, domain_output_schema)
|
|
|
|
def put(self, domain_id, data=None):
|
2015-12-31 00:11:08 +01:00
|
|
|
"""
|
|
|
|
.. http:get:: /domains/1
|
|
|
|
|
|
|
|
update one domain
|
|
|
|
|
|
|
|
**Example request**:
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
|
|
GET /domains HTTP/1.1
|
|
|
|
Host: example.com
|
|
|
|
Accept: application/json, text/javascript
|
|
|
|
|
|
|
|
{
|
|
|
|
"name": "www.example.com",
|
|
|
|
"sensitive": false
|
|
|
|
}
|
|
|
|
|
|
|
|
**Example response**:
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
Vary: Accept
|
|
|
|
Content-Type: text/javascript
|
|
|
|
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"name": "www.example.com",
|
|
|
|
"sensitive": false
|
|
|
|
}
|
|
|
|
|
|
|
|
:reqheader Authorization: OAuth token to authenticate
|
|
|
|
:statuscode 200: no error
|
|
|
|
:statuscode 403: unauthenticated
|
|
|
|
"""
|
|
|
|
if SensitiveDomainPermission().can():
|
2019-05-16 16:57:02 +02:00
|
|
|
return service.update(domain_id, data["name"], data["sensitive"])
|
2015-12-31 00:11:08 +01:00
|
|
|
|
2019-05-16 16:57:02 +02:00
|
|
|
return dict(message="You are not authorized to modify this domain"), 403
|
2015-12-31 00:11:08 +01:00
|
|
|
|
2015-06-22 22:47:27 +02:00
|
|
|
|
|
|
|
class CertificateDomains(AuthenticatedResource):
|
|
|
|
""" Defines the 'domains' endpoint """
|
2019-05-16 16:57:02 +02:00
|
|
|
|
2015-06-22 22:47:27 +02:00
|
|
|
def __init__(self):
|
|
|
|
super(CertificateDomains, self).__init__()
|
|
|
|
|
2016-05-16 20:09:50 +02:00
|
|
|
@validate_schema(None, domains_output_schema)
|
2015-06-22 22:47:27 +02:00
|
|
|
def get(self, certificate_id):
|
|
|
|
"""
|
|
|
|
.. http:get:: /certificates/1/domains
|
|
|
|
|
|
|
|
The current domain list
|
|
|
|
|
|
|
|
**Example request**:
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
|
|
GET /domains 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": 1,
|
|
|
|
"name": "www.example.com",
|
2015-12-31 00:11:08 +01:00
|
|
|
"sensitive": false
|
2015-06-22 22:47:27 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 2,
|
|
|
|
"name": "www.example2.com",
|
2015-12-31 00:11:08 +01:00
|
|
|
"sensitive": false
|
2015-06-22 22:47:27 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
"total": 2
|
|
|
|
}
|
|
|
|
|
|
|
|
:query sortBy: field to sort on
|
2016-12-14 18:29:04 +01:00
|
|
|
:query sortDir: asc or desc
|
2016-01-29 20:47:16 +01:00
|
|
|
:query page: int default is 1
|
|
|
|
:query filter: key value pair format is k;v
|
2016-06-03 17:28:09 +02:00
|
|
|
:query count: count number default is 10
|
2015-06-22 22:47:27 +02:00
|
|
|
:reqheader Authorization: OAuth token to authenticate
|
|
|
|
:statuscode 200: no error
|
|
|
|
:statuscode 403: unauthenticated
|
|
|
|
"""
|
|
|
|
parser = paginated_parser.copy()
|
|
|
|
args = parser.parse_args()
|
2019-05-16 16:57:02 +02:00
|
|
|
args["certificate_id"] = certificate_id
|
2015-06-22 22:47:27 +02:00
|
|
|
return service.render(args)
|
|
|
|
|
|
|
|
|
2019-05-16 16:57:02 +02:00
|
|
|
api.add_resource(DomainsList, "/domains", endpoint="domains")
|
|
|
|
api.add_resource(Domains, "/domains/<int:domain_id>", endpoint="domain")
|
|
|
|
api.add_resource(
|
|
|
|
CertificateDomains,
|
|
|
|
"/certificates/<int:certificate_id>/domains",
|
|
|
|
endpoint="certificateDomains",
|
|
|
|
)
|