resticprofile
resticprofile copied to clipboard
Feature request: Add support for nested hand-made variables
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.
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 "") }}
Closing this issue, as it has been resolved thanks to @jkellerer answer. Glad to have a way to not repeat those base URLs!