]> git.proxmox.com Git - pve-manager.git/commitdiff
api: prepare api handler module for notification config
authorLukas Wagner <l.wagner@proxmox.com>
Thu, 3 Aug 2023 12:16:56 +0000 (14:16 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 16 Aug 2023 09:10:15 +0000 (11:10 +0200)
This commit adds a new Perl module, PVE::API2::Cluster::Notification.
The module will contain all API handlers for the new notification
subsystem.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
PVE/API2/Cluster.pm
PVE/API2/Cluster/Makefile
PVE/API2/Cluster/Notifications.pm [new file with mode: 0644]

index 31e9f51e4dab692340c2f2abdd73aa7c03a02ec6..04387ab4848343b34313c24b7967e8d7440601c0 100644 (file)
@@ -29,6 +29,7 @@ use PVE::API2::Cluster::Ceph;
 use PVE::API2::Cluster::Mapping;
 use PVE::API2::Cluster::Jobs;
 use PVE::API2::Cluster::MetricServer;
+use PVE::API2::Cluster::Notifications;
 use PVE::API2::ClusterConfig;
 use PVE::API2::Firewall::Cluster;
 use PVE::API2::HAConfig;
@@ -52,6 +53,11 @@ __PACKAGE__->register_method ({
     path => 'metrics',
 });
 
+__PACKAGE__->register_method ({
+    subclass => "PVE::API2::Cluster::Notifications",
+    path => 'notifications',
+});
+
 __PACKAGE__->register_method ({
     subclass => "PVE::API2::ClusterConfig",
     path => 'config',
@@ -149,6 +155,7 @@ __PACKAGE__->register_method ({
            { name => 'log' },
            { name => 'mapping' },
            { name => 'metrics' },
+           { name => 'notifications' },
            { name => 'nextid' },
            { name => 'options' },
            { name => 'replication' },
index 0c52a24103a7a6dbcee124dad572baac0a94772d..b109e5cb695dcc11e4cd56591f83b683f0c81eef 100644 (file)
@@ -8,6 +8,7 @@ PERLSOURCE=                     \
        BackupInfo.pm           \
        MetricServer.pm         \
        Mapping.pm              \
+       Notifications.pm                \
        Jobs.pm                 \
        Ceph.pm
 
diff --git a/PVE/API2/Cluster/Notifications.pm b/PVE/API2/Cluster/Notifications.pm
new file mode 100644 (file)
index 0000000..1efebbc
--- /dev/null
@@ -0,0 +1,71 @@
+package PVE::API2::Cluster::Notifications;
+
+use warnings;
+use strict;
+
+use Storable qw(dclone);
+use JSON;
+
+use PVE::Tools qw(extract_param);
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::RESTHandler;
+use PVE::Notify;
+
+use base qw(PVE::RESTHandler);
+
+sub make_properties_optional {
+    my ($properties) = @_;
+    $properties = dclone($properties);
+
+    for my $key (keys %$properties) {
+       $properties->{$key}->{optional} = 1 if $key ne 'name';
+    }
+
+    return $properties;
+}
+
+sub raise_api_error {
+    my ($api_error) = @_;
+
+    if (!(ref($api_error) eq 'HASH' && $api_error->{message} && $api_error->{code})) {
+       die $api_error;
+    }
+
+    my $msg = "$api_error->{message}\n";
+    my $exc = PVE::Exception->new($msg, code => $api_error->{code});
+
+    my (undef, $filename, $line) = caller;
+
+    $exc->{filename} = $filename;
+    $exc->{line} = $line;
+
+    die $exc;
+}
+
+__PACKAGE__->register_method ({
+    name => 'index',
+    path => '',
+    method => 'GET',
+    description => 'Index for notification-related API endpoints.',
+    permissions => { user => 'all' },
+    parameters => {
+       additionalProperties => 0,
+       properties => {},
+    },
+    returns => {
+       type => 'array',
+       items => {
+           type => 'object',
+           properties => {},
+       },
+       links => [ { rel => 'child', href => '{name}' } ],
+    },
+    code => sub {
+       my $result = [
+       ];
+
+       return $result;
+    }
+});
+
+1;