Skip to content

Commit 361c98b

Browse files
committed
Improves plugin validation and handles duplicates
Enhances plugin URL validation by skipping entries without a URL or with duplicate URLs, logging warnings for skipped plugins. Ensures installed plugins are removed from the registry list and checks for version upgrades more robustly. Refines filtering logic for better query handling and maintains clarity in plugin management. check for url != plugin_url
1 parent 99016e5 commit 361c98b

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

core/cat/routes/plugins.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ async def get_available_plugins(
2828
# index registry plugins by url
2929
registry_plugins_index = {}
3030
for p in registry_plugins:
31-
plugin_url = p["url"]
31+
plugin_url = p.get("plugin_url", None)
32+
if plugin_url is None:
33+
log.warning(f"Plugin {p.get('name')} has no `plugin_url`. It will be skipped from the plugins list.")
34+
continue
35+
url = p.get("url", None)
36+
if url and url != plugin_url:
37+
log.warning(f"Plugin {p.get('name')} has `url` {url} different from `plugin_url` {plugin_url}. please check the plugin.")
38+
if plugin_url in registry_plugins_index:
39+
current = registry_plugins_index[plugin_url]
40+
log.warning(f"duplicate plugin_url {plugin_url} found in registry. Plugins {p.get('name')} has same url than {current.get('name')}. Skipping.")
41+
continue
42+
3243
registry_plugins_index[plugin_url] = p
3344

3445
# get active plugins
@@ -53,19 +64,20 @@ async def get_available_plugins(
5364
manifest["endpoints"] = [{"name": endpoint.name, "tags": endpoint.tags} for endpoint in p.endpoints]
5465
manifest["forms"] = [{"name": form.name} for form in p.forms]
5566

67+
# do not show already installed plugins among registry plugins
68+
r = registry_plugins_index.pop(manifest["plugin_url"], None)
69+
5670
# filter by query
5771
plugin_text = [str(field) for field in manifest.values()]
5872
plugin_text = " ".join(plugin_text).lower()
73+
5974
if (query is None) or (query.lower() in plugin_text):
60-
for r in registry_plugins:
61-
if r["plugin_url"] == p.manifest["plugin_url"]:
62-
if r["version"] != p.manifest["version"]:
63-
manifest["upgrade"] = r["version"]
75+
if r is not None:
76+
r_version = r.get("version", None)
77+
if r_version is not None and r_version != p.manifest.get("version"):
78+
manifest["upgrade"] = r["version"]
6479
installed_plugins.append(manifest)
6580

66-
# do not show already installed plugins among registry plugins
67-
registry_plugins_index.pop(manifest["plugin_url"], None)
68-
6981
return {
7082
"filters": {
7183
"query": query,
@@ -298,4 +310,4 @@ async def delete_plugin(
298310
# remove folder, hooks and tools
299311
ccat.mad_hatter.uninstall_plugin(plugin_id)
300312

301-
return {"deleted": plugin_id}
313+
return {"deleted": plugin_id}

0 commit comments

Comments
 (0)