-
Notifications
You must be signed in to change notification settings - Fork 203
Bug 2061445 - Migrate Bugzilla (system info) REST resource to native Mojo API #2719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| # | ||
| # This Source Code Form is "Incompatible With Secondary Licenses", as | ||
| # defined by the Mozilla Public License, v. 2.0. | ||
|
|
||
| package Bugzilla::API::V1::Bugzilla; | ||
|
|
||
| use 5.10.1; | ||
| use Mojo::Base qw( Mojolicious::Controller ); | ||
|
|
||
| use DateTime; | ||
| use Try::Tiny; | ||
|
|
||
| use Bugzilla::Constants; | ||
| use Bugzilla::Logging; | ||
| use Bugzilla::Util qw(datetime_from); | ||
|
|
||
| sub setup_routes { | ||
| my ($class, $r) = @_; | ||
|
|
||
| $r->get('/version')->to('V1::Bugzilla#version'); | ||
| $r->get('/extensions')->to('V1::Bugzilla#extensions'); | ||
| $r->get('/timezone')->to('V1::Bugzilla#timezone'); | ||
| $r->get('/time')->to('V1::Bugzilla#time'); | ||
| $r->get('/jobqueue_status')->to('V1::Bugzilla#jobqueue_status'); | ||
|
|
||
| foreach my $path (qw(/version /extensions /timezone /time /jobqueue_status)) { | ||
| $r->options($path)->to('V1::Bugzilla#options'); | ||
| } | ||
| } | ||
|
|
||
| sub options { | ||
| my ($self) = @_; | ||
|
|
||
| $self->res->headers->header('Allow' => 'GET'); | ||
| $self->res->headers->header('Access-Control-Allow-Methods' => 'GET'); | ||
|
|
||
| return $self->rendered(200); | ||
| } | ||
|
|
||
| sub version { | ||
| my ($self) = @_; | ||
| Bugzilla->usage_mode(USAGE_MODE_MOJO_REST); | ||
|
|
||
| return $self->render(json => {version => BUGZILLA_VERSION}); | ||
| } | ||
|
|
||
| sub extensions { | ||
| my ($self) = @_; | ||
| Bugzilla->usage_mode(USAGE_MODE_MOJO_REST); | ||
|
|
||
| my %extensions; | ||
| foreach my $extension (@{Bugzilla->extensions}) { | ||
| $extensions{$extension->NAME} = {version => $extension->VERSION || 0}; | ||
| } | ||
|
|
||
| return $self->render(json => {extensions => \%extensions}); | ||
| } | ||
|
|
||
| sub timezone { | ||
| my ($self) = @_; | ||
| Bugzilla->usage_mode(USAGE_MODE_MOJO_REST); | ||
|
|
||
| # All Webservices return times in UTC; Use UTC here for backwards compat. | ||
| return $self->render(json => {timezone => '+0000'}); | ||
| } | ||
|
|
||
| sub time { | ||
| my ($self) = @_; | ||
| Bugzilla->usage_mode(USAGE_MODE_MOJO_REST); | ||
|
|
||
| # All Webservices return times in UTC; Use UTC here for backwards compat. | ||
| my $dbh = Bugzilla->dbh; | ||
| my $db_time = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); | ||
| $db_time = datetime_from($db_time, 'UTC')->iso8601(); | ||
| my $now_utc = DateTime->now()->iso8601(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. response shape changes here: the legacy endpoint ran these through |
||
|
|
||
| return $self->render( | ||
| json => { | ||
| db_time => $db_time, | ||
| web_time => $now_utc, | ||
| web_time_utc => $now_utc, | ||
| tz_name => 'UTC', | ||
| tz_offset => '+0000', | ||
| tz_short_name => 'UTC', | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| sub jobqueue_status { | ||
| my ($self) = @_; | ||
|
|
||
| my $user = $self->bugzilla->login; | ||
| $user->id || return $self->user_error('login_required'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. usage_mode is still USAGE_MODE_REST here (set by suggest moving line 98 above line 95, and adding an anonymous-request case to |
||
|
|
||
| Bugzilla->usage_mode(USAGE_MODE_MOJO_REST); | ||
|
|
||
| my $dbh = Bugzilla->dbh; | ||
| my $query = q{ | ||
| SELECT | ||
| COUNT(*) AS total, | ||
| COALESCE( | ||
| (SELECT COUNT(*) | ||
| FROM ts_error | ||
| WHERE ts_error.jobid = j.jobid | ||
| ) | ||
| , 0) AS errors | ||
| FROM ts_job j | ||
| INNER JOIN ts_funcmap f | ||
| ON f.funcid = j.funcid | ||
| GROUP BY errors | ||
| }; | ||
|
|
||
| my $status; | ||
| try { | ||
| $status = $dbh->selectrow_hashref($query); | ||
| } | ||
| catch { | ||
| ERROR($_); | ||
| return $self->code_error('jobqueue_status_error'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
eg |
||
| }; | ||
|
|
||
| return $self->render( | ||
| json => { | ||
| errors => 0 + ($status->{errors} // 0), | ||
| total => 0 + ($status->{total} // 0), | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| 1; | ||
|
|
||
| __END__ | ||
|
|
||
| =head1 NAME | ||
|
|
||
| Bugzilla::API::V1::Bugzilla - Global functions for the webservice interface. | ||
|
|
||
| =head1 DESCRIPTION | ||
|
|
||
| This provides functions that tell you about Bugzilla in general. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extensionsandtimewere not in the oldLOGIN_EXEMPTlist, so the legacy server calledBugzilla->login()(LOGIN_NORMAL) for them, meaning they were gated when therequireloginparam is on. neither handler calls$self->bugzilla->loginnow, so both become anonymously readable under requirelogin. Teams.pm calls$self->bugzilla->login()for exactly this reason even though it does not use the user