Summary: | Serve static files from plugins through the API | ||
---|---|---|---|
Product: | Koha | Reporter: | Tomás Cohen Arazi <tomascohen> |
Component: | Plugin architecture | Assignee: | Agustín Moyano <agustinmoyano> |
Status: | CLOSED FIXED | QA Contact: | Kyle M Hall <kyle> |
Severity: | new feature | ||
Priority: | P5 - low | CC: | agustinmoyano, arthur.suzuki, black23, fridolin.somers, hayleypelham, josef.moravec, katrin.fischer, kyle, lucas, martin.renvoize, nick |
Version: | Main | ||
Hardware: | All | ||
OS: | All | ||
Change sponsored?: | Sponsored | Patch complexity: | Trivial patch |
Documentation contact: | Documentation submission: | ||
Text to go in the release notes: |
This new feature allows plugin authors to serve static files through the API without the requirement to tweak the Apache configuration files. Routes to the static files tree are automatically loaded from a specially crafted file the plugin authors need to include in the distributed .kpz files.
**Warning**: Care should be taken when installing any plugins and only plugins you trust should be used.
|
Version(s) released in: |
19.11.00, 19.05.08
|
Bug Depends on: | 22834 | ||
Bug Blocks: | |||
Attachments: |
Bug 22835: Serve plugin static files through API
Bug 22835: Serve plugin static files through API Bug 22835: (follow-up) Remove unwanted warn Bug 22835: Serve plugin static files through API Bug 22835: (follow-up) Remove unwanted warn Bug 22835: (follow-up) Remove comented code Bug 22835: Serve plugin static files through API Bug 22835: (follow-up) Remove unwanted warn Bug 22835: (follow-up) Remove comented code |
Description
Tomás Cohen Arazi
2019-05-02 18:59:16 UTC
Created attachment 89262 [details] [review] Bug 22835: Serve plugin static files through API This patch serves static files declared within plugins. To declare static files the plugin must implement the method 'static_routes' which retrieves the spec of static file routes to add to the API. Once those routes are added to the API, the become available through the /api/v1/contrib/<api_namespace>/static/<path>/<to>/<file>/<filename> endpoint. To test: 1) Install bug-22835-plugin.kpz 2) Point your browser to /api/v1/contrib/kitchensink/static/static_files/mm.gif CHECK => No file is served 3) Apply this patch 4) restart_all 5) Repeat step 2. SUCCESS => File is served! 6) Sign off > 1) Install bug-22835-plugin.kpz KPZ available at https://github.com/agmoyano/koha-plugin-kitchen-sink/releases/download/bug-22835/bug-22835-plugin.kpz Created attachment 89263 [details] [review] Bug 22835: Serve plugin static files through API This patch serves static files declared within plugins. To declare static files the plugin must implement the method 'static_routes' which retrieves the spec of static file routes to add to the API. Once those routes are added to the API, the become available through the /api/v1/contrib/<api_namespace>/static/<path>/<to>/<file>/<filename> endpoint. To test: 1) Install bug-22835-plugin.kpz 2) Point your browser to /api/v1/contrib/kitchensink/static/static_files/mm.gif CHECK => No file is served 3) Apply this patch 4) restart_all 5) Repeat step 2. SUCCESS => File is served! 6) Sign off Sponsored-by: Theke Created attachment 89280 [details] [review] Bug 22835: (follow-up) Remove unwanted warn Created attachment 89663 [details] [review] Bug 22835: Serve plugin static files through API This patch serves static files declared within plugins. To declare static files the plugin must implement the method 'static_routes' which retrieves the spec of static file routes to add to the API. Once those routes are added to the API, the become available through the /api/v1/contrib/<api_namespace>/static/<path>/<to>/<file>/<filename> endpoint. To test: 1) Install bug-22835-plugin.kpz 2) Point your browser to /api/v1/contrib/kitchensink/static/static_files/mm.gif CHECK => No file is served 3) Apply this patch 4) restart_all 5) Repeat step 2. SUCCESS => File is served! 6) Sign off Sponsored-by: Theke Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> Created attachment 89664 [details] [review] Bug 22835: (follow-up) Remove unwanted warn Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> Works as expected, the gif provided as an example is very rewarding, thanks ;) Made my day! The patch contains some unexplained commented code : - @plugins = grep { $_->api_namespace } @plugins; + #@plugins = grep { $_->api_namespace } @plugins; + # $c->res->headers->content_type("image/jpeg"); Created attachment 89812 [details] [review] Bug 22835: (follow-up) Remove comented code I like the idea behind this, but it feels somewhat wrong that it's under the /api path.. it's not really serving an api. Trying to work out if we could instead use `/contrib/<plugin_namespace>/path/to/file.js` or something similar. Yes, it's one more route in the vhosts we'd need to ship, but would serve the same purpose of not requiring server admins to mess with the vhost for each plugin. What do you say Tomás ? (In reply to Fridolin SOMERS from comment #11) > What do you say Tomás ? I haven't pondered the effort required to implement a whole new endpoint in our current complex setup - New Apache config - New plack tweaks - New mojo app and controller? It all seems too much given the simplicity of this dev. I'd rather just allow an array of openapi specs and leave to the plugin authors the decision of making it a real API or not. The main dev here is the controller class for static files and I think it is pretty cool :-) Thomas, I definitely agree with you :) Plus I've played a bit around the plugin system during this KohaCon! Tweaking into Plack + Apache/Nginx configuration quickly becomes a nightmare whenever several <plugin_dir> are defined in koha-conf.xml Also : I've had the opportunity to meet in person with Martin (great to meet IRL btw!!!) who also agreed on the greatness of the feature and saying we might just ignore his comment and take another opportunity to refactor/improve later on. Let's push it for QA! \o/ Arthur (In reply to Arthur Suzuki from comment #13) > Thomas, I definitely agree with you :) > > Plus I've played a bit around the plugin system during this KohaCon! > Tweaking into Plack + Apache/Nginx configuration quickly becomes a nightmare > whenever several <plugin_dir> are defined in koha-conf.xml > > Also : I've had the opportunity to meet in person with Martin (great to meet > IRL btw!!!) who also agreed on the greatness of the feature and saying we > might just ignore his comment and take another opportunity to > refactor/improve later on. > > Let's push it for QA! \o/ > Arthur So now you made our day :-D We don't really use 'pushed for QA' (meaning pushed to a branch in the repo) right now. Changing it to the more fitting "Signed off" :) Created attachment 90148 [details] [review] Bug 22835: Serve plugin static files through API This patch serves static files declared within plugins. To declare static files the plugin must implement the method 'static_routes' which retrieves the spec of static file routes to add to the API. Once those routes are added to the API, the become available through the /api/v1/contrib/<api_namespace>/static/<path>/<to>/<file>/<filename> endpoint. To test: 1) Install bug-22835-plugin.kpz 2) Point your browser to /api/v1/contrib/kitchensink/static/static_files/mm.gif CHECK => No file is served 3) Apply this patch 4) restart_all 5) Repeat step 2. SUCCESS => File is served! 6) Sign off Sponsored-by: Theke Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Created attachment 90149 [details] [review] Bug 22835: (follow-up) Remove unwanted warn Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Created attachment 90150 [details] [review] Bug 22835: (follow-up) Remove comented code Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Nice work! Pushed to master for 19.11.00 Yeay! Thanks everyone! \o/ And now we talk nicely to Fridolin and ask if he's going to carry forward my policy during tenure as RMaint to backport non-breaking Plugin and API enhancement/new features to the stable branch ;) I believe in this case the whole dependency list should apply without issue and not cause any regressions. Oh, that would be great :) he's already in the CC's list btw! > This development allows plugins to serve static files through the API without the requirement to tweak the Apache configuration files. Routes to the static files tree are automatically loaded from a specially crafted file the plugin authors need to include in the distributed .kpz files.
Could we document this somewhere?
@fridolin can we backport this? (In reply to Tomás Cohen Arazi from comment #24) > @fridolin can we backport this? I'd love to but I'm actually on last release. You will have to see this with next maintainer. Best regards, It applies to the 19.05.x branch! And works! backported to 19.05.x for 19.05.08 Enhancement will not be backported to 18.11.x series. |