chiark / gitweb /
dgit: Provide internal archive-api-query command
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 18 Jan 2015 17:59:23 +0000 (17:59 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 22 Mar 2015 15:18:52 +0000 (15:18 +0000)
dgit

diff --git a/dgit b/dgit
index 7cbef4e75fb218d2e55a69fa3e1e8ff76c535c3e..02ed55d179246a1cdbbb8be365662eda7c1f89fa 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -528,6 +528,9 @@ our %defcfg = ('dgit.default.distro' => 'debian',
               'dgit-distro.debian.git-user-force' => 'dgit',
               'dgit-distro.debian.git-proto' => 'git+ssh://',
               'dgit-distro.debian.git-path' => '/dgit/debian/repos',
+ 'dgit-distro.debian.archive-query-url', 'https://api.ftp-master.debian.org/',
+ 'dgit-distro.debian.archive-query-tls-key',
+    '/etc/ssl/certs/%HOST%.pem:/etc/dgit/%HOST%.pem',
               'dgit-distro.debian.diverts.alioth' => '/alioth',
               'dgit-distro.debian/alioth.git-host' => 'git.debian.org',
               'dgit-distro.debian/alioth.git-user-force' => '',
@@ -775,6 +778,27 @@ sub must_getcwd () {
     return $d;
 }
 
+sub archive_api_query_cmd ($) {
+    my ($subpath) = @_;
+    my @cmd = qw(curl -sS);
+    my $url = access_cfg('archive-query-url');
+    if ($url =~ m#^https://([-.0-9a-z]+)/#) {
+       my $host = $1;
+       my $keys = access_cfg('archive-query-tls-key','RETURN-UNDEF');
+       foreach my $key (split /\:/, $keys) {
+           $key =~ s/\%HOST\%/$host/g;
+           if (!stat $key) {
+               fail "for $url: stat $key: $!" unless $!==ENOENT;
+               next;
+           }
+           push @cmd, "--ca-certificate=$key", "--ca-directory=/dev/enoent";
+           last;
+       }
+    }
+    push @cmd, $url.$subpath;
+    return @cmd;
+}
+
 our %rmad;
 
 sub archive_query ($) {
@@ -2604,6 +2628,13 @@ sub cmd_quilt_fixup {
     build_maybe_quilt_fixup();
 }
 
+sub cmd_archive_api_query {
+    badusage "need only 1 subpath argument" unless @ARGV==1;
+    my ($subpath) = @ARGV;
+    my @cmd = archive_api_query_cmd($subpath);
+    exec @cmd or fail "exec curl: $!\n";
+}
+
 #---------- argument parsing and main program ----------
 
 sub cmd_version {