ACME: add challengeschema api call

which returns a list of challenge api types with the schema of their
required data (if it exists)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
[ Thomas: adapt to my changes from proxmox-acme schema def and change
  path from challengeschema to challenge-schema ]
This commit is contained in:
Dominik Csapak 2020-05-05 14:38:14 +02:00 committed by Thomas Lamprecht
parent 463ea0b1d8
commit 75a2be66bb

View File

@ -9,6 +9,7 @@ use PVE::Exception qw(raise_param_exc);
use PVE::JSONSchema qw(get_standard_option);
use PVE::RPCEnvironment;
use PVE::Tools qw(extract_param);
use PVE::ACME::Challenge;
use PVE::API2::ACMEPlugin;
@ -63,6 +64,7 @@ __PACKAGE__->register_method ({
{ name => 'tos' },
{ name => 'directories' },
{ name => 'plugins' },
{ name => 'challengeschema' },
];
}});
@ -366,4 +368,63 @@ __PACKAGE__->register_method ({
return $acme_directories;
}});
__PACKAGE__->register_method ({
name => 'challengeschema',
path => 'challenge-schema',
method => 'GET',
description => "Get schema of ACME challenge types.",
permissions => { user => 'all' },
parameters => {
additionalProperties => 0,
properties => {},
},
returns => {
type => 'array',
items => {
type => 'object',
additionalProperties => 0,
properties => {
id => {
type => 'string',
},
name => {
description => 'Human readable name, falls back to id',
type => 'string',
},
type => {
type => 'string',
},
schema => {
type => 'object',
},
},
},
},
code => sub {
my ($param) = @_;
my $plugin_type_enum = PVE::ACME::Challenge->lookup_types();
my $res = [];
for my $type (@$plugin_type_enum) {
my $plugin = PVE::ACME::Challenge->lookup($type);
next if !$plugin->can('get_supported_plugins');
my $plugin_type = $plugin->type();
my $plugins = $plugin->get_supported_plugins();
for my $id (sort keys %$plugins) {
my $schema = $plugins->{$id};
push @$res, {
id => $id,
name => $schema->{name} // $id,
type => $plugin_type,
schema => $schema,
};
}
}
return $res;
}});
1;