Skip to content
Snippets Groups Projects

Add support for versioned API

Merged Duncan Macleod requested to merge duncanmmacleod/gwdatafind-server:versioned-api into master
@@ -2,62 +2,37 @@
# Copyright (2019) Cardiff University
# Licensed under GPLv3+ - see LICENSE
"""Data views for GWDataFindServer
"""GWDataFind API v1
This API provides the same endpoints as the 'original'
LDR DataFind server API.
"""
import json
import operator
import re
import socket
from collections import defaultdict
from functools import (reduce, wraps)
from functools import reduce
from math import inf as INF
from urllib.parse import urlparse, unquote
from flask import (Blueprint, current_app, jsonify, request)
from flask import (Blueprint, current_app, request)
from ligo.segments import (segmentlist, segment)
from . import authentication
# we expect to be configured to /LDR in Apache
_PREFIX = '/services/data/v1'
from .. import authentication
from .utils import (
as_json,
_file_url,
_gsiftp_url,
)
blueprint = Blueprint(
"data",
"api/v1",
__name__,
url_prefix=_PREFIX,
url_prefix="/services/data/v1",
)
_DEFAULT_GSIFTP_HOST = socket.gethostbyaddr(socket.gethostname())[0]
_DEFAULT_GSIFTP_PORT = 15000
# -- utilities ----------------------------------------------------------------
def as_json(func):
"""Dump a function's return to JSON
"""
@wraps(func)
def decorated(*args, **kwargs):
return jsonify(func(*args, **kwargs))
return decorated
def _file_url(path):
config = current_app.config['LDRDataFindServer']
host = config.get('filehost', 'localhost')
return f'file://{host}{path}'
def _gsiftp_url(path):
config = current_app.config['LDRDataFindServer']
host = config.get('gsiftphost', _DEFAULT_GSIFTP_HOST)
port = config.get('gsiftpport', _DEFAULT_GSIFTP_PORT)
return f'gsiftp://{host}:{port}{path}'
# -- routes -------------------------------------------------------------------
@blueprint.route('/', methods=['GET', 'POST'])
@authentication.validate
Loading