]> git.proxmox.com Git - pve-manager.git/blob - PVE/CLI/pvesubscription.pm
api: backup: refactor backup permission check
[pve-manager.git] / PVE / CLI / pvesubscription.pm
1 package PVE::CLI::pvesubscription;
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::RPCEnvironment;
13 use PVE::CLIHandler;
14 use PVE::API2::Subscription;
15
16 use base qw(PVE::CLIHandler);
17
18 my $nodename = PVE::INotify::nodename();
19
20 sub setup_environment {
21 PVE::RPCEnvironment->setup_default_cli_env();
22 }
23
24 __PACKAGE__->register_method({
25 name => 'set_offline_key',
26 path => 'set_offline_key',
27 method => 'POST',
28 description => "(Internal use only!) Set a signed subscription info blob as offline key",
29 parameters => {
30 additionalProperties => 0,
31 properties => {
32 data => {
33 type => "string",
34 },
35 },
36 },
37 returns => { type => 'null' },
38 code => sub {
39 my ($param) = @_;
40
41 my $info = decode_json(decode_base64($param->{data}));
42
43 $info = Proxmox::RS::Subscription::check_signature($info);
44 $info = Proxmox::RS::Subscription::check_server_id($info);
45 $info = Proxmox::RS::Subscription::check_age($info, 0);
46
47 PVE::API2::Subscription::check_key($info->{key}, PVE::API2::Subscription::get_sockets());
48
49 PVE::API2::Subscription::write_etc_subscription($info);
50 }});
51
52 our $cmddef = {
53 update => [ 'PVE::API2::Subscription', 'update', undef, { node => $nodename } ],
54 get => [ 'PVE::API2::Subscription', 'get', undef, { node => $nodename }, sub {
55 my $info = shift;
56 print "$_: $info->{$_}\n" for sort keys %$info;
57 }],
58 set => [ 'PVE::API2::Subscription', 'set', ['key'], { node => $nodename } ],
59 "set-offline-key" => [ __PACKAGE__, 'set_offline_key', ['data'] ],
60 delete => [ 'PVE::API2::Subscription', 'delete', undef, { node => $nodename } ],
61 };
62
63 1;