Bug 17030

Summary: Configure the REST api on packages install
Product: Koha Reporter: Tomás Cohen Arazi <tomascohen>
Component: PackagingAssignee: Tomás Cohen Arazi <tomascohen>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: abl, benjamin.rokseth, f.demians, jonathan.druart, julian.maurice, kyle, mirko, tomascohen
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on: 17044    
Bug Blocks: 17050    
Attachments: Bug 17030: Enable REST api on packages
Bug 17030: Make REST api available on packages with plack enabled
Bug 17030: (followup) Rewrite rule for Plack
Bug 17030: Make REST api available on packages with plack enabled
Bug 17030: Enable REST api on packages
Bug 17030: Make REST api available on packages with plack enabled
Bug 17030: Enable REST api on packages
Bug 17030: Make REST api available on packages with plack enabled

Description Tomás Cohen Arazi 2016-08-02 15:10:27 UTC
This should've been implemented a while back, so we start taking advantage of the REST api in the UI.
Comment 1 Tomás Cohen Arazi 2016-08-04 14:55:59 UTC Comment hidden (obsolete)
Comment 2 Tomás Cohen Arazi 2016-08-04 14:56:04 UTC Comment hidden (obsolete)
Comment 3 Tomás Cohen Arazi 2016-08-04 15:52:23 UTC Comment hidden (obsolete)
Comment 4 Tomás Cohen Arazi 2016-08-04 17:47:31 UTC Comment hidden (obsolete)
Comment 5 Benjamin Rokseth 2016-08-04 21:27:32 UTC Comment hidden (obsolete)
Comment 6 Benjamin Rokseth 2016-08-04 21:27:36 UTC Comment hidden (obsolete)
Comment 7 Benjamin Rokseth 2016-08-04 21:40:58 UTC
Lovely work Tomas!

Just as we have implemented at OPL, but with a much better apache rewrite...

As for the session timeout, I tested by disabled the syspref SessionRestrictionByIP and never suffered the session timeout issue again.

Relevant log error with :
Use of uninitialized value in string ne at /usr/share/koha/lib/C4/Auth.pm line 1674.

which points to the test:
C4::Context->preference('SessionRestrictionByIP') && $ip ne $ENV{'REMOTE_ADDR'} )

my guess is that session worker translates localhost to 127.0.0.1 and then this test will give false and delete session.

Anyway, this should be a separate bug and not prevent this important one to hit master as soon as possible!
Comment 8 Jonathan Druart 2016-08-05 14:29:46 UTC
Created attachment 54049 [details] [review]
Bug 17030: Enable REST api on packages

This patch enables access to the REST API endpoint on packages setup.
It does so, by patching the shared apache-shared-intranet.conf and
apache-shared-opac.conf.

You can build your own master packages with this patch applied, or just:

- Grab
  debian/templates/apache-shared-intranet.conf
  debian/templates/apache-shared-opac.conf
and overwrite their counterparts in /etc/koha on a packages setup. For example
in kohadevbox.
- Have Koha loaded with all default data
- Create a superlibrarian user for you
- Login to the intranet and the OPAC
- Point your browser to:
  http://localhost:8080/api/v1/patrons/51
=> SUCCESS: You get JSON data, for the patron you requested
  http://localhost:8081/api/v1/patrons/51
=> SUCCESS: You get JSON data, for the patron you requested
- Sign off :-D

Note: I use the HTTPRequester addon for Firefox, re-using the CGISESSID value from the
browser session cookie, in the headers.

Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 9 Jonathan Druart 2016-08-05 14:29:50 UTC
Created attachment 54050 [details] [review]
Bug 17030: Make REST api available on packages with plack enabled

This patch is the starting point for making the REST api available
on Plack.

What it does:
- It creates the /api/v1/app.pl mount point in plack.psgi
- It enables the ProxyPass and ProxyPassReverse directives so it
  is reached through Plack.
- It sets rewrite rules so we can use the 'pretty' urls (i.e.
  /api/v1/patrons instead of /api/v1/app.pl/api/v1/patrons).

To test:
- Grab the following files, and put them in /etc/koha (overwrite the existing ones)
  debian/templates/apache-shared-intranet-plack.conf
  debian/templates/apache-shared-opac-plack.conf
- Tweak your /etc/koha/sites/kohadev/plack.psgi file so the API-related stuff
  is present on your file.
- Make sure Plack is enabled for the instance:
  $ sudo koha-plack --enable kohadev
  $ sudo koha-plack --restart kohadev
  $ sudo service apache2 restart
- Follow the previous patch test plan, but use this URLs (no pretty URL):

  http://localhost:8080/api/v1/app.pl/api/v1/patrons/50
  http://localhost:8081/api/v1/app.pl/api/v1/patrons/50
=> SUCCESS: You get a JSON response from the API [1]
- Not use this URLs:
  http://localhost:8080/api/v1/patrons/50
  http://localhost:8081/api/v1/patrons/50
=> SUCCESS: You get a JSON response from the API [1]
- Sign off :-D

[1] this patch made a bug visible (the session is lost when accessing the API through
Plack) but it shouldn't prevent its inclusion because the API right now is not even available
as default for developers to test or fix it.

Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 10 Kyle M Hall 2016-08-08 13:18:00 UTC
Pushed to master for 16.11, thanks Tomas!
Comment 11 Frédéric Demians 2016-08-08 14:39:37 UTC
Pushed in 16.05. Will be in 16.05.03.
Comment 12 Frédéric Demians 2016-08-24 09:37:01 UTC
Reverted on 16.05.x