From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id A907C6B05F for ; Tue, 16 Mar 2021 11:24:35 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4A2712C4EE for ; Tue, 16 Mar 2021 11:24:34 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 022002C3DB for ; Tue, 16 Mar 2021 11:24:27 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C08534631D for ; Tue, 16 Mar 2021 11:24:26 +0100 (CET) From: Wolfgang Bumiller To: pmg-devel@lists.proxmox.com Date: Tue, 16 Mar 2021 11:24:14 +0100 Message-Id: <20210316102424.25885-8-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210316102424.25885-1-w.bumiller@proxmox.com> References: <20210316102424.25885-1-w.bumiller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.031 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [certificates.pm, acmeplugin.pm, nodes.pm, api2.pm, acme.pm, nodeconfig.pm] Subject: [pmg-devel] [PATCH v3 api 7/8] add node-config api entry points X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Mar 2021 10:24:35 -0000 adds /nodes/{nodename}/config to access node config Signed-off-by: Wolfgang Bumiller --- No changes since v2 src/Makefile | 1 + src/PMG/API2/NodeConfig.pm | 90 ++++++++++++++++++++++++++++++++++++++ src/PMG/API2/Nodes.pm | 7 +++ 3 files changed, 98 insertions(+) create mode 100644 src/PMG/API2/NodeConfig.pm diff --git a/src/Makefile b/src/Makefile index e0629b2..eac682b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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 index 0000000..284f663 --- /dev/null +++ b/src/PMG/API2/NodeConfig.pm @@ -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; diff --git a/src/PMG/API2/Nodes.pm b/src/PMG/API2/Nodes.pm index b6f0cd5..8cdf935 100644 --- a/src/PMG/API2/Nodes.pm +++ b/src/PMG/API2/Nodes.pm @@ -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; -- 2.20.1