Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 0.48.1 #220

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading