creativeprojects / resticprofile

Configuration profiles manager and scheduler for restic backup
https://creativeprojects.github.io/resticprofile/
GNU General Public License v3.0
604 stars 29 forks source link

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

Open adamantike opened 2 months ago

adamantike commented 2 months ago

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

jkellerer commented 2 months ago

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 "") }}