[pve-devel] [PATCH manager v9 02/12] api: add /ui-options api call
Dominik Csapak
d.csapak at proxmox.com
Mon Nov 14 10:43:54 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>
---
changes from v8:
* add 'allowed-tags' too
maybe we want the 'allowed-tags' somewhere else? though we only use
it for the ui at the moment and i did not want to introduce another api
call that we have to call after logging in
PVE/API2.pm | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/PVE/API2.pm b/PVE/API2.pm
index a42561604..03b16aaf4 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,59 @@ __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 $tags = PVE::DataCenterConfig::get_allowed_tags($rpcenv, $authuser);
+
+ $res->{'allowed-tags'} = [sort keys $tags->%*];
+
+ return $res;
+ }});
+
1;
--
2.30.2
More information about the pve-devel
mailing list