]> git.proxmox.com Git - proxmox-acme.git/blob - src/PVE/ACME/Challenge.pm
plugin id: limit to 'pve-configid' format
[proxmox-acme.git] / src / PVE / ACME / Challenge.pm
1 package PVE::ACME::Challenge;
2
3 use strict;
4 use warnings;
5
6 use PVE::JSONSchema qw(get_standard_option);
7
8 use base qw(PVE::SectionConfig);
9
10 my $defaultData = {
11 additionalProperties => 0,
12 propertyList => {
13 id => {
14 description => "ACME Plugin ID name",
15 type => 'string',
16 format => 'pve-configid',
17 },
18 type => {
19 description => "ACME challenge type.",
20 type => 'string',
21 },
22 disable => {
23 description => "Flag to disable the config.",
24 type => 'boolean',
25 optional => 1,
26 },
27 nodes => get_standard_option('pve-node-list', { optional => 1 }),
28 },
29 };
30
31 sub private {
32 return $defaultData;
33 }
34
35 sub parse_config {
36 my ($class, $filename, $raw) = @_;
37
38 my $cfg = $class->SUPER::parse_config($filename, $raw);
39 my $ids = $cfg->{ids};
40
41 # make sure we have a standalone plugin definition as fallback!
42 if (!$ids->{standalone} || $ids->{standalone}->{type} ne 'standalone') {
43 $ids->{standalone} = {
44 type => 'standalone',
45 };
46 }
47
48 return $cfg;
49 }
50
51 sub encode_value {
52 my ($self, $type, $key, $value) = @_;
53
54 if ($key eq 'data') {
55 $value = MIME::Base64::encode_base64url($value);
56 }
57
58 return $value;
59 };
60
61 sub decode_value {
62 my ($self, $type, $key, $value) = @_;
63
64 if ($key eq 'data') {
65 $value = MIME::Base64::decode_base64url($value);
66 }
67
68 return $value;
69 };
70
71 sub supported_challenge_types {
72 return [];
73 }
74
75 sub extract_challenge {
76 my ($self, $challenges) = @_;
77
78 die "no challenges defined\n" if !$challenges;
79
80 my $supported_types = $self->supported_challenge_types();
81
82 # preference returned by plugin!
83 foreach my $supported_type (@$supported_types) {
84 foreach my $challenge (@$challenges) {
85 next if $challenge->{type} ne $supported_type;
86
87 return $challenge;
88 }
89 }
90
91 die "plugin does not support any of the requested challenge types\n";
92 }
93
94 # acme => PVE::ACME instance
95 # auth => authorization object returned by ACME server
96 # $data => {
97 # plugin => plugin config data
98 # alias => optional domain alias
99 # }
100 # needs to set $data->{url} to URL of the challenge which has been set up
101 # can set other $data keys needed by teardown sub
102 sub setup {
103 my ($self, $acme, $auth, $data) = @_;
104
105 die "implement me\n";
106 }
107
108 # see setup
109 sub teardown {
110 my ($self, $acme, $auth, $data) = @_;
111
112 die "implement me\n";
113 }
114
115 1;