Implement Hooks per #726

This commit is contained in:
Oliver Gorwits
2020-11-28 14:45:56 +00:00
parent 225f9824b2
commit 669eec46db
11 changed files with 177 additions and 6 deletions

View File

@@ -29,8 +29,8 @@ subroutines.
=head2 check_acl_no( $ip | $instance, $setting_name | $acl_entry | \@acl )
Given an IP address or object instance, returns true if the configuration
setting C<$setting_name> matches, else returns false. If the setting is
undefined or empty, then C<check_acl_no> also returns false.
setting C<$setting_name> matches, else returns false. If the content of the
setting is undefined or empty, then C<check_acl_no> also returns false.
If C<$setting_name> is a valid setting, then it will be resolved to the access
control list, else we assume you passed an ACL entry or ACL.
@@ -51,8 +51,8 @@ sub check_acl_no {
=head2 check_acl_only( $ip | $instance, $setting_name | $acl_entry | \@acl )
Given an IP address or object instance, returns true if the configuration
setting C<$setting_name> matches, else returns false. If the setting is
undefined or empty, then C<check_acl_only> also returns true.
setting C<$setting_name> matches, else returns false. If the content of the
setting is undefined or empty, then C<check_acl_only> also returns true.
If C<$setting_name> is a valid setting, then it will be resolved to the access
control list, else we assume you passed an ACL entry or ACL.

View File

@@ -0,0 +1,34 @@
package App::Netdisco::Util::Worker;
use Dancer ':syntax';
use App::Netdisco::JobQueue 'jq_insert';
use Encode 'encode';
use MIME::Base64 'encode_base64';
use Storable 'dclone';
use Data::Visitor::Tiny;
use base 'Exporter';
our @EXPORT = ('queue_hook');
sub queue_hook {
my ($hook, $conf) = @_;
my $extra = { action_conf => dclone ($conf->{'with'} || {}),
event_data => dclone (vars->{'hook_data'} || {}) };
# remove scalar references which to_json cannot handle
visit( $extra->{'event_data'}, sub {
my ($key, $valueref) = @_;
$$valueref = '' if ref $$valueref eq 'SCALAR';
});
jq_insert({
action => ('hook::'. lc($conf->{'type'})),
extra => encode_base64( encode('UTF-8', to_json( $extra )) ),
});
return 1;
}
true;