]> git.proxmox.com Git - pmg-api.git/blob - src/PMG/API2/NodeConfig.pm
bump version to 8.1.4
[pmg-api.git] / src / PMG / API2 / NodeConfig.pm
1 package PMG::API2::NodeConfig;
2
3 use strict;
4 use warnings;
5
6 use PVE::JSONSchema qw(get_standard_option);
7 use PVE::Tools qw(extract_param);
8
9 use PMG::NodeConfig;
10
11 use base qw(PVE::RESTHandler);
12
13 __PACKAGE__->register_method ({
14 name => 'get_config',
15 path => '',
16 method => 'GET',
17 description => "Get node configuration options.",
18 protected => 1,
19 proxyto => 'node',
20 permissions => { check => [ 'admin', 'audit' ] },
21 parameters => {
22 additionalProperties => 0,
23 properties => {
24 node => get_standard_option('pve-node'),
25 },
26 },
27 returns => PMG::NodeConfig::acme_config_schema({
28 digest => {
29 type => 'string',
30 description => 'Prevent changes if current configuration file has different SHA1 digest.'
31 .' This can be used to prevent concurrent modifications.',
32 maxLength => 40,
33 optional => 1,
34 },
35 }),
36 code => sub {
37 my ($param) = @_;
38
39 return PMG::NodeConfig::load_config();
40 }});
41
42 __PACKAGE__->register_method ({
43 name => 'set_config',
44 path => '',
45 method => 'PUT',
46 description => "Set node configuration options.",
47 protected => 1,
48 proxyto => 'node',
49 permissions => { check => [ 'admin', 'audit' ] },
50 parameters => PMG::NodeConfig::acme_config_schema({
51 delete => {
52 type => 'string', format => 'pve-configid-list',
53 description => "A list of settings you want to delete.",
54 optional => 1,
55 },
56 digest => {
57 type => 'string',
58 description => 'Prevent changes if current configuration file has different SHA1 digest.'
59 .' This can be used to prevent concurrent modifications.',
60 maxLength => 40,
61 optional => 1,
62 },
63 node => get_standard_option('pve-node'),
64 }),
65 returns => { type => "null" },
66 code => sub {
67 my ($param) = @_;
68
69 my $node = extract_param($param, 'node');
70 my $delete = extract_param($param, 'delete');
71 my $digest = extract_param($param, 'digest');
72
73 PMG::NodeConfig::lock_config(sub {
74 my $conf = PMG::NodeConfig::load_config();
75
76 PVE::Tools::assert_if_modified($digest, delete $conf->{digest});
77
78 foreach my $opt (PVE::Tools::split_list($delete)) {
79 delete $conf->{$opt};
80 }
81 foreach my $opt (keys %$param) {
82 $conf->{$opt} = $param->{$opt};
83 }
84
85 # validate the acme config (check for duplicates)
86 PMG::NodeConfig::get_acme_conf($conf);
87
88 PMG::NodeConfig::write_config($conf);
89 });
90
91 return undef;
92 }});
93
94 1;