Added tags reading and optimized presentation

This commit is contained in:
Kevin Veen-Birkenbach 2025-04-10 09:39:49 +02:00
parent 557869802a
commit 150e15625d
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
3 changed files with 27 additions and 11 deletions

View File

@ -9,75 +9,87 @@ import yaml
from ansible.plugins.lookup import LookupBase from ansible.plugins.lookup import LookupBase
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
class LookupModule(LookupBase): class LookupModule(LookupBase):
def run(self, terms, variables=None, **kwargs): def run(self, terms, variables=None, **kwargs):
""" """
This lookup iterates over all roles whose folder name starts with 'docker-' This lookup iterates over all roles whose folder name starts with 'docker-'
and generates a list of dictionaries (cards). For each role, it: and generates a list of dictionaries (cards). For each role, it:
- Extracts the application_id (everything after "docker-") - Extracts the application_id (everything after "docker-")
- Reads the title from the role's README.md (the first H1 line) - Reads the title from the role's README.md (the first H1 line)
- Retrieves the description from galaxy_info.description in meta/main.yml - Retrieves the description from galaxy_info.description in meta/main.yml
- Retrieves the icon class from galaxy_info.logo.class - Retrieves the icon class from galaxy_info.logo.class
- Retrieves the tags from galaxy_info.galaxy_tags
- Builds the URL using the 'domains' variable (e.g. domains[application_id]) - Builds the URL using the 'domains' variable (e.g. domains[application_id])
- Sets the iframe flag from applications[application_id].landingpage_iframe_enabled - Sets the iframe flag from applications[application_id].landingpage_iframe_enabled
Only cards whose application_id is included in the variable group_names are returned. Only cards whose application_id is included in the variable group_names are returned.
""" """
# Default to "roles" if no directory is provided # Default to "roles" directory if no path is provided
roles_dir = terms[0] if len(terms) > 0 else "roles" roles_dir = terms[0] if len(terms) > 0 else "roles"
cards = [] cards = []
# Get group_names from variables; default to empty list if not set # Retrieve group_names from variables (used to filter roles)
group_names = variables.get("group_names", []) group_names = variables.get("group_names", [])
# Pattern to match roles starting with "docker-" # Search for all roles starting with "docker-"
pattern = os.path.join(roles_dir, "docker-*") pattern = os.path.join(roles_dir, "docker-*")
for role_path in glob.glob(pattern): for role_path in glob.glob(pattern):
role_dir = role_path.rstrip("/") role_dir = role_path.rstrip("/")
role_basename = os.path.basename(role_dir) role_basename = os.path.basename(role_dir)
# Skip roles not starting with "docker-"
if not role_basename.startswith("docker-"): if not role_basename.startswith("docker-"):
continue continue
# The application_id is the substring after "docker-" # Extract application_id from role name
application_id = role_basename[len("docker-"):] application_id = role_basename[len("docker-"):]
# Only add card if the application_id is in group_names # Skip roles not listed in group_names
if application_id not in group_names: if application_id not in group_names:
continue continue
# Define paths for the README.md and meta/main.yml # Define paths to README.md and meta/main.yml
readme_path = os.path.join(role_dir, "README.md") readme_path = os.path.join(role_dir, "README.md")
meta_path = os.path.join(role_dir, "meta", "main.yml") meta_path = os.path.join(role_dir, "meta", "main.yml")
# Skip role if required files are missing
if not os.path.exists(readme_path) or not os.path.exists(meta_path): if not os.path.exists(readme_path) or not os.path.exists(meta_path):
continue continue
# Extract title from first H1 line in README.md
try: try:
with open(readme_path, "r", encoding="utf-8") as f: with open(readme_path, "r", encoding="utf-8") as f:
readme_content = f.read() readme_content = f.read()
# Extract the first H1 line (title) via regex
title_match = re.search(r'^#\s+(.*)$', readme_content, re.MULTILINE) title_match = re.search(r'^#\s+(.*)$', readme_content, re.MULTILINE)
title = title_match.group(1).strip() if title_match else application_id title = title_match.group(1).strip() if title_match else application_id
except Exception as e: except Exception as e:
raise AnsibleError("Error reading '{}': {}".format(readme_path, str(e))) raise AnsibleError("Error reading '{}': {}".format(readme_path, str(e)))
# Extract metadata from meta/main.yml
try: try:
with open(meta_path, "r", encoding="utf-8") as f: with open(meta_path, "r", encoding="utf-8") as f:
meta_data = yaml.safe_load(f) meta_data = yaml.safe_load(f)
galaxy_info = meta_data.get("galaxy_info", {}) galaxy_info = meta_data.get("galaxy_info", {})
description = galaxy_info.get("description", "") description = galaxy_info.get("description", "")
logo = galaxy_info.get("logo", {}) logo = galaxy_info.get("logo", {})
icon_class = logo.get("class", "fa-solid fa-cube") icon_class = logo.get("class", "fa-solid fa-cube")
tags = galaxy_info.get("galaxy_tags", [])
except Exception as e: except Exception as e:
raise AnsibleError("Error reading '{}': {}".format(meta_path, str(e))) raise AnsibleError("Error reading '{}': {}".format(meta_path, str(e)))
# Retrieve variables for domain and application settings. # Build URL and retrieve iframe flag
domains = variables.get("domains", {}) domains = variables.get("domains", {})
applications = variables.get("applications", {}) applications = variables.get("applications", {})
domain_url = domains.get(application_id, "") domain_url = domains.get(application_id, "")
url = "https://" + domain_url if domain_url else "" url = "https://" + domain_url if domain_url else ""
app_data = applications.get(application_id, {}) app_data = applications.get(application_id, {})
iframe = app_data.get("landingpage_iframe_enabled", False) iframe = app_data.get("landingpage_iframe_enabled", False)
# Build card dictionary
card = { card = {
"icon": {"class": icon_class}, "icon": {"class": icon_class},
"title": title, "title": title,
@ -85,6 +97,10 @@ class LookupModule(LookupBase):
"url": url, "url": url,
"link_text": "Discover {} Now!".format(title), "link_text": "Discover {} Now!".format(title),
"iframe": iframe, "iframe": iframe,
"tags": tags,
} }
cards.append(card) cards.append(card)
# Return the list of cards
return [cards] return [cards]

View File

@ -1,4 +1,4 @@
# CyMaIS Presentation 🚀 # Presentation
## Description ## Description

View File

@ -1,6 +1,6 @@
galaxy_info: galaxy_info:
author: "Kevin Veen-Birkenbach" author: "Kevin Veen-Birkenbach"
description: "Automates the process of presenting CyMaIS using Reveal.js in a containerized environment. Ideal for administrators, developers, end-users, businesses, and investors." description: "This Presentation Software is a powerful tool designed for showcasing the CyMaIS platform to various audiences, including Administrators, Developers, End-Users, Businesses, and Investors."
license: "CyMaIS NonCommercial License (CNCL)" license: "CyMaIS NonCommercial License (CNCL)"
license_url: "https://s.veen.world/cncl" license_url: "https://s.veen.world/cncl"
company: | company: |
@ -25,6 +25,6 @@ galaxy_info:
issue_tracker_url: "https://s.veen.world/cymaisissues" issue_tracker_url: "https://s.veen.world/cymaisissues"
documentation: "https://s.veen.world/cymais" documentation: "https://s.veen.world/cymais"
logo: logo:
class: "fa-solid fa-presentation-screen" class: "fas fa-chalkboard-teacher"
dependencies: dependencies:
- package-manager - package-manager