[pve-devel] [PATCH manager v10 02/13] api: add /ui-options api call

Dominik Csapak d.csapak at proxmox.com
Tue Nov 15 14:02:37 CET 2022


which contains ui relevant options, like the console preference and tag-style
also contains the list of allowed tags

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2.pm | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/PVE/API2.pm b/PVE/API2.pm
index a42561604..7c1d0830d 100644
--- a/PVE/API2.pm
+++ b/PVE/API2.pm
@@ -118,6 +118,7 @@ __PACKAGE__->register_method ({
 
 	my $res = {};
 
+	# TODO remove with next major release
 	my $datacenter_confg = eval { PVE::Cluster::cfs_read_file('datacenter.cfg') } // {};
 	for my $k (qw(console)) {
 	    $res->{$k} = $datacenter_confg->{$k} if exists $datacenter_confg->{$k};
@@ -130,4 +131,64 @@ __PACKAGE__->register_method ({
 	return $res;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'ui-options',
+    path => 'ui-options',
+    method => 'GET',
+    permissions => { user => 'all' },
+    description => "Global options regarding the UI.",
+    parameters => {
+	additionalProperties => 0,
+	properties => {},
+    },
+    returns => {
+	type => "object",
+	properties => {
+	    console => {
+		type => 'string',
+		enum => ['applet', 'vv', 'html5', 'xtermjs'],
+		optional => 1,
+		description => 'The default console viewer to use.',
+	    },
+	    'tag-style' => {
+		type => 'string',
+		optional => 1,
+		description => 'Cluster wide tag style overrides',
+	    },
+	    'allowed-tags' => {
+		type => 'array',
+		optional => 1,
+		description => 'A list of allowed tags that exist.',
+		items => {
+		    type => 'string',
+		    description => 'A tag the user is allowed to set.',
+		},
+	    },
+	},
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $res = {};
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+	my $authuser = $rpcenv->get_user();
+
+	my $datacenter_confg = eval { PVE::Cluster::cfs_read_file('datacenter.cfg') } // {};
+	for my $k (qw(console tag-style)) {
+	    $res->{$k} = $datacenter_confg->{$k} if exists $datacenter_confg->{$k};
+	}
+
+	my $privileged_user = $rpcenv->check($authuser, '/', ['Sys.Modify'], 1);
+
+	my $tags = PVE::DataCenterConfig::get_allowed_tags($privileged_user, sub {
+	    my ($vmid) = @_;
+	    return $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Audit'], 0, 1);
+	});
+
+	$res->{'allowed-tags'} = [sort keys $tags->%*];
+
+	return $res;
+    }});
+
 1;
-- 
2.30.2






More information about the pve-devel mailing list