Skip to content

Commit

Permalink
[backend] support view=info in cloudupload pubkey query
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Feb 16, 2018
1 parent ac7c219 commit 6232ff0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 36 deletions.
19 changes: 11 additions & 8 deletions src/backend/BSXML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1820,17 +1820,20 @@ our $multibuild = [
[ 'flavor' ],
];

our $pubkeyinfo = [
'pubkey' =>
'keyid',
'algo',
'keysize',
'expires',
'fingerprint',
'_content',
];

our $keyinfo = [
'keyinfo' =>
'project',
[ 'pubkey' =>
'keyid',
'algo',
'keysize',
'expires',
'fingerprint',
'_content',
],
$pubkeyinfo,
'sslcert',
];

Expand Down
65 changes: 37 additions & 28 deletions src/backend/bs_srcserver
Original file line number Diff line number Diff line change
Expand Up @@ -5147,6 +5147,33 @@ sub getsslcert {
return ('', 'Content-Type: text/plain');
}

sub pubkeyinfo {
my ($pk) = @_;

my $algo;
my $keysize;
my $fingerprint;
my $expire;
eval {
my $pku = BSPGP::unarmor($pk);
eval { $algo = BSPGP::pk2algo($pku) };
eval { $keysize = BSPGP::pk2keysize($pku) };
eval { $fingerprint = BSPGP::pk2fingerprint($pku) };
eval { $expire = BSPGP::pk2expire($pku) };
};
my $pubkey = { '_content' => $pk };
$pubkey->{'algo'} = $algo if $algo;
$pubkey->{'keysize'} = $keysize if $keysize;
if ($fingerprint) {
$pubkey->{'keyid'} = substr($fingerprint, -8, 8);
$fingerprint =~ s/(....)/$1 /g;
$fingerprint =~ s/ $//;
$pubkey->{'fingerprint'} = $fingerprint;
}
$pubkey->{'expires'} = $expire if $expire;
return $pubkey;
}

sub getkeyinfo {
my ($cgi, $projid) = @_;

Expand Down Expand Up @@ -5184,32 +5211,8 @@ sub getkeyinfo {
}
my $keyinfo = {};
$keyinfo->{'project'} = $projid if $projid;
if ($pk) {
my $algo;
my $keysize;
my $fingerprint;
my $expire;
eval {
my $pku = BSPGP::unarmor($pk);
eval { $algo = BSPGP::pk2algo($pku) };
eval { $keysize = BSPGP::pk2keysize($pku) };
eval { $fingerprint = BSPGP::pk2fingerprint($pku) };
eval { $expire = BSPGP::pk2expire($pku) };
};
$keyinfo->{'pubkey'} = { '_content' => $pk };
$keyinfo->{'pubkey'}->{'algo'} = $algo if $algo;
$keyinfo->{'pubkey'}->{'keysize'} = $keysize if $keysize;
if ($fingerprint) {
$keyinfo->{'pubkey'}->{'keyid'} = substr($fingerprint, -8, 8);
$fingerprint =~ s/(....)/$1 /g;
$fingerprint =~ s/ $//;
$keyinfo->{'pubkey'}->{'fingerprint'} = $fingerprint;
}
$keyinfo->{'pubkey'}->{'expires'} = $expire if $expire;
}
if ($cert) {
$keyinfo->{'sslcert'} = $cert;
}
$keyinfo->{'pubkey'} = pubkeyinfo($pk) if $pk;
$keyinfo->{'sslcert'} = $cert if $cert;
return ($keyinfo, $BSXML::keyinfo);
}

Expand Down Expand Up @@ -6168,7 +6171,13 @@ sub cloudupload_status {

sub cloudupload_pubkey {
my ($cgi) = @_;
return cloudupload_status($cgi, '_pubkey');
die("no cloud upload server configurated\n") unless $BSConfig::clouduploadserver;
return cloudupload_status($cgi, '_pubkey') unless $cgi->{'view'};
die("unsupported view '$cgi->{'view'}'\n") if $cgi->{'view'} ne 'info';
my $pk = BSWatcher::rpc("$BSConfig::clouduploadserver/cloudupload/_pubkey");
die("no pubkey configured\n") unless $pk;
my $pubkey = pubkeyinfo($pk);
return ($pubkey, $BSXML::pubkeyinfo);
}

sub cloudupload_kill {
Expand Down Expand Up @@ -6381,7 +6390,7 @@ my $dispatches = [
# cloud upload calls
'POST:/cloudupload $project $repository $arch $package $filename user: target:' => \&cloudupload_create,
'POST:/cloudupload/$job cmd=kill' => \&cloudupload_kill,
'/cloudupload/_pubkey' => \&cloudupload_pubkey,
'/cloudupload/_pubkey view:?' => \&cloudupload_pubkey,
'/cloudupload/$job' => \&cloudupload_status,
'/cloudupload/$job/_log nostream:bool? start:intnum? end:num? view:?' => \&cloudupload_log,
'/cloudupload name:num*' => \&cloudupload_joblist,
Expand Down

0 comments on commit 6232ff0

Please sign in to comment.