Skip to content

Commit

Permalink
Add landing page with configuration
Browse files Browse the repository at this point in the history
JIRA: RHELWF-10318
  • Loading branch information
hluk committed Dec 5, 2023
1 parent b23ef50 commit 8550329
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
43 changes: 43 additions & 0 deletions greenwave/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,49 @@
log = logging.getLogger(__name__)


@api.route('/', methods=['GET'])
def landing_page():
"""
Landing page with links to documentation and other APIs and interpretation
of outcomes from ResultDB results (passed, error and incomplete).
**Sample response**:
.. sourcecode:: none
HTTP/1.1 200 OK
Connection: close
Content-Length: 452
Content-Type: application/json
Date: Tue, 05 Dec 2023 07:45:39 GMT
Server: Werkzeug/3.0.1 Python/3.12.0
{
"api_v1": "http://greenwave.example.com/api/v1.0",
"documentation": "https://gating-greenwave.readthedocs.io",
"koji_api": "https://koji.example.com/kojihub",
"outcomes_error": ["ERROR"],
"outcomes_incomplete": ["QUEUED", "RUNNING"],
"outcomes_passed": ["PASSED", "INFO"],
"resultsdb_api": "https://resultsdb.example.com/api/v2.0",
"waiverdb_api": "http://waiverdb.example.com/api/v1.0"
}
"""
return (
jsonify({
"documentation": current_app.config["DOCUMENTATION_URL"],
"api_v1": current_app.config["GREENWAVE_API_URL"],
"resultsdb_api": current_app.config["RESULTSDB_API_URL"],
"waiverdb_api": current_app.config["WAIVERDB_API_URL"],
"koji_api": current_app.config["KOJI_BASE_URL"],
"outcomes_passed": current_app.config["OUTCOMES_PASSED"],
"outcomes_error": current_app.config["OUTCOMES_ERROR"],
"outcomes_incomplete": current_app.config["OUTCOMES_INCOMPLETE"],
}),
200,
)


@api.route('/version', methods=['GET'])
def version():
"""
Expand Down
5 changes: 3 additions & 2 deletions greenwave/app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import logging
import logging.config

from flask import Flask
from greenwave.api_v1 import api
from flask import Flask, current_app, jsonify
from greenwave.api_v1 import api, landing_page
from greenwave.utils import json_error, load_config, mangle_key
from greenwave.policies import load_policies
from greenwave.subjects.subject_type import load_subject_types
Expand Down Expand Up @@ -50,6 +50,7 @@ def create_app(config_obj=None):

# register blueprints
app.register_blueprint(api, url_prefix="/api/v1.0")
app.add_url_rule('/', view_func=landing_page)
app.add_url_rule('/healthcheck', view_func=healthcheck)

# Initialize the cache.
Expand Down
2 changes: 2 additions & 0 deletions greenwave/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class Config(object):
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_SAMESITE = "Lax"

DOCUMENTATION_URL = "https://gating-greenwave.readthedocs.io"


class ProductionConfig(Config):
DEBUG = False
Expand Down
20 changes: 20 additions & 0 deletions greenwave/tests/test_landing_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-License-Identifier: GPL-2.0+
from pytest import mark


@mark.parametrize("endpoint", ("/", "/api/v1.0/"))
def test_landing_page(client, endpoint):
response = client.get(endpoint)
assert response.status_code == 200, response.text
data = response.json
config = client.application.config
assert data == {
"documentation": config["DOCUMENTATION_URL"],
"api_v1": config["GREENWAVE_API_URL"],
"resultsdb_api": config["RESULTSDB_API_URL"],
"waiverdb_api": config["WAIVERDB_API_URL"],
"koji_api": config["KOJI_BASE_URL"],
"outcomes_passed": list(config["OUTCOMES_PASSED"]),
"outcomes_error": list(config["OUTCOMES_ERROR"]),
"outcomes_incomplete": list(config["OUTCOMES_INCOMPLETE"]),
}

0 comments on commit 8550329

Please sign in to comment.