-
-
Notifications
You must be signed in to change notification settings - Fork 216
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
API 2.0 #958
API 2.0 #958
Conversation
This is pretty cool. I'll try to play with it soon. |
I suggest we follow https://cloud.google.com/apis/design for the structure and design of the API |
This comment has been minimized.
This comment has been minimized.
I need to get the api_client python application working with the new API. This would mean that all the python apps have been migrated. I've been working on getting the Now/Next that is pulled into liquidsoap working, but then life got a bit hectic. I'm hoping to be able to get back to it in a week or so. Once the new API is working with the api_client and integrated into the installer, we can merge this PR and start looking at rewriting parts of the front-end. I would like to be able to do that piecemeal, so that pages can be done individually without requiring an entire UI re-write before things can be merged. That way development isn't stalled while everyone waits for a new UI to develop against. |
Some of the installation integration is now complete, and development can happen within Vagrant. I have documented the required steps in |
Authentication and writing to the DB both work now. I need to work on the permissions, as they do not work currently. @Robbt we could potentially replace Propel with an interface to this once it is merged... |
@paddatrapper I've been looking into development with Django in general. What do you think about a Django rewrite of Libretime's front end? |
Eventually, that is how I would serve the frontend, but I don't think templating will be the best way forward here. A lot of what we do involves continuous updating (schedule, now/next, what is playing, input switching, etc), which I think works better with a JavaScript frontend with API. It also ensures that the API works and is actively maintained |
I'd go for a static vue based SPA (ie a drf first approach) in the long run... This means that the django server will (if at all) only host static files during dev. On production those can be hosted directly by whatever webserver we end up supporting. From a Vue/frontend PoV we will most likely already start using some Vue components (hosted from PHP) before this aligns with the target architecture where Vue is not only a component but also manages things top-level routing as a real SPA. |
Yeah, I agree with @hairmare. Initially serve the Vue components from PHP and eventually get to the point where all PHP does is serve Vue. At which point Django can serve the Vue and the PHP can be removed |
0930552
to
f246d53
Compare
This is now testable without any special vagrant commands. It should setup and install a init script for There are a couple things to note:
|
PHP can run shell commands but I suspect they will run with the permissions associated with the user that runs the apache process typically www-data. I'm not sure if that would have sufficient permissions but perhaps it could be made to work since it just touches the database. |
Yeah, provided the user can read the config file, it has enough permissions. The command is |
Should in theory be as simple as adding the following command in the installer |
@Robbt thanks. I have added that, though I have no idea how to tell it if actually ran or not... |
We can add the command to the final screen of the configuration wizard, where we ask the user to copy and paste commands into the terminal to start necessary services. |
We could, but I'd rather keep the amount of manual operations to a minimum |
It would be nice if we could eventually incorporate the entire setup process into the installer script, so users would only need to touch the terminal once (with exception to troubleshooting). |
I have implemented guest and admin permissions. It is based on the existing structure and doesn't have any flexibility using Django groups yet (this can be added fairly trivially later once Django manages DB migrations. The API explorer is current only available to admins. This will change as I work on further user types. |
I have fixed support for Guests, Programme Managers and Admins. However, I'm running into issues adding support for DJs' 'own' permissions, i.e. permissions that DJs have to edit objects that they own. This is because ownership is represented in a variety of ways and I'm finding I'm having to special-case every one... For example a DJ has the permission |
I have found a way of doing it by placing the ownership logic in the models. All that is remaining before this is ready to be merged is the rest of the test suite 🎉 |
af98ccf
to
33c5d0e
Compare
Finally, after almost 1.5 years, API 2.0 is ready for review and merge! All permissions are implemented and the API gives users direct access to the DB and media files. You can see the API working in the schedule and file download requests made by the API client |
So far looks good on a clean install. I installed and everything worked. When trying to upgrade an existing debian buster vagrant box by running ./install -fiap
I tried rebooting the vagrant server and that didn't solve anything. 2021-05-19T14:20:53+00:00 ERR (3): localhost [ErrorController.php:54 - errorAction()] - The requested action is not supported.: Zend_Controller_Action_Exception: Action "v2" does not exist and was not trapped in __call() in /vagrant/vendor/zf1s/zend-controller/library/Zend/Controller/Action.php:485 So I suspect something additional needs to be done for people who are upgrading existing libretime instances before we can merge this. Can you explain what part of the existing system this API v2 replaces - ie is pypo using the API v1 in theory able to use this w/o any internal modifications. |
Ok I figured out what is going wrong on upgrade, basically the airtime.conf under /etc/apache2/sites-enabled/ is not upgraded which it needs to be, since the new version contains the proxy information to be able to use the Django based API v2. There is no way to pass this variable via the command line. Add a new check in the install to see if one of the proxy statements is missing from the /etc/apache2/sites-enabled/airtime.conf and if it is then to run the script to replace the apache config. This would work transparent to users that are already used to running ./install -fiap as a means of upgrading their instances. |
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.
It seems to work well except for the need to trigger installation of the new apache config for people upgrading from an existing libretime install.
This replaces the schedule and file download calls made by api_client with v2 equivalent. There is work required to migrate things to use v2 from v1. I plan on doing that incrementally - slowly replacing v1 calls in api_client with v2. Currently there is a Tangentially, we may want to look at uploading api_client to PyPi as an official API client library for LibreTime so that 3rd-party applications can use it eventually. |
Installer update has been added. This will transparently update apache config if the user runs |
Ok, this fix appears to work. People will need to restart the libretime services except for API after running the install. I've also noticed a false upload error that seems to occur the first time I bulk upload tracks. This may or may not be related to the API change and the track it shows an error on seems to actual work so I don't know what is going on there but I wanted to note it in case it ends up being something. I think we could merge this and be in good shape. I didn't actually test much of the API functionality itself but it does appear to work for the sections where we starting using the new API. Does anyone else want to chime in before we merge it ? |
Can you post the error log for reference in the future? |
Ah just noticed that the API unit tests aren't actually run in CI. Fixing that |
Actually, I'm going to leave them out of the CI for the moment and work on getting the GitHub actions CI working. Can integrate it into that without waiting 5 years for a build to complete |
Ok I'm going to merge this as I think it is ready and should work as long as people run install after upgrading to the latest master and we can start to move forward with it. Thanks so much for the work. If I notice the issue with the false error again I'll upload logs. It may just be some kind of AJAX issue and unrelated to this as none of the imports actually failed. |
I have a question about the API for @paddatrapper. As I've been working on building our Vue UI, I've been fiddling with the new API to help me prototype. I've noticed that getting the title of a show on the schedule requires three endpoint requests:
This would result in a ton of information getting sent to the client and a long wait time for the three requests to be received. This especially effects the calendar and weekly schedule widgets. Is there a more efficient method being planned or in the works? It seems that the API is returning tables from the database, but no more. It would be helpful if the app could query the dataset, like GraphQL, so only the data needed would be returned and would require minimal parsing on the client. |
Not currently. That was left as an extension for once we started using the API and experienced where we needed to optimise. We probably should include things like the show_id in the schedule as that is a very common thing that we need |
This is the implementation of the API 2.0 based on discourse and Mattermost discussions. It is a Django application using a REST framework and is designed to use the database defined by Zend. This ensures that the UI can be migrated over in stages without breaking everything else.
It currently just provides GET requests and I'm pretty sure that authentication does not yet work. I have not attempted to integrate this into the install script or have it run under Vagrant yet. That will have to wait at least until #951 is merged.I work on it by running Vagrant to get Zend to initialise the database and then changing the PostgresSQL configuration to listen on all interfaces and allow admin access from the vagrant network. The API can then be installed into a Python virtualenv and run on a non-standard port (I uselocalhost:8083
). It can be accessed in the browser from http://localhost:8083. Later on this will be integrated better and be hidden from the user.After provisioning vagrant and going through the setup, the API can be browsed from http://127.0.0.1:8080/api/v2/
Fixes #1056