Skip to content

Commit

Permalink
Merge branch 'proxmox:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
wy414012 authored Nov 12, 2024
2 parents e7bdf05 + 449722b commit 56fab97
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 111 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export VERSION = $(DEB_VERSION_UPSTREAM_REVISION)
BUILDDIR = $(PACKAGE)-$(DEB_VERSION_UPSTREAM)

DSC=$(PACKAGE)_$(DEB_VERSION).dsc
DEB=$(PACKAGE)_$(DEB_VERSION)_$(DEB_HOST_ARCH).deb
DEB=$(PACKAGE)_$(DEB_VERSION)_all.deb

DESTDIR=
SUBDIRS = aplinfo PVE bin www services configs network-hooks test templates
Expand Down
297 changes: 263 additions & 34 deletions PVE/API2/Cluster/Notifications.pm
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ __PACKAGE__->register_method ({
{ name => 'gotify' },
{ name => 'sendmail' },
{ name => 'smtp' },
{ name => 'webhook' },
];

return $result;
Expand Down Expand Up @@ -283,7 +284,7 @@ __PACKAGE__->register_method ({
'type' => {
description => 'Type of the target.',
type => 'string',
enum => [qw(sendmail gotify smtp)],
enum => [qw(sendmail gotify smtp webhook)],
},
'comment' => {
description => 'Comment',
Expand All @@ -309,39 +310,7 @@ __PACKAGE__->register_method ({
my $config = PVE::Notify::read_config();

my $targets = eval {
my $result = [];

for my $target (@{$config->get_sendmail_endpoints()}) {
push @$result, {
name => $target->{name},
comment => $target->{comment},
type => 'sendmail',
disable => $target->{disable},
origin => $target->{origin},
};
}

for my $target (@{$config->get_gotify_endpoints()}) {
push @$result, {
name => $target->{name},
comment => $target->{comment},
type => 'gotify',
disable => $target->{disable},
origin => $target->{origin},
};
}

for my $target (@{$config->get_smtp_endpoints()}) {
push @$result, {
name => $target->{name},
comment => $target->{comment},
type => 'smtp',
disable => $target->{disable},
origin => $target->{origin},
};
}

$result
$config->get_targets();
};

raise_api_error($@) if $@;
Expand Down Expand Up @@ -1265,6 +1234,266 @@ __PACKAGE__->register_method ({
}
});

my $webhook_properties = {
name => {
description => 'The name of the endpoint.',
type => 'string',
format => 'pve-configid',
},
url => {
description => 'Server URL',
type => 'string',
},
method => {
description => 'HTTP method',
type => 'string',
enum => [qw(post put get)],
},
header => {
description => 'HTTP headers to set. These have to be formatted as'
. ' a property string in the format name=<name>,value=<base64 of value>',
type => 'array',
items => {
type => 'string',
},
optional => 1,
},
body => {
description => 'HTTP body, base64 encoded',
type => 'string',
optional => 1,
},
secret => {
description => 'Secrets to set. These have to be formatted as'
. ' a property string in the format name=<name>,value=<base64 of value>',
type => 'array',
items => {
type => 'string',
},
optional => 1,
},
comment => {
description => 'Comment',
type => 'string',
optional => 1,
},
disable => {
description => 'Disable this target',
type => 'boolean',
optional => 1,
default => 0,
},
};

__PACKAGE__->register_method ({
name => 'get_webhook_endpoints',
path => 'endpoints/webhook',
method => 'GET',
description => 'Returns a list of all webhook endpoints',
protected => 1,
permissions => {
check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
check => ['perm', '/mapping/notifications', ['Mapping.Audit']],
},
parameters => {
additionalProperties => 0,
properties => {},
},
returns => {
type => 'array',
items => {
type => 'object',
properties => {
%$webhook_properties,
'origin' => {
description => 'Show if this entry was created by a user or was built-in',
type => 'string',
enum => [qw(user-created builtin modified-builtin)],
},
},
},
links => [ { rel => 'child', href => '{name}' } ],
},
code => sub {
my $config = PVE::Notify::read_config();
my $rpcenv = PVE::RPCEnvironment::get();

my $entities = eval {
$config->get_webhook_endpoints();
};
raise_api_error($@) if $@;

return $entities;
}
});

__PACKAGE__->register_method ({
name => 'get_webhook_endpoint',
path => 'endpoints/webhook/{name}',
method => 'GET',
description => 'Return a specific webhook endpoint',
protected => 1,
permissions => {
check => ['or',
['perm', '/mapping/notifications', ['Mapping.Modify']],
['perm', '/mapping/notifications', ['Mapping.Audit']],
],
},
parameters => {
additionalProperties => 0,
properties => {
name => {
type => 'string',
format => 'pve-configid',
description => 'Name of the endpoint.'
},
}
},
returns => {
type => 'object',
properties => {
%$webhook_properties,
digest => get_standard_option('pve-config-digest'),
}
},
code => sub {
my ($param) = @_;
my $name = extract_param($param, 'name');

my $config = PVE::Notify::read_config();
my $endpoint = eval {
$config->get_webhook_endpoint($name)
};

raise_api_error($@) if $@;
$endpoint->{digest} = $config->digest();

return $endpoint;
}
});

__PACKAGE__->register_method ({
name => 'create_webhook_endpoint',
path => 'endpoints/webhook',
protected => 1,
method => 'POST',
description => 'Create a new webhook endpoint',
permissions => {
check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
},
parameters => {
additionalProperties => 0,
properties => $webhook_properties,
},
returns => { type => 'null' },
code => sub {
my ($param) = @_;
eval {
PVE::Notify::lock_config(sub {
my $config = PVE::Notify::read_config();

$config->add_webhook_endpoint(
$param,
);

PVE::Notify::write_config($config);
});
};

raise_api_error($@) if $@;
return;
}
});

__PACKAGE__->register_method ({
name => 'update_webhook_endpoint',
path => 'endpoints/webhook/{name}',
protected => 1,
method => 'PUT',
description => 'Update existing webhook endpoint',
permissions => {
check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
},
parameters => {
additionalProperties => 0,
properties => {
%{ make_properties_optional($webhook_properties) },
delete => {
type => 'array',
items => {
type => 'string',
format => 'pve-configid',
},
optional => 1,
description => 'A list of settings you want to delete.',
},
digest => get_standard_option('pve-config-digest'),
}
},
returns => { type => 'null' },
code => sub {
my ($param) = @_;

my $name = extract_param($param, 'name');
my $delete = extract_param($param, 'delete');
my $digest = extract_param($param, 'digest');

eval {
PVE::Notify::lock_config(sub {
my $config = PVE::Notify::read_config();

$config->update_webhook_endpoint(
$name,
$param, # Config updater
$delete,
$digest,
);

PVE::Notify::write_config($config);
});
};

raise_api_error($@) if $@;
return;
}
});

__PACKAGE__->register_method ({
name => 'delete_webhook_endpoint',
protected => 1,
path => 'endpoints/webhook/{name}',
method => 'DELETE',
description => 'Remove webhook endpoint',
permissions => {
check => ['perm', '/mapping/notifications', ['Mapping.Modify']],
},
parameters => {
additionalProperties => 0,
properties => {
name => {
type => 'string',
format => 'pve-configid',
},
}
},
returns => { type => 'null' },
code => sub {
my ($param) = @_;
my $name = extract_param($param, 'name');

eval {
PVE::Notify::lock_config(sub {
my $config = PVE::Notify::read_config();
$config->delete_webhook_endpoint($name);
PVE::Notify::write_config($config);
});
};

raise_api_error($@) if $@;
return;
}
});

my $matcher_properties = {
name => {
description => 'Name of the matcher.',
Expand Down
7 changes: 3 additions & 4 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Maintainer: Proxmox Support Team <support@proxmox.com>
Package: pve-manager
Section: admin
Priority: optional
Architecture: any
Architecture: all
Depends: apt (>= 1.5~),
ca-certificates,
cstream,
Expand Down Expand Up @@ -64,7 +64,7 @@ Depends: apt (>= 1.5~),
libpve-guest-common-perl (>= 5.1.4),
libpve-http-server-perl (>= 5.1.1),
libpve-notify-perl (>= 8.0.5),
libpve-rs-perl (>= 0.8.10),
libpve-rs-perl (>= 0.8.11),
libpve-storage-perl (>= 8.1.5),
librados2-perl (>= 1.3-1),
libtemplate-perl,
Expand All @@ -80,7 +80,7 @@ Depends: apt (>= 1.5~),
postfix | mail-transport-agent,
proxmox-mail-forward,
proxmox-mini-journalreader (>= 1.3-1),
proxmox-widget-toolkit (>= 4.2.0),
proxmox-widget-toolkit (>= 4.3.0),
pve-cluster (>= 8.0.5),
pve-container (>= 5.1.11),
pve-docs (>= 8.0~~),
Expand All @@ -99,7 +99,6 @@ Depends: apt (>= 1.5~),
lm-sensors,
${misc:Depends},
${perl:Depends},
${shlibs:Depends},
Recommends: libpve-network-perl (>= 0.9~),
proxmox-firewall,
proxmox-offline-mirror-helper,
Expand Down
1 change: 1 addition & 0 deletions debian/triggers
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
interest-noawait pve-api-updates
interest-noawait /usr/share/perl5/PVE
1 change: 1 addition & 0 deletions www/manager6/Workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ Ext.define('PVE.StdWorkspace', {
var win = Ext.create('Proxmox.window.PasswordEdit', {
userid: Proxmox.UserName,
confirmCurrentPassword: Proxmox.UserName !== 'root@pam',
minLength: 8,
});
win.show();
},
Expand Down
3 changes: 1 addition & 2 deletions www/manager6/dc/TokenEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Ext.define('PVE.dc.TokenEdit', {

isAdd: true,
isCreate: false,
fixedUser: false,

method: 'POST',
url: '/api2/extjs/access/users/',
Expand All @@ -33,7 +32,7 @@ Ext.define('PVE.dc.TokenEdit', {
{
xtype: 'pmxDisplayEditField',
cbind: {
editable: (get) => get('isCreate') && !get('fixedUser'),
editable: '{isCreate}',
},
submitValue: true,
editConfig: {
Expand Down
Loading

0 comments on commit 56fab97

Please sign in to comment.