]> git.proxmox.com Git - pmg-api.git/blob - src/PMG/CLI/pmgsubscription.pm
subscription: switch to rust, add offline key support
[pmg-api.git] / src / PMG / CLI / pmgsubscription.pm
1 package PMG::CLI::pmgsubscription;
2
3 use strict;
4 use warnings;
5
6 use MIME::Base64;
7 use JSON qw(decode_json);
8
9 use PVE::Tools;
10 use PVE::SafeSyslog;
11 use PVE::INotify;
12 use PVE::CLIHandler;
13
14 use PMG::RESTEnvironment;
15 use PMG::API2::Subscription;
16
17 use base qw(PVE::CLIHandler);
18
19 my $nodename = PVE::INotify::nodename();
20
21 __PACKAGE__->register_method({
22 name => 'set_offline_key',
23 path => 'set_offline_key',
24 method => 'POST',
25 description => "(Internal use only!) Set a signed subscription info blob as offline key",
26 parameters => {
27 additionalProperties => 0,
28 properties => {
29 data => {
30 type => "string",
31 },
32 },
33 },
34 returns => { type => 'null' },
35 code => sub {
36 my ($param) = @_;
37
38 my $info = decode_json(decode_base64($param->{data}));
39
40 $info = Proxmox::RS::Subscription::check_signature($info);
41 $info = Proxmox::RS::Subscription::check_server_id($info);
42 $info = Proxmox::RS::Subscription::check_age($info, 0);
43
44 PMG::API2::Subscription::write_etc_subscription($info);
45 }});
46
47 sub setup_environment {
48 PMG::RESTEnvironment->setup_default_cli_env();
49 }
50
51 our $cmddef = {
52 update => [ 'PMG::API2::Subscription', 'update', undef, { node => $nodename } ],
53 get => [ 'PMG::API2::Subscription', 'get', undef, { node => $nodename },
54 sub {
55 my $info = shift;
56 foreach my $k (sort keys %$info) {
57 print "$k: $info->{$k}\n";
58 }
59 }],
60 set => [ 'PMG::API2::Subscription', 'set', ['key'], { node => $nodename } ],
61 "set-offline-key" => [ __PACKAGE__, 'set_offline_key', ['data'] ],
62 delete => [ 'PMG::API2::Subscription', 'delete', undef, { node => $nodename } ],
63 };
64
65 1;