[pmg-devel] [PATCH pmg-api v2 2/2] dkim: add selector list api call

Stoiko Ivanov s.ivanov at proxmox.com
Tue Jan 14 19:31:35 CET 2020


The fix for #2504 left the GUI with an unsatisfactory UX:
Users can change the selector to any newly created or existing one, but
don't know which ones exist (without looking on the commandline)

By adding a method under '/config/dkim/selectors' which lists all existing
files matching the pattern '/etc/pmg/dkim/.*\.private' the GUI can display
all currently existing selectors.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PMG/API2/DKIMSign.pm | 38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/src/PMG/API2/DKIMSign.pm b/src/PMG/API2/DKIMSign.pm
index a8f4bd8..56edd55 100644
--- a/src/PMG/API2/DKIMSign.pm
+++ b/src/PMG/API2/DKIMSign.pm
@@ -3,7 +3,7 @@ package PMG::API2::DKIMSign;
 use strict;
 use warnings;
 
-use PVE::Tools qw(extract_param);
+use PVE::Tools qw(extract_param dir_glob_foreach);
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::Exception qw(raise_param_exc);
 use PVE::RESTHandler;
@@ -42,7 +42,8 @@ __PACKAGE__->register_method({
 
 	return [
 	    { section => 'domains'},
-	    { section => 'selector'}
+	    { section => 'selector'},
+	    { section => 'selectors'}
 	];
     }});
 
@@ -129,4 +130,37 @@ __PACKAGE__->register_method({
 
 	return { selector => $selector, keysize => $size, record => $record };
     }});
+
+__PACKAGE__->register_method({
+    name => 'get_selector_list',
+    path => 'selectors',
+    method => 'GET',
+    description => "Get a list of all existing selectors",
+    protected => 1,
+    permissions => { check => [ 'admin' ] },
+    proxyto => 'master',
+    parameters => {
+	additionalProperties => 0,
+	properties => { },
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => { selector => { type => 'string', format => 'dns-name' } },
+	},
+	links => [ { rel => 'child', href => "{selector}" } ],
+    },
+    code => sub {
+	my $res = [];
+
+	my @selectors = dir_glob_foreach('/etc/pmg/dkim/', '.*\.private', sub {
+	    my ($sel) = @_;
+	    $sel =~ s/\.private$//;
+	    push @$res, { selector => $sel };
+	});
+
+	return $res;
+    }});
+
 1;
-- 
2.20.1




More information about the pmg-devel mailing list