* Start of a JSON API to get information about a specific build.

E.g. http://server/build/1341335/api/get-info returns a JSON 
  record containing information about the build.
This commit is contained in:
Eelco Dolstra 2011-09-15 08:27:17 +00:00
parent d72538e641
commit d8a7ca67f4
5 changed files with 28 additions and 11 deletions

View file

@ -11,6 +11,7 @@ with pkgs;
perlPackages.CatalystViewTT perlPackages.CatalystViewTT
perlPackages.CatalystEngineHTTPPrefork perlPackages.CatalystEngineHTTPPrefork
perlPackages.CatalystViewDownload perlPackages.CatalystViewDownload
perlPackages.CatalystViewJSON
perlPackages.XMLSimple perlPackages.XMLSimple
perlPackages.IPCRun perlPackages.IPCRun
perlPackages.IOCompressBzip2 perlPackages.IOCompressBzip2

View file

@ -43,7 +43,13 @@ __PACKAGE__->config(
}, },
}, },
}, },
} },
'View::JSON' => {
expose_stash => qr/^json/,
},
'Plugin::Session' => {
expires => 3600 * 24 * 2,
},
); );
__PACKAGE__->setup(); __PACKAGE__->setup();

View file

@ -11,6 +11,8 @@ use JSON::Any;
use DateTime; use DateTime;
use Digest::SHA qw(sha256_hex); use Digest::SHA qw(sha256_hex);
# !!! Rewrite this to use View::JSON.
sub api : Chained('/') PathPart('api') CaptureArgs(0) { sub api : Chained('/') PathPart('api') CaptureArgs(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
$c->response->content_type('application/json'); $c->response->content_type('application/json');
@ -163,16 +165,6 @@ sub nrrunning : Chained('api') PathPart('nrrunning') Args(0) {
$c->forward('Hydra::View::Plain'); $c->forward('Hydra::View::Plain');
} }
sub ts {
my ($nr, $period) = @_;
my @arr ;
return @arr;
}
sub nrbuilds : Chained('api') PathPart('nrbuilds') Args(0) { sub nrbuilds : Chained('api') PathPart('nrbuilds') Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
my $nr = $c->request->params->{nr} ; my $nr = $c->request->params->{nr} ;

View file

@ -10,6 +10,7 @@ use File::stat;
use Data::Dump qw(dump); use Data::Dump qw(dump);
use Nix; use Nix;
sub build : Chained('/') PathPart CaptureArgs(1) { sub build : Chained('/') PathPart CaptureArgs(1) {
my ($self, $c, $id) = @_; my ($self, $c, $id) = @_;
@ -29,6 +30,7 @@ sub build : Chained('/') PathPart CaptureArgs(1) {
$c->stash->{project} = $c->stash->{build}->project; $c->stash->{project} = $c->stash->{build}->project;
} }
sub view_build : Chained('build') PathPart('') Args(0) { sub view_build : Chained('build') PathPart('') Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
@ -215,6 +217,7 @@ sub download_by_type : Chained('build') PathPart('download-by-type') {
$c->res->redirect(defaultUriForProduct($self, $c, $product, @path)); $c->res->redirect(defaultUriForProduct($self, $c, $product, @path));
} }
sub contents : Chained('build') PathPart Args(1) { sub contents : Chained('build') PathPart Args(1) {
my ($self, $c, $productnr) = @_; my ($self, $c, $productnr) = @_;
@ -308,6 +311,7 @@ sub buildtimedeps : Chained('build') PathPart('buildtime-deps') {
$c->res->content_type('image/png'); # !!! $c->res->content_type('image/png'); # !!!
} }
sub deps : Chained('build') PathPart('deps') { sub deps : Chained('build') PathPart('deps') {
my ($self, $c) = @_; my ($self, $c) = @_;
@ -539,4 +543,15 @@ sub clone_submit : Chained('build') PathPart('clone/submit') Args(0) {
} }
sub get_info : Chained('build') PathPart('api/get-info') Args(0) {
my ($self, $c) = @_;
my $build = $c->stash->{build};
# !!! strip the json prefix
$c->stash->{jsonBuildId} = $build->id;
$c->stash->{jsonDrvPath} = $build->drvpath;
$c->stash->{jsonOutPath} = $build->outpath;
$c->forward('View::JSON');
}
1; 1;

View file

@ -0,0 +1,3 @@
package Hydra::View::JSON;
use base qw(Catalyst::View::JSON);
1;