From 39313ced7edf3dc9069328390bba38f638920fd9 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 7 May 2014 12:27:57 +0200 Subject: [PATCH] map_path_to_methods: add code to return paths with uri patterns. A previous commit removed that code, but we need it in pvesh to display nice help messages. --- data/PVE/RESTHandler.pm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/data/PVE/RESTHandler.pm b/data/PVE/RESTHandler.pm index a149e8a..91b269e 100644 --- a/data/PVE/RESTHandler.pm +++ b/data/PVE/RESTHandler.pm @@ -295,10 +295,17 @@ sub map_method_by_name { } sub map_path_to_methods { - my ($class, $stack, $uri_param) = @_; + my ($class, $stack, $uri_param, $pathmatchref) = @_; my $path_lookup = $method_path_lookup->{$class}; + # Note: $pathmatchref can be used to obtain path including + # uri patterns like '/cluster/firewall/groups/{group}'. + # Used by pvesh to display help + if (defined($pathmatchref)) { + $$pathmatchref = '' if !$$pathmatchref; + } + while (defined(my $comp = shift @$stack)) { return undef if !$path_lookup; # not registerd? if ($path_lookup->{regex}) { @@ -308,8 +315,10 @@ sub map_path_to_methods { return undef if $comp !~ m/^($regex)$/; $uri_param->{$name} = $1; $path_lookup = $path_lookup->{regex}; + $$pathmatchref .= '/{' . $name . '}' if defined($pathmatchref); } elsif ($path_lookup->{folders}) { $path_lookup = $path_lookup->{folders}->{$comp}; + $$pathmatchref .= '/' . $comp if defined($pathmatchref); } else { die "internal error"; } @@ -338,13 +347,13 @@ sub map_path_to_methods { } sub find_handler { - my ($class, $method, $path, $uri_param) = @_; + my ($class, $method, $path, $uri_param, $pathmatchref) = @_; my $stack = [ grep { length($_) > 0 } split('\/+' , $path)]; # skip empty fragments my ($handler_class, $path_info); eval { - ($handler_class, $path_info) = $class->map_path_to_methods($stack, $uri_param); + ($handler_class, $path_info) = $class->map_path_to_methods($stack, $uri_param, $pathmatchref); }; my $err = $@; syslog('err', $err) if $err; -- 2.39.2