Skip to content

Commit

Permalink
release 0.48.1 (#220)
Browse files Browse the repository at this point in the history
* release 0.48.0

* we should have a more sensibe prefix

* released
  • Loading branch information
oetiker authored Dec 1, 2023
1 parent 37d40d1 commit 88609cd
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
23 changes: 22 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
0.48.1 2023-12-01 17:32:03 +0100 Tobias Oetiker <[email protected]>

- 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 <[email protected]>

* 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 <[email protected]>

Expand Down
2 changes: 1 addition & 1 deletion lib/CallBackery.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 51 additions & 1 deletion lib/CallBackery/Model/ConfigJsonSchema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 88609cd

Please sign in to comment.