Skip to content
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

Bin finalization and bin-related API #41

Merged
merged 6 commits into from Sep 2, 2016
Merged

Conversation

foxbunny
Copy link
Contributor

@foxbunny foxbunny commented Sep 1, 2016

The bin finalization works by tagging the current set of candidates with bin ID. By tagging the candidates, they automatically disappear from the candidate list since the candidate list only considers items that are not tagged yet. This is a change from the previous version where candidates could be tagged with a unfinalized bin. The finalization is performed by the ContentItem.finalize_candidates(bin_id) class method.

API endpoints are added to facilitate remote management of bin finalization and retrieval of bin information. Access control for the API is separate from the normal authentication mechanism, and has no relation to the user accounts. HTTP basic authentication is used to simplify scripting. Because of this, the calls are expected to be performed over SSL.

The ACL for the API calls is stored in a JSON file, and the file is read on every request to verify the identity of the caller. This file can be modified using the newly added apiuser command.

To generate a new user:

broadcast --conf conf/development.ini apiuser <user>

The command will print out the API token, which is a randomly generated 32-digit hex number. The command is also used to update the password.

API endpoints can be tested using curl.

To finalize the bin:

curl -i --data "" user:pass@localhost:8080/api/v1/bins/

To retrieve a list of bins:

curl -i user:pass@localhost:8080/api/v1/bins/

To retrieve full information for last bin:

curl -i user:pass@localhost:8080/api/v1/bins/last

Files can be downloaded using the following command:

curl -i user:pass@localhost:8080/api/v1/download/<item-id>

NOTE: API endpoints are using JSON. During serialization, big lists of items are created. While this works reasonably well in test scenario on the development machine, using XML and similar formats that can be streamed might prove more efficient in production. Whether we should switch or not is still TBD.

Branko Vukelic added 6 commits September 1, 2016 20:40
Since bin will be finalized in an instant, thre's no time difference between
'open' and 'close'. This patch removes the 'closed' timestamp column. The
new semantic is that 'bins' are basically snapshots of the candidate list at
the time of finalizing.

Signed-off-by: Branko Vukelic <branko@outernet.is>
This commit factors the code that builds the WHERE clause for binless item
lookup so that it can be used in other places where it may be required (pun
intentional).

Signed-off-by: Branko Vukelic <branko@outernet.is>
Signed-off-by: Branko Vukelic <branko@outernet.is>
This commit adds a new command, 'apiuser', and APIMixin route mixin. Both rely
on the newly introduced app.api_acl option, which points to a (not necessarily
existing) JSON file that would contain the ACL for API calls.

The API endpoints are expected to use APIMixin as part of the class definition.
The authentication is, therefore, completely separate from the normal user
database.

Credentials for API calls is created using the 'apiuser' command. The command
takes only username as its argument, and will generate a random 32-digit hex
number as the access token / password.

Signed-off-by: Branko Vukelic <branko@outernet.is>
This commit adds a to_dict() method to the Model class, which allows returning
the instance data as a dict, combining the data and extras dicts into one. The
new dict is created by copying the data dict.

Signed-off-by: Branko Vukelic <branko@outernet.is>
This commit modifies the ContentItem and Bin models to support bin finalization
and features required for retrieval of bin data. 4 API endpoints are also added
via the broadcast.routes.api module, which allow finalizing the bin, retrieval
of bin list, retrieval of item lists for bins (by ID or the last one), and
retrieval of file data for individual items.

Signed-off-by: Branko Vukelic <branko@outernet.is>
@n0phx n0phx merged commit c75bf0c into wip-overhaul Sep 2, 2016
@n0phx n0phx deleted the feature/bin-finalize branch September 2, 2016 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants