@@ -2,34 +2,20 @@ package MetaCPAN::API;
22
33=head1 DESCRIPTION
44
5- This is the API web server interface.
6-
7- # On vagrant VM
8- ./bin/run morbo bin/api.pl
5+ This is the API Minion server.
96
107 # Display information on jobs in queue
118 ./bin/run bin/api.pl minion job -s
129
13- To run the api web server, run the following on one of the servers:
14-
15- # Run the daemon on a local port (tunnel to display on your browser)
16- ./bin/run bin/api.pl daemon
17-
1810=cut
1911
2012use Mojo::Base ' Mojolicious' ;
2113
22- use File::Temp ();
23- use List::Util qw( any ) ;
24- use MetaCPAN::Script::Runner ();
25- use Try::Tiny qw( catch try ) ;
26- use MetaCPAN::Server::Config ();
27- use MetaCPAN::Types::TypeTiny qw( ES ) ;
28-
29- has es => sub {
30- ES-> assert_coerce(
31- MetaCPAN::Server::Config::config()-> {elasticsearch_servers } );
32- };
14+ use File::Temp ();
15+ use List::Util qw( any ) ;
16+ use MetaCPAN::Script::Runner ();
17+ use Try::Tiny qw( catch try ) ;
18+ use MetaCPAN::Server::Config ();
3319
3420sub startup {
3521 my $self = shift ;
@@ -55,7 +41,6 @@ sub startup {
5541 $self -> minion-> add_task(
5642 index_favorite => $self -> _gen_index_task_sub(' favorite' ) );
5743
58- $self -> plugin(' MetaCPAN::API::Plugin::Model' );
5944 $self -> _set_up_routes;
6045}
6146
@@ -116,36 +101,7 @@ sub _set_up_routes {
116101 );
117102
118103 $self -> _set_up_oauth_routes;
119-
120- $admin -> get(' home' )-> to(' admin#home' )-> name(' admin-home' );
121- $admin -> post(' enqueue' )-> to(' queue#enqueue' )-> name(' enqueue' );
122- $admin -> post(' search-identities' )-> to(' admin#search_identities' )
123- -> name(' search-identities' );
124- $admin -> get(' index-release' )-> to(' queue#index_release' )
125- -> name(' index-release' );
126- $admin -> get(' identity-search-form' )-> to(' admin#identity_search_form' )
127- -> name(' identity_search_form' );
128-
129104 $self -> plugin( ' Minion::Admin' => { route => $admin -> any(' /minion' ) } );
130- $self -> plugin(
131- ' OpenAPI' => { url => $self -> home-> rel_file(' root/static/v1.yml' ) } );
132-
133- # This route is for when nginx gets updated to no longer strip the `/v1` path.
134- # By retaining the `/v1` path the OpenAPI spec is picked up and passed
135- # through Mojolicous. The `rewrite` parameter is stripping the `/v1` before
136- # it is passed to Catalyst allowing the previous logic to be followed.
137- $self -> plugin(
138- MountPSGI => {
139- ' /v1' => $self -> home-> child(' app.psgi' )-> to_string,
140- rewrite => 1
141- }
142- );
143-
144- # XXX Catch cases when `v1` has been stripped by nginx until migration is complete
145- # XXX then this path can be removed.
146- $self -> plugin(
147- MountPSGI => { ' /' => $self -> home-> child(' app.psgi' )-> to_string } );
148-
149105}
150106
151107sub _is_admin {
@@ -205,43 +161,12 @@ sub _set_up_oauth_routes {
205161 $c -> session( is_logged_in => 1 );
206162 $c -> session( github_username => $username );
207163 if ( $self -> _is_admin($username ) ) {
208- $c -> session( github_username => $username );
209164 $c -> redirect_to(' /admin' );
210165 return ;
211166 }
212167 $c -> redirect_to( $self -> config-> {front_end_url } );
213168 },
214169 );
215-
216- $self -> plugin(
217- ' Web::Auth' ,
218- module => ' Google' ,
219- key => $oauth -> {google }-> {key },
220- secret => $oauth -> {google }-> {secret },
221- user_info => 1,
222- on_finished => sub {
223- my ( $c , $access_token , $account_info ) = @_ ;
224- my $username = $account_info -> {login };
225- $c -> session( is_logged_in => 1 );
226- $c -> session( google_username => $username );
227- $c -> redirect_to( $self -> config-> {front_end_url } );
228- },
229- );
230-
231- $self -> plugin(
232- ' Web::Auth' ,
233- module => ' Twitter' ,
234- key => $oauth -> {twitter }-> {key },
235- secret => $oauth -> {twitter }-> {secret },
236- user_info => 1,
237- on_finished => sub {
238- my ( $c , $access_token , $access_secret , $account_info ) = @_ ;
239- my $username = $account_info -> {screen_name };
240- $c -> session( is_logged_in => 1 );
241- $c -> session( twitter_username => $username );
242- $c -> redirect_to( $self -> config-> {front_end_url } );
243- },
244- );
245170}
246171
2471721;
0 commit comments