[pmg-devel] [PATCH pmg-api 1/1] api: apt: add calls for repositories

Fabian Ebner f.ebner at proxmox.com
Tue Jul 13 10:04:12 CEST 2021


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/PMG/API2/APT.pm | 292 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 292 insertions(+)

diff --git a/src/PMG/API2/APT.pm b/src/PMG/API2/APT.pm
index dafe4f4..ce54b0f 100644
--- a/src/PMG/API2/APT.pm
+++ b/src/PMG/API2/APT.pm
@@ -20,6 +20,7 @@ use PVE::JSONSchema qw(get_standard_option);
 use PMG::RESTEnvironment;
 use PMG::pmgcfg;
 use PMG::Config;
+use PMG::RS::APT::Repositories;
 
 use AptPkg::Cache;
 use AptPkg::Version;
@@ -63,6 +64,7 @@ __PACKAGE__->register_method({
 
 	my $res = [
 	    { id => 'changelog' },
+	    { id => 'repositories' },
 	    { id => 'update' },
 	    { id => 'versions' },
 	];
@@ -469,6 +471,296 @@ __PACKAGE__->register_method({
 	return $data;
     }});
 
+__PACKAGE__->register_method({
+    name => 'repositories',
+    path => 'repositories',
+    method => 'GET',
+    proxyto => 'node',
+    description => "Get APT repository information.",
+    permissions => {
+	check => ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	},
+    },
+    returns => {
+	type => "object",
+	description => "Result from parsing the APT repository files in /etc/apt/.",
+	properties => {
+	    files => {
+		type => "array",
+		description => "List of parsed repository files.",
+		items => {
+		    type => "object",
+		    properties => {
+			path => {
+			    type => "string",
+			    description => "Path to the problematic file.",
+			},
+			'file-type' => {
+			    type => "string",
+			    enum => [ 'list', 'sources' ],
+			    description => "Format of the file.",
+			},
+			repositories => {
+			    type => "array",
+			    description => "The parsed repositories.",
+			    items => {
+				type => "object",
+				properties => {
+				    Types => {
+					type => "array",
+					description => "List of package types.",
+					items => {
+					    type => "string",
+					    enum => [ 'deb', 'deb-src' ],
+					},
+				    },
+				    URIs => {
+					description => "List of repository URIs.",
+					type => "array",
+					items => {
+					    type => "string",
+					},
+				    },
+				    Suites => {
+					type => "array",
+					description => "List of package distribuitions",
+					items => {
+					    type => "string",
+					},
+				    },
+				    Components => {
+					type => "array",
+					description => "List of repository components",
+					optional => 1, # not present if suite is absolute
+					items => {
+					    type => "string",
+					},
+				    },
+				    Options => {
+					type => "array",
+					description => "Additional options",
+					optional => 1,
+					items => {
+					    type => "object",
+					    properties => {
+						Key => {
+						    type => "string",
+						},
+						Values => {
+						    type => "array",
+						    items => {
+							type => "string",
+						    },
+						},
+					    },
+					},
+				    },
+				    Comment => {
+					type => "string",
+					description => "Associated comment",
+					optional => 1,
+				    },
+				    FileType => {
+					type => "string",
+					enum => [ 'list', 'sources' ],
+					description => "Format of the defining file.",
+				    },
+				    Enabled => {
+					type => "boolean",
+					description => "Whether the repository is enabled or not",
+				    },
+				},
+			    },
+			},
+			digest => {
+			    type => "array",
+			    description => "Digest of the file as bytes.",
+			    items => {
+				type => "integer",
+			    },
+			},
+		    },
+		},
+	    },
+	    errors => {
+		type => "array",
+		description => "List of problematic repository files.",
+		items => {
+		    type => "object",
+		    properties => {
+			path => {
+			    type => "string",
+			    description => "Path to the problematic file.",
+			},
+			error => {
+			    type => "string",
+			    description => "The error message",
+			},
+		    },
+		},
+	    },
+	    digest => {
+		type => "string",
+		description => "Common digest of all files.",
+	    },
+	    infos => {
+		type => "array",
+		description => "Additional information/warnings for APT repositories.",
+		items => {
+		    type => "object",
+		    properties => {
+			path => {
+			    type => "string",
+			    description => "Path to the associated file.",
+			},
+			index => {
+			    type => "string",
+			    description => "Index of the associated repository within the file.",
+			},
+			property => {
+			    type => "string",
+			    description => "Property from which the info originates.",
+			    optional => 1,
+			},
+			kind => {
+			    type => "string",
+			    description => "Kind of the information (e.g. warning).",
+			},
+			message => {
+			    type => "string",
+			    description => "Information message.",
+			}
+		    },
+		},
+	    },
+	    'standard-repos' => {
+		type => "array",
+		description => "List of standard repositories and their configuration status",
+		items => {
+		    type => "object",
+		    properties => {
+			handle => {
+			    type => "string",
+			    description => "Handle to identify the repository.",
+			},
+			name => {
+			    type => "string",
+			    description => "Display name of the repository.",
+			},
+			description => {
+			    type => "string",
+			    description => "Description of the repository.",
+			},
+			status => {
+			    type => "boolean",
+			    optional => 1,
+			    description => "Indicating enabled/disabled status, if the " .
+				"repository is configured.",
+			},
+		    },
+		},
+	    },
+	},
+    },
+    code => sub {
+	my ($param) = @_;
+
+	return PMG::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) = @_;
+
+	PMG::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 => int($param->{enabled}),
+	};
+
+	PMG::RS::APT::Repositories::change_repository(
+	    $param->{path},
+	    int($param->{index}),
+	    $options,
+	    $param->{digest}
+	);
+    }});
+
 __PACKAGE__->register_method({
     name => 'versions',
     path => 'versions',
-- 
2.30.2





More information about the pmg-devel mailing list