Skip to content
Snippets Groups Projects
Commit 9923a1ed authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

fix ignored_folders to expect folder name in the config

parent 3f48f1b9
No related branches found
No related tags found
No related merge requests found
...@@ -19,15 +19,35 @@ NUM_RETRIES = 3 ...@@ -19,15 +19,35 @@ NUM_RETRIES = 3
STATIC_DASHBOARDS_DIR = pathlib.Path(__file__).parents[1] / "dashboards" STATIC_DASHBOARDS_DIR = pathlib.Path(__file__).parents[1] / "dashboards"
def list_all_dashboards(request: TokenRequest) -> Dict[str, Dict[str, Dict]]: def list_all_dashboards(request: TokenRequest, config: dict) -> Dict[str, Dict[str, Dict]]:
config_ignored = set([f.lower() for f in config.get("ignored_folders", [])])
r = request.get("api/search?type=dash-db") r = request.get("api/search?type=dash-db")
dashboards = r.json() dashboards = r.json()
all_folders = get_folders(request) all_folders = get_folders(request)
result = {f["uid"]: {} for f in all_folders} result = {}
for dash in dashboards: ignored_folders = {}
result.setdefault(dash.get("folderUid", ""), {})[dash["title"].lower()] = dash for folder in all_folders:
if folder.get("title", "").lower() in config_ignored:
ignored_folders[folder["uid"]] = folder["title"].lower()
logger.info(
f"Ignoring folder {folder['title']} ({folder['uid']}) "
f"as it is in the ignored folders list"
)
continue
result[folder["uid"]] = {}
return result for dash in dashboards:
folder_uid = dash.get("folderUid", "")
if folder_uid in ignored_folders:
logger.info(
f"Ignoring dashboard {dash['title']} ({dash['uid']}) "
f"as it is in an ignored folder ({ignored_folders[folder_uid]})"
)
continue
result.setdefault(folder_uid, {})[dash["title"].lower()] = dash
return result, set(ignored_folders)
def delete_dashboard_by_uid(request: TokenRequest, uid: int): def delete_dashboard_by_uid(request: TokenRequest, uid: int):
......
...@@ -391,12 +391,12 @@ def provision_all_dashboards( ...@@ -391,12 +391,12 @@ def provision_all_dashboards(
organization: Organization, organization: Organization,
config: dict, config: dict,
): ):
current_folders = list_all_dashboards(organization.request) current_folders, ignored_folders = list_all_dashboards(organization.request, config)
to_render = populate_folders_for_organization(folders, data, organization) to_render = populate_folders_for_organization(folders, data, organization)
with ThreadPoolExecutor(max_workers=10) as executor: with ThreadPoolExecutor(max_workers=10) as executor:
futs = itertools.chain( futs = itertools.chain(
provision_folders( provision_folders(
to_render, organization, current_folders, config, executor to_render, organization, current_folders, ignored_folders, executor
), ),
) )
# We need to wait here for the futures to be completed. Those futures may # We need to wait here for the futures to be completed. Those futures may
...@@ -425,10 +425,10 @@ def provision_folders( ...@@ -425,10 +425,10 @@ def provision_folders(
folders: Sequence[BoundFolder], folders: Sequence[BoundFolder],
organization: Organization, organization: Organization,
current_folders: dict, current_folders: dict,
config: dict, ignored_folders: set,
executor: ThreadPoolExecutor, executor: ThreadPoolExecutor,
): ):
provisioned = set(config.get("ignored_folders", [])) provisioned = set(ignored_folders)
for folder in folders: for folder in folders:
provisioned.add(folder.uid) provisioned.add(folder.uid)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment