[pve-devel] [PATCH v7 pve-manager 2/3] api: apt: add PUT and POST handler for repositories

Fabian Ebner f.ebner at proxmox.com
Wed Jun 23 15:39:03 CEST 2021


To allow adding/modifying them. Currently the only possible modification is
enable/disable.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

New in v7.

 PVE/API2/APT.pm | 88 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm
index 36d0e67a..c58203a7 100644
--- a/PVE/API2/APT.pm
+++ b/PVE/API2/APT.pm
@@ -678,6 +678,94 @@ __PACKAGE__->register_method({
 	return PVE::RS::APT::Repositories::repositories();
     }});
 
+__PACKAGE__->register_method({
+    name => 'add_repository',
+    path => 'repositories',
+    method => 'PUT',
+    description => "Add a standard repository to the configuration",
+    permissions => {
+	check => ['perm', '/nodes/{node}', [ 'Sys.Modify' ]],
+    },
+    protected => 1,
+    proxyto => 'node',
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    handle => {
+		type => 'string',
+		description => "Handle that identifies a repository.",
+	    },
+	    digest => {
+		type => "string",
+		description => "Digest to detect modifications.",
+		maxLength => 80,
+		optional => 1,
+	    },
+	},
+    },
+    returns => {
+	type => 'null',
+    },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::RS::APT::Repositories::add_repository($param->{handle}, $param->{digest});
+    }});
+
+__PACKAGE__->register_method({
+    name => 'change_repository',
+    path => 'repositories',
+    method => 'POST',
+    description => "Change the properties of a repository. Currently only allows enabling/disabling.",
+    permissions => {
+	check => ['perm', '/nodes/{node}', [ 'Sys.Modify' ]],
+    },
+    protected => 1,
+    proxyto => 'node',
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    path => {
+		type => 'string',
+		description => "Path to the containing file.",
+	    },
+	    index => {
+		type => 'integer',
+		description => "Index within the file (starting from 0).",
+	    },
+	    enabled => {
+		type => 'boolean',
+		description => "Whether the repository should be enabled or not.",
+		optional => 1,
+	    },
+	    digest => {
+		type => "string",
+		description => "Digest to detect modifications.",
+		maxLength => 80,
+		optional => 1,
+	    },
+	},
+    },
+    returns => {
+	type => 'null',
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $options = {
+	    enabled => $param->{enabled},
+	};
+
+	PVE::RS::APT::Repositories::change_repository(
+	    $param->{path},
+	    $param->{index},
+	    $options,
+	    $param->{digest}
+	);
+    }});
+
 __PACKAGE__->register_method({
     name => 'versions', 
     path => 'versions', 
-- 
2.30.2






More information about the pve-devel mailing list