]> git.proxmox.com Git - pmg-api.git/commitdiff
add node-config api entry points
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 16 Mar 2021 10:24:14 +0000 (11:24 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 16 Mar 2021 16:14:57 +0000 (17:14 +0100)
adds /nodes/{nodename}/config to access node config

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/Makefile
src/PMG/API2/NodeConfig.pm [new file with mode: 0644]
src/PMG/API2/Nodes.pm

index e0629b2e201eacc56dddd0568ce66b3ecf2840a4..eac682b369849452a26f3806aa4cb53cf3b6b968 100644 (file)
@@ -158,6 +158,7 @@ LIBSOURCES =                                \
        PMG/API2/Certificates.pm        \
        PMG/API2/ACME.pm                \
        PMG/API2/ACMEPlugin.pm          \
+       PMG/API2/NodeConfig.pm          \
        PMG/API2.pm                     \
 
 SOURCES = ${LIBSOURCES} ${CLI_BINARIES} ${TEMPLATES_FILES} ${CONF_MANS} ${CLI_MANS} ${SERVICE_MANS} ${SERVICE_UNITS} ${TIMER_UNITS} pmg-sources.list pmg-apt.conf pmg-initramfs.conf
diff --git a/src/PMG/API2/NodeConfig.pm b/src/PMG/API2/NodeConfig.pm
new file mode 100644 (file)
index 0000000..284f663
--- /dev/null
@@ -0,0 +1,90 @@
+package PMG::API2::NodeConfig;
+
+use strict;
+use warnings;
+
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::Tools qw(extract_param);
+
+use PMG::NodeConfig;
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method ({
+    name => 'get_config',
+    path => '',
+    method => 'GET',
+    description => "Get node configuration options.",
+    protected => 1,
+    proxyto => 'node',
+    permissions => { check => [ 'admin', 'audit' ] },
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+       },
+    },
+    returns =>  PMG::NodeConfig::acme_config_schema({
+       digest => {
+           type => 'string',
+           description => 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
+           maxLength => 40,
+           optional => 1,
+       },
+    }),
+    code => sub {
+       my ($param) = @_;
+
+       return PMG::NodeConfig::load_config();
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'set_config',
+    path => '',
+    method => 'PUT',
+    description => "Set node configuration options.",
+    protected => 1,
+    proxyto => 'node',
+    permissions => { check => [ 'admin', 'audit' ] },
+    parameters => PMG::NodeConfig::acme_config_schema({
+       delete => {
+           type => 'string', format => 'pve-configid-list',
+           description => "A list of settings you want to delete.",
+           optional => 1,
+       },
+       digest => {
+           type => 'string',
+           description => 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
+           maxLength => 40,
+           optional => 1,
+       },
+       node => get_standard_option('pve-node'),
+    }),
+    returns => { type => "null" },
+    code => sub {
+       my ($param) = @_;
+
+       my $node = extract_param($param, 'node');
+       my $delete = extract_param($param, 'delete');
+       my $digest = extract_param($param, 'digest');
+
+       PMG::NodeConfig::lock_config(sub {
+           my $conf = PMG::NodeConfig::load_config();
+
+           PVE::Tools::assert_if_modified($digest, delete $conf->{digest});
+
+           foreach my $opt (PVE::Tools::split_list($delete)) {
+               delete $conf->{$opt};
+           };
+
+           foreach my $opt (keys %$param) {
+               $conf->{$opt} = $param->{$opt};
+           }
+
+           PMG::NodeConfig::write_config($conf);
+       });
+
+       return undef;
+    }});
+
+1;
index b6f0cd514239cdb9a450f0eaaf5d919e84dd4370..8cdf935150a913275ecb5e9e359239cbebeb6b89 100644 (file)
@@ -28,6 +28,7 @@ use PMG::API2::MailTracker;
 use PMG::API2::Backup;
 use PMG::API2::PBS::Job;
 use PMG::API2::Certificates;
+use PMG::API2::NodeConfig;
 
 use base qw(PVE::RESTHandler);
 
@@ -91,6 +92,11 @@ __PACKAGE__->register_method ({
     path => 'certificates',
 });
 
+__PACKAGE__->register_method ({
+    subclass => "PMG::API2::NodeConfig",
+    path => 'config',
+});
+
 __PACKAGE__->register_method ({
     name => 'index',
     path => '',
@@ -133,6 +139,7 @@ __PACKAGE__->register_method ({
            { name => 'termproxy' },
            { name => 'rrddata' },
            { name => 'certificates' },
+           { name => 'config' },
        ];
 
        return $result;