From 88609cd69f680d29337cc43ec516b077f7dfee15 Mon Sep 17 00:00:00 2001 From: Tobias Oetiker Date: Fri, 1 Dec 2023 17:33:25 +0100 Subject: [PATCH] release 0.48.1 (#220) * release 0.48.0 * we should have a more sensibe prefix * released --- CHANGES | 23 +++++++++- lib/CallBackery.pm | 2 +- lib/CallBackery/Model/ConfigJsonSchema.pm | 52 ++++++++++++++++++++++- 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index b061d64..4384fd3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,26 @@ +0.48.1 2023-12-01 17:32:03 +0100 Tobias Oetiker - - Fix update comboBox data + - use CB_CFG_ as prefix ... this makes more sense than CM_CB + +0.48.0 2023-11-29 11:21:50 +0100 Tobias Oetiker + + * If the environmeny variable CM_CB_OVERRIDE_... is set, the value + from the config file is overridden with the value from the environment. + + Example config file: + + BACKEND: + cfg_db: 'dbi:SQLite:dbname=/opt/running/cb.db' + LIST: + - hello + - world + + Example environment override: + + export CM_CB_OVERRIDE_BACKEND_CFG_DB='dbi:SQLite:dbname=/tmp/cb.db' + export CM_CB_OVERRIDE_LIST_0='goodbye' + + * Fix update comboBox data 0.47.9 2023-10-26 10:05:30 +0200 Tobias Oetiker diff --git a/lib/CallBackery.pm b/lib/CallBackery.pm index 5a81107..3809868 100644 --- a/lib/CallBackery.pm +++ b/lib/CallBackery.pm @@ -37,7 +37,7 @@ use CallBackery::Plugin::Doc; use CallBackery::Database; use CallBackery::User; -our $VERSION = '0.47.9'; +our $VERSION = '0.48.1'; =head2 config diff --git a/lib/CallBackery/Model/ConfigJsonSchema.pm b/lib/CallBackery/Model/ConfigJsonSchema.pm index 92edf59..ffed1a1 100644 --- a/lib/CallBackery/Model/ConfigJsonSchema.pm +++ b/lib/CallBackery/Model/ConfigJsonSchema.pm @@ -34,11 +34,61 @@ a hash containing the data from the config file =cut +my $walker; +$walker = sub ($data, $cb, $path='' ) { + if (ref $data eq 'HASH') { + for my $key (keys %$data) { + $data->{$key} = $walker->($data->{$key},$cb,$path.'/'.$key); + } + } + elsif (ref $data eq 'ARRAY') { + my $i = 0; + for my $item (@$data) { + $item = $walker->($item, $cb, $path.'/'.$i); + $i++; + } + } + else { + return $cb->($path,$data); + } + return $data; +}; + +=head2 cfgHash + +a hash containing the data from the config file. If the environment +variable CM_CB_OVERRIDE_... is set, the value from the config file is +overridden with the value from the environment. + +Example config file: + + BACKEND: + cfg_db: 'dbi:SQLite:dbname=/opt/running/cb.db' + LIST: + - hello + - world + +Example environment override: + + export CB_CFG_OVERRIDE_BACKEND_CFG_DB='dbi:SQLite:dbname=/tmp/cb.db' + export CB_CFG_OVERRIDE_LIST_0='goodbye' + +=cut + has cfgHash => sub ($self) { - my $cfg = eval { LoadFile($self->file) }; + my $cfgRaw = eval { LoadFile($self->file) }; if ($@) { Mojo::Exception->throw("Loading ".$self->file.": $@"); } + my $cfg = $walker->($cfgRaw, sub ($path,$data) { + my $env = 'CB_CFG_OVERRIDE'.$path; + $env =~ s/\//_/g; + if (exists $ENV{$env} and my $override = $ENV{$env}) { + $self->log->debug("overriding cfg $path ($data) with ENV \$$env ($override)"); + return $override; + } + return $data; + }); if (my @errors = $self->validator->validate($cfg)){ Mojo::Exception->throw("Validating ".$self->file.":\n".join "\n",@errors); }