From 7673f3ee1e5048d59b4942fc39b278849e31499a Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 6 May 2017 14:19:19 +0100 Subject: [PATCH] allow check_acl to accept Device or NetAddr::IP instance --- lib/App/Netdisco/Util/Permission.pm | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/App/Netdisco/Util/Permission.pm b/lib/App/Netdisco/Util/Permission.pm index d36ebe39..5a3b5014 100644 --- a/lib/App/Netdisco/Util/Permission.pm +++ b/lib/App/Netdisco/Util/Permission.pm @@ -70,17 +70,15 @@ regualr expressions (which you can achieve with nonmatching lookahead). To match any device, use "C". To match no devices we suggest using "C" in the list. -Device property regular expressions are anchored (that is, they must match the -whole string). Device name regexp are not anchored. - -Default operation is to return true if I of the items matches. To enforce -requirement that I items match, include "C" anywhere in the list. - =cut sub check_acl { my ($thing, $config) = @_; - my $real_ip = (blessed $thing ? $thing->ip : $thing); + my $real_ip = ( + (blessed $thing and $thing->can('ip')) ? $thing->ip : ( + (blessed $thing and $thing->can('addr')) ? $thing->addr : $thing )); + return 0 if blessed $real_ip; # class we do not understand + my $addr = NetAddr::IP::Lite->new($real_ip); my $name = hostname_from_ip($addr->addr) || '!!NO_HOSTNAME!!'; my $all = (scalar grep {m/^op:and$/} @$config);