mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-10-31 10:19:09 +00:00 
			
		
		
		
	Implement filter checks: ensure all defined filters are used and remove dead code
Integration tests added/updated:
- tests/integration/test_filters_usage.py: AST-based detection of filter definitions (FilterModule.filters), robust Jinja detection ({{ ... }}, {% ... %}, {% filter ... %}), plus Python call tracking; fails if a filter is used only under tests/.
- tests/integration/test_filters_are_defined.py: inverse check — every filter used in .yml/.yaml/.j2/.jinja2/.tmpl must be defined locally. Scans only inside Jinja blocks and ignores pipes inside strings (e.g., lookup('pipe', "... | grep ... | awk ...")) to avoid false positives like trusted_hosts, woff/woff2, etc.
Bug fixes & robustness:
- Build regexes without %-string formatting to avoid ValueError from literal '%' in Jinja tags.
- Strip quoted strings in usage analysis so sed/grep/awk pipes are not miscounted as filters.
- Prevent self-matches in the defining file.
Cleanup / removal of dead code:
- Removed unused filter plugins and related unit tests:
  * filter_plugins/alias_domains_map.py
  * filter_plugins/get_application_id.py
  * filter_plugins/load_configuration.py
  * filter_plugins/safe.py
  * filter_plugins/safe_join.py
  * roles/svc-db-openldap/filter_plugins/build_ldap_nested_group_entries.py
  * roles/sys-ctl-bkp-docker-2-loc/filter_plugins/dict_to_cli_args.py
  * corresponding tests under tests/unit/*
- roles/svc-db-postgres/filter_plugins/split_postgres_connections.py: dropped no-longer-needed list_postgres_roles API; adjusted tests.
Misc:
- sys-stk-front-proxy/defaults/main.yml: clarified valid vhost_flavour values (comma-separated).
Ref: https://chatgpt.com/share/68b56bac-c4f8-800f-aeef-6708dbb44199
			
			
This commit is contained in:
		| @@ -1,36 +0,0 @@ | ||||
| def dict_to_cli_args(data): | ||||
|     """ | ||||
|     Convert a dictionary into CLI argument string. | ||||
|     Example: | ||||
|     { | ||||
|         "backup-dir": "/mnt/backups", | ||||
|         "shutdown": True, | ||||
|         "ignore-volumes": ["redis", "memcached"] | ||||
|     } | ||||
|     becomes: | ||||
|     --backup-dir=/mnt/backups --shutdown --ignore-volumes="redis memcached" | ||||
|     """ | ||||
|     if not isinstance(data, dict): | ||||
|         raise TypeError("Expected a dictionary for CLI argument conversion") | ||||
|  | ||||
|     args = [] | ||||
|  | ||||
|     for key, value in data.items(): | ||||
|         cli_key = f"--{key}" | ||||
|  | ||||
|         if isinstance(value, bool): | ||||
|             if value: | ||||
|                 args.append(cli_key) | ||||
|         elif isinstance(value, list): | ||||
|             items = " ".join(map(str, value)) | ||||
|             args.append(f'{cli_key}="{items}"') | ||||
|         elif value is not None: | ||||
|             args.append(f'{cli_key}={value}') | ||||
|  | ||||
|     return " ".join(args) | ||||
|  | ||||
| class FilterModule(object): | ||||
|     def filters(self): | ||||
|         return { | ||||
|             'dict_to_cli_args': dict_to_cli_args | ||||
|         } | ||||
		Reference in New Issue
	
	Block a user