]>
Commit | Line | Data |
---|---|---|
5460050d WL |
1 | package PVE::ACME::Challenge; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
762af3b1 WL |
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', | |
f4ee95ae | 16 | format => 'pve-configid', |
762af3b1 WL |
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 | ||
c82603c9 FG |
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 | ||
13bc64ea FG |
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 | ||
5460050d | 71 | sub supported_challenge_types { |
122626b3 | 72 | return []; |
5460050d WL |
73 | } |
74 | ||
762af3b1 | 75 | sub extract_challenge { |
122626b3 | 76 | my ($self, $challenges) = @_; |
762af3b1 WL |
77 | |
78 | die "no challenges defined\n" if !$challenges; | |
762af3b1 | 79 | |
122626b3 FG |
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; | |
762af3b1 | 86 | |
122626b3 FG |
87 | return $challenge; |
88 | } | |
89 | } | |
762af3b1 | 90 | |
122626b3 | 91 | die "plugin does not support any of the requested challenge types\n"; |
762af3b1 WL |
92 | } |
93 | ||
f00829fd FG |
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 | |
5460050d | 102 | sub setup { |
f00829fd | 103 | my ($self, $acme, $auth, $data) = @_; |
5460050d WL |
104 | |
105 | die "implement me\n"; | |
106 | } | |
107 | ||
f00829fd | 108 | # see setup |
5460050d | 109 | sub teardown { |
f00829fd | 110 | my ($self, $acme, $auth, $data) = @_; |
5460050d WL |
111 | |
112 | die "implement me\n"; | |
113 | } | |
114 | ||
115 | 1; |