| 1 | # | ||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||
| 3 | # | ||
| 4 | # vim: set ts=2 sw=2 tw=0: | ||
| 5 | # vim: set expandtab: | ||
| 6 | |||
| 7 | package Rex::Repositorio::Server::Docker; | ||
| 8 | |||
| 9 | use Mojo::Base 'Mojolicious'; | ||
| 10 | |||
| 11 | our $VERSION = '1.2.1'; # VERSION | ||
| 12 | |||
| 13 | # This method will run once at server start | ||
| 14 | sub startup { | ||
| 15 | my $self = shift; | ||
| 16 | |||
| 17 | $self->plugin("Rex::Repositorio::Server::Helper::Common"); | ||
| 18 | |||
| 19 | $self->app->log( | ||
| 20 | Mojo::Log->new( | ||
| 21 | level => 'debug', | ||
| 22 | ) | ||
| 23 | ); | ||
| 24 | |||
| 25 | $self->plugin("Rex::Repositorio::Server::Helper::RenderFile"); | ||
| 26 | $self->plugin("Rex::Repositorio::Server::Helper::Proxy"); | ||
| 27 | $self->plugin( | ||
| 28 | "Rex::Repositorio::Server::Docker::Mojolicious::Plugin::DockerSession"); | ||
| 29 | |||
| 30 | my $r = $self->routes; | ||
| 31 | $r->get('/')->to('index#index'); | ||
| 32 | $r->get('/v1/_ping')->to('index#ping'); | ||
| 33 | $r->get('/v1/search')->to('search#search'); | ||
| 34 | $r->post('/v1/users')->to('auth#post_user'); | ||
| 35 | |||
| 36 | my $auth_repo_lib = $r->bridge('/v1/repositories/:name') | ||
| 37 | ->to( 'auth#login', repo_namespace => 'library' ); | ||
| 38 | $auth_repo_lib->get('/images')->to('repository#get_repo_images'); | ||
| 39 | $auth_repo_lib->get('/tags')->to('repository#get_repo_tag'); | ||
| 40 | $auth_repo_lib->put('/tags/:tag')->to('repository#put_repo_tag'); | ||
| 41 | $auth_repo_lib->put('/images')->to('repository#put_repo_image'); | ||
| 42 | $auth_repo_lib->put('/')->to('repository#put_repo'); | ||
| 43 | |||
| 44 | my $auth_repo = | ||
| 45 | $r->bridge('/v1/repositories/:repo_namespace/:name')->to('auth#login'); | ||
| 46 | $auth_repo->get('/images')->to('repository#get_repo_images'); | ||
| 47 | $auth_repo->get('/tags')->to('repository#get_repo_tag'); | ||
| 48 | $auth_repo->put('/tags/:tag')->to('repository#put_repo_tag'); | ||
| 49 | $auth_repo->put('/images')->to('repository#put_repo_image'); | ||
| 50 | $auth_repo->put('/')->to('repository#put_repo'); | ||
| 51 | |||
| 52 | my $auth_image = $r->bridge('/v1/images/:name') | ||
| 53 | ->to( 'auth#login', repo_namespace => 'images' ); | ||
| 54 | $auth_image->get('/json')->to('image#get_image'); | ||
| 55 | $auth_image->get('/ancestry')->to('image#get_image_ancestry'); | ||
| 56 | $auth_image->get('/layer')->to('image#get_image_layer'); | ||
| 57 | $auth_image->put('/json')->to('image#put_image'); | ||
| 58 | $auth_image->put('/layer')->to('image#put_image_layer'); | ||
| 59 | $auth_image->put('/checksum')->to('image#put_image_checksum'); | ||
| 60 | } | ||
| 61 | |||
| 62 | 1; |