Skip to content

Comments

Traefik: Allow nested access to properties#22

Merged
stonegray merged 7 commits intomainfrom
dev
Jan 12, 2026
Merged

Traefik: Allow nested access to properties#22
stonegray merged 7 commits intomainfrom
dev

Conversation

@stonegray
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings January 12, 2026 12:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables nested property access in Traefik templates using dot notation (e.g., {{ userData.port }}) while maintaining backward compatibility with flat key access (e.g., {{ port }}). The changes also remove the warnings system from the validator since template variable errors are now caught earlier during rendering.

Changes:

  • Added support for nested property access in templates via dot notation
  • Removed warning system from validator (template errors now throw during rendering)
  • Changed error handling for missing templates from throwing to returning null

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/backends/traefik/templateParser.ts Updated regex patterns to allow dots, added getContextValue function for nested property resolution, modified buildContext to populate both flat keys and userData namespace
src/backends/traefik/validators.ts Removed warnings from ValidationResult type and eliminated unreplaced template variable checks
src/backends/traefik/traefikManager.ts Removed warning handling code that logged validation warnings
src/backends/traefik/traefik.ts Changed template-not-found handling from throwing error to returning null
test/unit/traefik/template-validation.test.ts Updated tests to reflect removal of warnings and document new behavior

Comment on lines +68 to +84
/**
* Get a value from context, supporting nested property access with dot notation.
* e.g., "userData.foo" returns context.userData.foo
*/
function getContextValue(path: string): string | undefined {
const parts = path.split('.');
let value: any = context;

for (const part of parts) {
if (value == null || typeof value !== 'object') {
return undefined;
}
value = value[part];
}

return value == null ? undefined : String(value);
}
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new nested property access feature (e.g., {{ userData.port }}) is not covered by tests. While the PR updates existing tests to remove warnings-related checks, there are no tests that verify the new functionality of accessing userData properties via dot notation.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved by 5f87a1a

const available = Array.from(templates.keys()).join(', ') || '(none)';
log.error({ message: 'Template not found', data: { appName, template: data.template, available } });
throw new Error(`Template '${data.template}' not found for app '${appName}'. Available: ${available}`);
return null;
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the error handling behavior from throwing an error to returning null when a template is not found. While this makes the behavior consistent with render errors (which also return null), it's a potentially risky change. Previously, a missing template would cause an exception that could be caught higher up the stack. Now it silently fails and just logs an error. This could mask configuration issues during startup or runtime. Consider whether this behavior change is intentional and if it should be documented.

Copilot uses AI. Check for mistakes.
Comment on lines 10 to 11
/** Pattern for valid variable names (alphanumeric, underscores, and dots for nested access) */
const VALID_KEY_PATTERN = /^[a-zA-Z0-9_.]+$/;
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VALID_KEY_PATTERN now allows dots in key names, which creates ambiguity. If a user provides userData with a key containing a dot (e.g., "foo.bar": "value"), the template variable {{ foo.bar }} will try to access it as a nested path (context.foo.bar) rather than a flat key (context["foo.bar"]). This means keys with dots in userData won't be accessible via the old flat syntax, only via {{ userData.foo.bar }} (which would also fail because it tries to access userData["foo"]["bar"]). Consider either disallowing dots in userData keys or documenting this limitation clearly.

Suggested change
/** Pattern for valid variable names (alphanumeric, underscores, and dots for nested access) */
const VALID_KEY_PATTERN = /^[a-zA-Z0-9_.]+$/;
/** Pattern for valid userData keys (alphanumeric and underscores only; no dots to avoid path ambiguity) */
const VALID_KEY_PATTERN = /^[a-zA-Z0-9_]+$/;

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged and resolved in 5f87a1a

@stonegray stonegray merged commit 1ea34ed into main Jan 12, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant