Skip to content

Commit

Permalink
Make the versions view authenticated
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Sep 26, 2024
1 parent 6549d60 commit dcb6ecb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion acceptance_tests/tests/tests/test_versions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
def test_ok(app_connection):
response = app_connection.get_json("c2c/versions.json", cors=False)
params = {"secret": "changeme"}
response = app_connection.get_json("c2c/versions.json", params=params, cors=False)
assert "main" in response
assert "git_hash" in response["main"]
assert "packages" in response
Expand Down
2 changes: 1 addition & 1 deletion c2cwsgiutils/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def _index(request: pyramid.request.Request) -> dict[str, str]:
body = ""
body += _health_check(request)
body += _stats(request)
body += _versions(request)
if has_access:
body += _versions(request)
body += _debug(request)
body += _db_maintenance(request)
body += _logging(request)
Expand Down
15 changes: 11 additions & 4 deletions c2cwsgiutils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import prometheus_client
import pyramid.config

from c2cwsgiutils import config_utils, prometheus
from c2cwsgiutils import auth, config_utils, prometheus

_VERSIONS_PATH = "/app/versions.json"
_LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -41,6 +41,15 @@ def init(config: pyramid.config.Configurator) -> None:
includeme(config)


class _View:
def __init__(self, versions: dict[str, dict[str, str]]) -> None:
self.versions = versions

def __call__(self, request: pyramid.request.Request) -> dict[str, dict[str, str]]:
auth.auth_view(request)
return self.versions


def includeme(config: pyramid.config.Configurator) -> None:
"""Initialize the versions view."""

Expand All @@ -49,9 +58,7 @@ def includeme(config: pyramid.config.Configurator) -> None:
config.add_route(
"c2c_versions", config_utils.get_base_path(config) + r"/versions.json", request_method="GET"
)
config.add_view(
lambda request: versions, route_name="c2c_versions", renderer="fast_json", http_cache=0
)
config.add_view(_View(versions), route_name="c2c_versions", renderer="fast_json", http_cache=0)
_LOG.info("Installed the /versions.json service")
git_hash = versions["main"]["git_hash"]

Expand Down

0 comments on commit dcb6ecb

Please sign in to comment.