fix: add templating support in configuration

Refs: #15
This commit is contained in:
Glenn Y. Rolland 2023-11-18 19:56:03 +01:00 committed by glenux
parent 576b7c62c6
commit 592f0fbe41
3 changed files with 12 additions and 1 deletions

View file

@ -1,5 +1,8 @@
version: 2.0 version: 2.0
shards: shards:
crinja:
git: https://github.com/straight-shoota/crinja.git
version: 0.8.1
shellwords: shellwords:
git: https://github.com/sztheory/shellwords-crystal.git git: https://github.com/sztheory/shellwords-crystal.git
version: 0.1.0 version: 0.1.0

View file

@ -18,6 +18,8 @@ targets:
# Short description of gx-vault # Short description of gx-vault
dependencies: dependencies:
crinja:
github: straight-shoota/crinja
shellwords: shellwords:
github: szTheory/shellwords-crystal github: szTheory/shellwords-crystal

View file

@ -3,6 +3,8 @@
# SPDX-FileCopyrightText: 2023 Glenn Y. Rolland <glenux@glenux.net> # SPDX-FileCopyrightText: 2023 Glenn Y. Rolland <glenux@glenux.net>
# Copyright © 2023 Glenn Y. Rolland <glenux@glenux.net> # Copyright © 2023 Glenn Y. Rolland <glenux@glenux.net>
require "crinja"
require "./filesystems" require "./filesystems"
module GX module GX
@ -81,7 +83,11 @@ module GX
end end
private def load_filesystems(config_path : String) private def load_filesystems(config_path : String)
yaml_data = YAML.parse(File.read(config_path)) file_data = File.read(config_path)
# FIXME: render template on a value basis (instead of global)
file_patched = Crinja.render(file_data, {"env" => ENV.to_h})
yaml_data = YAML.parse(file_patched)
vaults_data = yaml_data["filesystems"].as_a vaults_data = yaml_data["filesystems"].as_a
vaults_data.each do |filesystem_data| vaults_data.each do |filesystem_data|