Skip to content

Commit

Permalink
make created_time a datetime object
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jan 16, 2026
1 parent 00cf983 commit 1b5d20f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
16 changes: 14 additions & 2 deletions local-app/python-tools/sso-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.

13 changes: 6 additions & 7 deletions local-app/python-tools/sso-tools/sso-create-sc-group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -93,4 +93,3 @@ def create_sc_group():

if __name__ == "__main__":
create_sc_group()

0 comments on commit 1b5d20f

Please sign in to comment.