From 2d058d294729cedd6712338dfb60236c04956e98 Mon Sep 17 00:00:00 2001 From: Matt Jia Date: Oct 31 2017 23:17:49 +0000 Subject: New /about API endpoint This API endpoint simply returns the version and the authentication method of the running waiverdb instance. --- diff --git a/tests/test_api_v10.py b/tests/test_api_v10.py index 422e048..6fe55e2 100644 --- a/tests/test_api_v10.py +++ b/tests/test_api_v10.py @@ -4,6 +4,7 @@ import json from .utils import create_waiver import datetime from mock import patch +from waiverdb import __version__ @patch('waiverdb.auth.get_user', return_value=('foo', {})) @@ -209,3 +210,11 @@ def test_get_waivers_with_post_request(client, session): assert set([w['result_id'] for w in res_data['data']]) == set(range(1, 51)) assert all(w['username'] == 'foo' for w in res_data['data']) assert all(w['product_version'] == 'foo-1' for w in res_data['data']) + + +def test_about_endpoint(client): + r = client.get('/api/v1.0/about') + output = json.loads(r.get_data(as_text=True)) + assert r.status_code == 200 + assert output['version'] == __version__ + assert output['auth_method'] == client.application.config['AUTH_METHOD'] diff --git a/waiverdb/api_v1.py b/waiverdb/api_v1.py index fbe8c1d..14d1eb2 100644 --- a/waiverdb/api_v1.py +++ b/waiverdb/api_v1.py @@ -1,10 +1,11 @@ # SPDX-License-Identifier: GPL-2.0+ -from flask import Blueprint, request +from flask import Blueprint, request, current_app from flask_restful import Resource, Api, reqparse, marshal_with, marshal from werkzeug.exceptions import BadRequest, NotFound, UnsupportedMediaType from sqlalchemy.sql.expression import func +from waiverdb import __version__ from waiverdb.models import db, Waiver from waiverdb.utils import reqparse_since, json_collection, jsonp from waiverdb.fields import waiver_fields @@ -282,7 +283,35 @@ class GetWaiversByResultIDs(Resource): return {'data': marshal(query.all(), waiver_fields)} +class AboutResource(Resource): + @jsonp + def get(self): + """ + Returns the current running version and the method used for authentication. + + **Sample response**: + + .. sourcecode:: none + + HTTP/1.0 200 OK + Content-Length: 55 + Content-Type: application/json + Date: Tue, 31 Oct 2017 04:29:19 GMT + Server: Werkzeug/0.11.10 Python/2.7.13 + + { + "auth_method": "OIDC", + "version": "0.3.1" + } + + :statuscode 200: Currently running waiverdb software version and authentication + are returned. + """ + return {'version': __version__, 'auth_method': current_app.config['AUTH_METHOD']} + + # set up the Api resource routing here api.add_resource(WaiversResource, '/waivers/') api.add_resource(WaiverResource, '/waivers/') api.add_resource(GetWaiversByResultIDs, '/waivers/+by-result-ids') +api.add_resource(AboutResource, '/about')