Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add support for nested hand-made variables #363

Closed
adamantike opened this issue May 6, 2024 · 2 comments
Closed

Feature request: Add support for nested hand-made variables #363

adamantike opened this issue May 6, 2024 · 2 comments

Comments

@adamantike
Copy link

Problem

Currently, hand-made variables do not support nesting, which sometimes helps to reduce duplication and simplify configuration files.

Here is a simple example, trying to reuse a single Healthchecks host URL across multiple projects:

version: "1"

{{ $healthchecksURL := "https://healthchecks.com" }}
{{ $healthchecksURLProj1 := "{{ $healthchecksURL }}/ping/uuid1" }}
{{ $healthchecksURLProj2 := "{{ $healthchecksURL }}/ping/uuid2" }}

proj1:
  env:
    HEALTHCHECKS_URL: "{{ $healthchecksURLProj1 }}"

proj2:
  env:
    HEALTHCHECKS_URL: "{{ $healthchecksURLProj2 }}"

Running show indicates that no variable expansion was done when initializing $healthchecksURLProj1:

$ resticprofile -n proj1 show
global:
    ionice-class:             2
    default-command:          snapshots
    restic-arguments-filter:  true
    restic-lock-retry-after:  1m0s
    restic-stale-lock-age:    1h0m0s
    min-memory:               100
    send-timeout:             30s

profile proj1:
    prometheus-push-format:  text

    env:
        HEALTHCHECKS_URL:  {{ $healthchecksURL }}/ping/uuid1

Proposed solution

  • Include the variable expansion logic during hand-made variable initialization/assignment.
  • If the nested variable hasn't been initialized yet, the program could fail to indicate a configuration error.
@jkellerer
Copy link
Collaborator

These variables derive from the support for go templates for all config files. These templates have very limited default functionality and a strict syntax (though they can be extended with functions, e.g. like done here )

That said there are 2 options right now to perform what you’d like to achieve:

{{ $healthchecksURL := "https://healthchecks.com" }}
{{ $healthchecksURLProj1 := (printf "%s%s" $healthchecksURL "/ping/uuid1") }}
{{ $healthchecksURLProj2 := (list $healthchecksURL "/ping/uuid2" | join "") }}

@adamantike
Copy link
Author

Closing this issue, as it has been resolved thanks to @jkellerer answer. Glad to have a way to not repeat those base URLs!

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

No branches or pull requests

2 participants