From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 3A5BBBDFF for ; Tue, 4 Jul 2023 11:45:35 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 23F4E2782F for ; Tue, 4 Jul 2023 11:45:35 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 4 Jul 2023 11:45:33 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 56D7043C65 for ; Tue, 4 Jul 2023 11:45:33 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pve-devel@lists.proxmox.com Date: Tue, 4 Jul 2023 11:45:07 +0200 Message-Id: <20230704094507.92567-5-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230704094507.92567-1-f.gruenbichler@proxmox.com> References: <20230704094507.92567-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.071 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH manager 1/1] apt: use `apt changelog` for changelog fetching X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Jul 2023 09:45:35 -0000 support for it got added to Proxmox repositories, so there is no need to use custom logic and manual fetching for this anymore. Signed-off-by: Fabian Grünbichler --- Notes: requires versioned depends on proxmox-widget-toolkit. PVE/API2/APT.pm | 101 ++++++++---------------------------------------- 1 file changed, 16 insertions(+), 85 deletions(-) diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm index 6694dbeb6..dc506e6fe 100644 --- a/PVE/API2/APT.pm +++ b/PVE/API2/APT.pm @@ -88,38 +88,6 @@ my $get_pkgfile = sub { return undef; }; -my $get_changelog_url =sub { - my ($pkgname, $info, $pkgver, $pkgfile) = @_; - - my $base; - $base = dirname($info->{FileName}) if defined($info->{FileName}); - - my $origin = $pkgfile->{Origin}; - - if ($origin && $base) { - $pkgver =~ s/^\d+://; # strip epoch - my $srcpkg = $info->{SourcePkg} || $pkgname; - if ($origin eq 'Debian' || $origin eq 'Debian Backports') { - $base =~ s!pool/updates/!pool/!; # for security channel - return "http://packages.debian.org/changelogs/$base/${srcpkg}_${pkgver}/changelog"; - } elsif ($origin eq 'Proxmox') { - # the product is just for getting the standard repos and is currently a required param, - # but we actually only care about `files`, which includes _all_ configured repos - my $data = Proxmox::RS::APT::Repositories::repositories("pve"); - - for my $file ($data->{files}->@*) { - for my $repo (grep { $_->{Enabled} } $file->{repositories}->@*) { - next if !grep(/$pkgfile->{Component}/, $repo->{Components}->@*); - next if !$repo->{URIs}[0] =~ m/$pkgfile->{Site}/; - - return $repo->{URIs}[0] . "/$base/${pkgname}_${pkgver}.changelog"; - } - } - } - } - return; # none found, with our heuristic that is.. -}; - my $assemble_pkginfo = sub { my ($pkgname, $info, $current_ver, $candidate_ver) = @_; @@ -131,9 +99,6 @@ my $assemble_pkginfo = sub { if (my $pkgfile = &$get_pkgfile($candidate_ver)) { $data->{Origin} = $pkgfile->{Origin}; - my $changelog_url = $get_changelog_url->($pkgname, $info, $candidate_ver->{VerStr}, $pkgfile); - - $data->{ChangeLogUrl} = $changelog_url if $changelog_url; } if (my $desc = $info->{LongDesc}) { @@ -410,62 +375,28 @@ __PACKAGE__->register_method({ my $pkgname = $param->{name}; - my $cache = &$get_apt_cache(); - my $policy = $cache->policy; - my $p = $cache->{$pkgname} || die "no such package '$pkgname'\n"; - my $pkgrecords = $cache->packages(); - - my $ver; - if ($param->{version}) { - if (my $available = $p->{VersionList}) { - for my $v (@$available) { - if ($v->{VerStr} eq $param->{version}) { - $ver = $v; - last; - } - } - } - die "package '$pkgname' version '$param->{version}' is not available\n" if !$ver; + my $cmd = ['apt-get', 'changelog', '-qq']; + if (my $version = $param->{version}) { + push @$cmd, "$pkgname=$version"; } else { - $ver = $policy->candidate($p) || die "no installation candidate for package '$pkgname'\n"; + push @$cmd, "$pkgname"; } - my $info = $pkgrecords->lookup($pkgname); - - my $pkgfile = $get_pkgfile->($ver) or die "couldn't find package info file for ${pkgname}=$ver->{VerStr}\n"; - - my $url = $get_changelog_url->($pkgname, $info, $ver->{VerStr}, $pkgfile) - or die "changelog for '${pkgname}_$ver->{VerStr}' not available\n"; - - my $ua = LWP::UserAgent->new(); - $ua->agent("PVE/1.0"); - $ua->timeout(10); - $ua->max_size(1024 * 1024); - $ua->ssl_opts(verify_hostname => 0); # don't care for changelogs - - my $datacenter_cfg = PVE::Cluster::cfs_read_file('datacenter.cfg'); - if (my $proxy = $datacenter_cfg->{http_proxy}) { - $ua->proxy(['http', 'https'], $proxy); - } else { - $ua->env_proxy; - } + my $output = ""; - if ($pkgfile->{Origin} eq 'Proxmox' && $pkgfile->{Component} eq 'pve-enterprise') { - my $info = PVE::API2::Subscription::read_etc_subscription(); - if ($info->{status} eq 'active') { - my $pw = PVE::API2Tools::get_hwaddress(); - $ua->credentials("enterprise.proxmox.com:443", 'pve-enterprise-repository', $info->{key}, $pw); - } - } + my $rc = PVE::Tools::run_command( + $cmd, + timeout => 10, + logfunc => sub { + my $line = shift; + $output .= "$line\n"; + }, + noerr => 1, + ); - my $response = $ua->get($url); + $output .= "RC: $rc" if $rc != 0; - if ($response->is_success) { - return $response->decoded_content; - } else { - PVE::Exception::raise($response->message, code => $response->code); - } - return ''; + return $output; }}); __PACKAGE__->register_method({ -- 2.39.2