diff --git a/local-app/python-tools/sso-tools/README.md b/local-app/python-tools/sso-tools/README.md index 42edc0e8..6920234a 100644 --- a/local-app/python-tools/sso-tools/README.md +++ b/local-app/python-tools/sso-tools/README.md @@ -103,13 +103,26 @@ resource "aws_identitystore_group" "this" { ``` +### How to use the datetime object in templates + +Because `created_time` is now an object rather than a pre-formatted string, you can use Python's `.strftime()` method directly inside your templates: + +* **Standard ISO Timestamp**: `{{ created_time }}` +* **Custom Date (e.g., 2026-01-16)**: `{{ created_time.strftime('%Y-%m-%d') }}` +* **Full Time with Seconds**: `{{ created_time.strftime('%H:%M:%S') }}` +* **Year Only**: `{{ created_time.year }}` + + ## CHANGELOG +#### v1.0.6 + +* Changed `created_time` from a string to a native Python `datetime` object, allowing for custom formatting within Jinja2 templates using `.strftime()`. + ### v1.0.5 * Added `script_name`, `version`, and `created_time` to the Jinja2 render context for better file auditing/header generation. - ### v1.0.4 * Added `--description` (`-d`) argument and exposed it to Jinja2 context. @@ -135,4 +148,3 @@ resource "aws_identitystore_group" "this" { * Initial release. * Basic CLI argument parsing (`-b`, `-a`, `-g`). * Template rendering logic for `.j2` files and static file copying. - 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 20ec1233..448e87ed 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 @@ -8,9 +8,9 @@ from jinja2 import Environment, FileSystemLoader # Version History: -# 1.0.0 - 1.0.4: Initial logic, lowercase enforcement, force flag, description -# 1.0.5: Added script_name, version, and created_time to Jinja2 context -__version__ = "1.0.5" +# 1.0.0 - 1.0.5: Basic logic, lowercase, force, description, metadata strings +# 1.0.6: Passed created_time as a datetime object for flexible template formatting +__version__ = "1.0.6" def create_sc_group(): parser = argparse.ArgumentParser(description="Automate file creation from templates.") @@ -25,7 +25,7 @@ def create_sc_group(): # 1. Setup metadata script_name = os.path.basename(__file__) - now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + now = datetime.now() # Native datetime object # 2. Determine names and force to lowercase raw_group = args.group if args.group else Path.cwd().name @@ -58,7 +58,7 @@ def create_sc_group(): # 6. Initialize Jinja2 Environment env = Environment(loader=FileSystemLoader(str(template_dir))) - # 7. Context variables (Now including script metadata) + # 7. Context variables render_vars = { "business_label": args.business_label, "application_label": args.application_label, @@ -67,7 +67,7 @@ def create_sc_group(): "description": args.description or "", "script_name": script_name, "version": __version__, - "created_time": now + "created_time": now # Passed as object } # 8. Process files @@ -93,4 +93,3 @@ def create_sc_group(): if __name__ == "__main__": create_sc_group() -