From e627e5ee22c7f025f6a1b1ae3d603a6c304b7590 Mon Sep 17 00:00:00 2001 From: Tobias Oetiker Date: Wed, 29 Nov 2023 11:39:02 +0100 Subject: [PATCH 1/3] release 0.48.0 --- CHANGES | 19 ++++++++- lib/CallBackery.pm | 2 +- lib/CallBackery/Model/ConfigJsonSchema.pm | 52 ++++++++++++++++++++++- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index b061d64..86d4467 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,22 @@ +0.48.0 2023-11-29 11:21:50 +0100 Tobias Oetiker - - Fix update comboBox data + * 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..e530e2b 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.0'; =head2 config diff --git a/lib/CallBackery/Model/ConfigJsonSchema.pm b/lib/CallBackery/Model/ConfigJsonSchema.pm index 92edf59..70ec439 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 CM_CB_OVERRIDE_BACKEND_CFG_DB='dbi:SQLite:dbname=/tmp/cb.db' + export CM_CB_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 = 'CM_CB_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); } From 591428bfcc88388d7c9aa6b9737b30572160359e Mon Sep 17 00:00:00 2001 From: Tobias Oetiker Date: Fri, 1 Dec 2023 17:31:30 +0100 Subject: [PATCH 2/3] we should have a more sensibe prefix --- lib/CallBackery/Model/ConfigJsonSchema.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/CallBackery/Model/ConfigJsonSchema.pm b/lib/CallBackery/Model/ConfigJsonSchema.pm index 70ec439..ffed1a1 100644 --- a/lib/CallBackery/Model/ConfigJsonSchema.pm +++ b/lib/CallBackery/Model/ConfigJsonSchema.pm @@ -70,8 +70,8 @@ Example config file: Example environment override: - export CM_CB_OVERRIDE_BACKEND_CFG_DB='dbi:SQLite:dbname=/tmp/cb.db' - export CM_CB_OVERRIDE_LIST_0='goodbye' + export CB_CFG_OVERRIDE_BACKEND_CFG_DB='dbi:SQLite:dbname=/tmp/cb.db' + export CB_CFG_OVERRIDE_LIST_0='goodbye' =cut @@ -81,7 +81,7 @@ has cfgHash => sub ($self) { Mojo::Exception->throw("Loading ".$self->file.": $@"); } my $cfg = $walker->($cfgRaw, sub ($path,$data) { - my $env = 'CM_CB_OVERRIDE'.$path; + 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)"); From 24bfedf7c2b65ce6d93e6a462d29377d6312869b Mon Sep 17 00:00:00 2001 From: Tobias Oetiker Date: Fri, 1 Dec 2023 17:32:37 +0100 Subject: [PATCH 3/3] released --- CHANGES | 4 ++++ lib/CallBackery.pm | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 86d4467..4384fd3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +0.48.1 2023-12-01 17:32:03 +0100 Tobias Oetiker + + - 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 diff --git a/lib/CallBackery.pm b/lib/CallBackery.pm index e530e2b..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.48.0'; +our $VERSION = '0.48.1'; =head2 config