diff --git a/local-app/python-tools/sso-tools/sso-create-sc-group.py b/local-app/python-tools/sso-tools/sso-create-sc-group.py index b9652082..d1426dad 100755 --- a/local-app/python-tools/sso-tools/sso-create-sc-group.py +++ b/local-app/python-tools/sso-tools/sso-create-sc-group.py @@ -1,5 +1,4 @@ #!/usr/bin/env python - import argparse import shutil from pathlib import Path @@ -7,8 +6,9 @@ # Version History: # 1.0.0: Initial release -# 1.0.1: Added shebang, exposed variables to Jinja2, updated versioning -__version__ = "1.0.1" +# 1.0.1: Added shebang, exposed variables to Jinja2 +# 1.0.2: Enforced lowercase for group and created_group names +__version__ = "1.0.2" def create_sc_group(): parser = argparse.ArgumentParser(description="Automate file creation from templates.") @@ -19,14 +19,15 @@ def create_sc_group(): args = parser.parse_args() - # 1. Determine the 'group' name (from arg or folder name) - group_name = args.group if args.group else Path.cwd().name + # 1. Determine the 'group' name and force to lowercase + raw_group = args.group if args.group else Path.cwd().name + group_name = raw_group.lower() - # 2. Define the 'created_group' string + # 2. Define the 'created_group' string and force to lowercase if args.application_label: - created_group = f"{args.business_label}-{args.application_label}-{group_name}" + created_group = f"{args.business_label}-{args.application_label}-{group_name}".lower() else: - created_group = f"{args.business_label}-{group_name}" + created_group = f"{args.business_label}-{group_name}".lower() # 3. Setup paths template_dir = Path("TEMPLATE") @@ -41,7 +42,7 @@ def create_sc_group(): # 4. Initialize Jinja2 Environment env = Environment(loader=FileSystemLoader(str(template_dir))) - # 5. Expose variables to Jinja2 templates + # 5. Expose variables to Jinja2 templates (all relevant strings are now lowercase) render_vars = { "business_label": args.business_label, "application_label": args.application_label, @@ -57,7 +58,8 @@ def create_sc_group(): continue # Skips subdirectories if item.suffix == ".j2": - # Rule: Rename GROUP.extension.j2 to {created_group}.extension + # Rule: Replace 'GROUP' with created_group and strip '.j2' + # Note: We replace the literal string 'GROUP' in the filename new_filename = item.name.replace("GROUP", created_group).replace(".j2", "") target_path = target_dir / new_filename @@ -77,3 +79,4 @@ def create_sc_group(): if __name__ == "__main__": create_sc_group() +