Skip to content

Commit

Permalink
Add badge on main page to know if the source is correctly working or not
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Feb 25, 2025
1 parent 84aeac1 commit 68a83fd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ jobs:

- name: Checks
run: make checks
- run: git reset --hard
if: failure()

- name: Tests
run: make tests
Expand Down Expand Up @@ -89,6 +87,7 @@ jobs:
if: failure()

- run: git reset --hard
if: failure()
- name: Publish
run: tag-publish
if: env.HAS_SECRETS == 'HAS_SECRETS'
Expand Down
Binary file modified acceptance_tests/acceptance/index.expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 11 additions & 8 deletions app/shared_config_manager/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _watch_source():
try:
slaves = slave_status.get_source_status(id_=key)
need_refresh = False
hash_ = source.get_hash()
hash_ = ""
for slave in slaves:
if slave is None or slave.get("filtered", False):
continue
Expand All @@ -53,13 +53,16 @@ def _watch_source():
key,
)

if slave.get("hash") != hash_:
need_refresh = True
_LOG.warning(
"The hash in the slave '%s' status for source '%s' is different -> refresh.",
slave.get("hostname"),
key,
)
if hash_:
if slave.get("hash") != hash_:
need_refresh = True
_LOG.warning(
"The hash in the slave '%s' status for source '%s' is different -> refresh.",
slave.get("hostname"),
key,
)
else:
hash_ = slave.get("hash")

if need_refresh:
source.refresh()
Expand Down
5 changes: 5 additions & 0 deletions app/shared_config_manager/templates/index.html.mako
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
<ul class="list-group">
%for source in sources:
<li class="list-group-item">
%if is_valid(source):
<span class="badge bg-success">✓</span>
%else:
<span class="badge bg-danger">✗</span>
%endif
<a href="${request.route_url('ui_source', id=source.get_id())}"
>${source.get_config().get("name", source.get_id()) | h}</a>
</li>
Expand Down
24 changes: 23 additions & 1 deletion app/shared_config_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,32 @@
from shared_config_manager import slave_status
from shared_config_manager.configuration import SourceStatus
from shared_config_manager.sources import registry
from shared_config_manager.sources.base import BaseSource

_LOG = logging.getLogger(__name__)


def _is_valid(source: BaseSource) -> bool:
if source is None:
return False

slaves = slave_status.get_source_status(id_=source.get_id())
if slaves is None:
return True
hash_ = ""
for slave in slaves:
if slave is None or slave.get("filtered", False):
continue
if "hash" not in slave:
return False
if hash_:
if slave.get("hash") != hash_:
return False
else:
hash_ = slave.get("hash")
return True


@view_config(route_name="ui_index", renderer="./templates/index.html.mako") # type: ignore
def _ui_index(request: pyramid.request.Request) -> dict[str, Any]:
permission = request.has_permission("all", {})
Expand All @@ -35,7 +57,7 @@ def _ui_index(request: pyramid.request.Request) -> dict[str, Any]:
if isinstance(permission, Allowed):
sources_list.append(source)

return {"sources": sources_list}
return {"sources": sources_list, "is_valid": _is_valid}


@view_config(route_name="ui_source", renderer="./templates/source.html.mako") # type: ignore
Expand Down

0 comments on commit 68a83fd

Please sign in to comment.