[pve-devel] [PATCH v2 pve-manager 21/22] PVE::API2Tools::resolve_proxyto - new helper
Dietmar Maurer
dietmar at proxmox.com
Mon May 29 11:30:05 CEST 2017
Call proxyto_callback if that method is defined.
Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
PVE/API2Tools.pm | 18 ++++++++++++++++++
PVE/HTTPServer.pm | 9 ++++-----
bin/pvesh | 8 ++++----
3 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/PVE/API2Tools.pm b/PVE/API2Tools.pm
index 24947753..9bd4e49d 100644
--- a/PVE/API2Tools.pm
+++ b/PVE/API2Tools.pm
@@ -4,8 +4,10 @@ use strict;
use warnings;
use Net::IP;
+use PVE::Exception qw(raise_param_exc);
use PVE::Tools;
use PVE::INotify;
+use PVE::Cluster;
use Digest::MD5 qw(md5_hex);
use URI;
use URI::Escape;
@@ -239,4 +241,20 @@ sub read_proxy_config {
return $res;
}
+sub resolve_proxyto {
+ my ($rpcenv, $proxyto_callback, $proxyto, $uri_param) = @_;
+
+ my $node;
+ if ($proxyto_callback) {
+ $node = $proxyto_callback->($rpcenv, $proxyto, $uri_param);
+ die "internal error - proxyto_callback returned nothing\n"
+ if !$node;
+ } else {
+ $node = $uri_param->{$proxyto};
+ raise_param_exc({ $proxyto => "proxyto parameter does not exists"})
+ if !$node;
+ }
+ return $node;
+}
+
1;
diff --git a/PVE/HTTPServer.pm b/PVE/HTTPServer.pm
index 0fae3e28..bbea3198 100755
--- a/PVE/HTTPServer.pm
+++ b/PVE/HTTPServer.pm
@@ -12,6 +12,7 @@ use PVE::Exception qw(raise_param_exc);
use PVE::RPCEnvironment;
use PVE::AccessControl;
use PVE::Cluster;
+use PVE::API2Tools;
use Data::Dumper;
@@ -135,11 +136,9 @@ sub rest_handler {
# check access permissions
$rpcenv->check_api2_permissions($info->{permissions}, $auth->{userid}, $uri_param);
- if ($info->{proxyto}) {
- my $pn = $info->{proxyto};
- my $node = $uri_param->{$pn};
-
- raise_param_exc({$pn => "proxy parameter '$pn' does not exists"}) if !$node;
+ if ($info->{proxyto} || $info->{proxyto_callback}) {
+ my $node = PVE::API2Tools::resolve_proxyto(
+ $rpcenv, $info->{proxyto_callback}, $info->{proxyto}, $uri_param);
if ($node ne 'localhost' && $node ne PVE::INotify::nodename()) {
die "unable to proxy file uploads" if $auth->{isUpload};
diff --git a/bin/pvesh b/bin/pvesh
index 6f7687ef..936a849b 100755
--- a/bin/pvesh
+++ b/bin/pvesh
@@ -15,6 +15,7 @@ use PVE::SafeSyslog;
use PVE::Cluster;
use PVE::INotify;
use PVE::RPCEnvironment;
+use PVE::API2Tools;
use PVE::API2;
use JSON;
@@ -239,10 +240,9 @@ sub map_cmd {
sub check_proxyto {
my ($info, $uri_param) = @_;
- if ($info->{proxyto}) {
- my $pn = $info->{proxyto};
- my $node = $uri_param->{$pn};
- die "proxy parameter '$pn' does not exists" if !$node;
+ if ($info->{proxyto} || $info->{proxyto_callback}) {
+ my $node = PVE::API2Tools::resolve_proxyto(
+ $rpcenv, $info->{proxyto_callback}, $info->{proxyto}, $uri_param);
if ($node ne 'localhost' && ($node ne PVE::INotify::nodename())) {
die "proxy loop detected - aborting\n" if $disable_proxy;
--
2.11.0
More information about the pve-devel
mailing list