]> git.proxmox.com Git - pve-manager-legacy.git/commitdiff
Adapt acme node config parser and rename the function.
authorWolfgang Link <w.link@proxmox.com>
Thu, 16 Apr 2020 05:18:28 +0000 (07:18 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 3 May 2020 12:10:17 +0000 (14:10 +0200)
Signed-off-by: Wolfgang Link <w.link@proxmox.com>
PVE/API2/ACME.pm
PVE/NodeConfig.pm

index 7bb3ab954769752080f0aaa79ac0efca119bdd36..d215739b021f5cf68b4b02171db3be0d506fb82c 100644 (file)
@@ -73,9 +73,9 @@ my $get_plugin_type = sub {
 };
 
 my $order_certificate = sub {
-    my ($acme, $domains) = @_;
+    my ($acme, $acme_node_config) = @_;
     print "Placing ACME order\n";
-    my ($order_url, $order) = $acme->new_order($domains);
+    my ($order_url, $order) = $acme->new_order($acme_node_config->{domains});
     print "Order URL: $order_url\n";
     my $index = 0;
     for my $auth_url (@{$order->{authorizations}}) {
@@ -213,11 +213,9 @@ __PACKAGE__->register_method ({
            if !$param->{force} && -e "${cert_prefix}.pem";
 
        my $node_config = PVE::NodeConfig::load_config($node);
-       raise("ACME settings in node configuration are missing!", 400)
-           if !$node_config || !$node_config->{acme};
-       my $acme_node_config = PVE::NodeConfig::parse_acme($node_config->{acme});
+       my $acme_node_config = PVE::NodeConfig::get_acme_conf($node_config);
        raise("ACME domain list in node configuration is missing!", 400)
-           if !$acme_node_config;
+           if !$acme_node_config || !$acme_node_config->{domains};
 
        my $rpcenv = PVE::RPCEnvironment::get();
 
@@ -235,7 +233,7 @@ __PACKAGE__->register_method ({
            print "Loading ACME account details\n";
            $acme->load();
 
-           my ($cert, $key) = $order_certificate->($acme, $acme_node_config->{domains});
+           my ($cert, $key) = $order_certificate->($acme, $acme_node_config);
 
            my $code = sub {
                print "Setting pveproxy certificate and key\n";
@@ -287,11 +285,9 @@ __PACKAGE__->register_method ({
            if !$expires_soon && !$param->{force};
 
        my $node_config = PVE::NodeConfig::load_config($node);
-       raise("ACME settings in node configuration are missing!", 400)
-           if !$node_config || !$node_config->{acme};
-       my $acme_node_config = PVE::NodeConfig::parse_acme($node_config->{acme});
+       my $acme_node_config = PVE::NodeConfig::get_acme_conf($node_config);
        raise("ACME domain list in node configuration is missing!", 400)
-           if !$acme_node_config;
+           if !$acme_node_config || !$acme_node_config->{domains};
 
        my $rpcenv = PVE::RPCEnvironment::get();
 
@@ -311,7 +307,7 @@ __PACKAGE__->register_method ({
            print "Loading ACME account details\n";
            $acme->load();
 
-           my ($cert, $key) = $order_certificate->($acme, $acme_node_config->{domains});
+           my ($cert, $key) = $order_certificate->($acme, $acme_node_config);
 
            my $code = sub {
                print "Setting pveproxy certificate and key\n";
@@ -353,11 +349,9 @@ __PACKAGE__->register_method ({
        my $cert_prefix = PVE::CertHelpers::cert_path_prefix($node);
 
        my $node_config = PVE::NodeConfig::load_config($node);
-       raise("ACME settings in node configuration are missing!", 400)
-           if !$node_config || !$node_config->{acme};
-       my $acme_node_config = PVE::NodeConfig::parse_acme($node_config->{acme});
+       my $acme_node_config = PVE::NodeConfig::get_acme_conf($node_config);
        raise("ACME domain list in node configuration is missing!", 400)
-           if !$acme_node_config;
+           if !$acme_node_config || !$acme_node_config->{domains};
 
        my $rpcenv = PVE::RPCEnvironment::get();
 
index 6ea2dac18858475ea4244c81071a865a30fe504f..ae2f916cd5dffb3596f9ec8d63b4c5d00d7e3c21 100644 (file)
@@ -227,18 +227,50 @@ sub write_node_config {
     return $raw;
 }
 
-sub parse_acme {
+sub get_acme_conf {
     my ($data, $noerr) = @_;
 
     $data //= '';
 
-    my $res = eval { PVE::JSONSchema::parse_property_string($acmedesc, $data); };
-    if ($@) {
-       return undef if $noerr;
-       die $@;
+    my $res = {};
+
+    if (defined($data->{acme})) {
+       $res->{0} = eval {
+           PVE::JSONSchema::parse_property_string($acmedesc, $data->{acme});
+       };
+       if ($@) {
+           return undef if $noerr;
+           die $@;
+       }
     }
+    $res->{0}->{account} = $res->{0}->{account} // "default";
+    my $domainlist = [];
+
+    for my $index (0..$MAXDOMAINS) {
+       my $domain_rec = $data->{"acme_additional_domain$index"};
+       next if !defined($domain_rec);
+
+       # index = 0 is used by acme see above
+       $res->{($index+1)} = eval {
+           PVE::JSONSchema::parse_property_string(
+               $acme_additional_desc,
+               $domain_rec);
+       };
+       if ($@) {
+           return undef if $noerr;
+           die $@;
+       }
+       push @$domainlist, $res->{($index+1)}->{domain};
+    }
+
+    # If additional domain are used it is not allowed
+    # to have a domain(list) at acme entry
+    my @domains = split(";", $res->{0}->{domains})
+       if $res->{0}->{domains};
+    die "Mutual exclusion of setting domains in acme and additional domains\n"
+       if (0 < @domains && defined(@$domainlist[0]));
 
-    $res->{domains} = [ PVE::Tools::split_list($res->{domains}) ];
+    $res->{"domains"} = @domains ? \@domains : $domainlist;
 
     return $res;
 }