]>
Commit | Line | Data |
---|---|---|
8002175e DM |
1 | package PVE::CLI::pvesubscription; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
d4df1b14 FG |
6 | use MIME::Base64; |
7 | use JSON qw(decode_json); | |
8 | ||
8002175e DM |
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 | ||
7e017024 DM |
20 | sub setup_environment { |
21 | PVE::RPCEnvironment->setup_default_cli_env(); | |
22 | } | |
23 | ||
d4df1b14 FG |
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})); | |
d4df1b14 FG |
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 | ||
8002175e DM |
52 | our $cmddef = { |
53 | update => [ 'PVE::API2::Subscription', 'update', undef, { node => $nodename } ], | |
75d1eb55 TL |
54 | get => [ 'PVE::API2::Subscription', 'get', undef, { node => $nodename }, sub { |
55 | my $info = shift; | |
56 | print "$_: $info->{$_}\n" for sort keys %$info; | |
57 | }], | |
8002175e | 58 | set => [ 'PVE::API2::Subscription', 'set', ['key'], { node => $nodename } ], |
d4df1b14 | 59 | "set-offline-key" => [ __PACKAGE__, 'set_offline_key', ['data'] ], |
85222f82 | 60 | delete => [ 'PVE::API2::Subscription', 'delete', undef, { node => $nodename } ], |
8002175e DM |
61 | }; |
62 | ||
63 | 1; |