summaryrefslogtreecommitdiff
path: root/rest-api
AgeCommit message (Collapse)Author
2013-07-03Update events to use Swagger 1.3 subtyping, and related aftermathDavid M. Lee
This patch started with the simple idea of changing the /events data model to be more sane. The original model would send out events like: { "stasis_start": { "args": [], "channel": { ... } } } The event discriminator was the field name instead of being a value in the object, due to limitations in how Swagger 1.1 could model objects. While technically sufficient in communicating event information, it was really difficult to deal with in terms of client side JSON handling. This patch takes advantage of a proposed extension[1] to Swagger which allows type variance through the use of a discriminator field. This had a domino effect that made this a surprisingly large patch. [1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ In changing the models, I also had to change the swagger_model.py processor so it can handle the type discriminator and subtyping. I took that a big step forward, and using that information to generate an ari_model module, which can validate a JSON object against the Swagger model. The REST and WebSocket generators were changed to take advantage of the validators. If compiled with AST_DEVMODE enabled, JSON objects that don't match their corresponding models will not be sent out. For REST API calls, a 500 Internal Server response is sent. For WebSockets, the invalid JSON message is replaced with an error message. Since this took over about half of the job of the existing JSON generators, and the .to_json virtual function on messages took over the other half, I reluctantly removed the generators. The validators turned up all sorts of errors and inconsistencies in our data models, and the code. These were cleaned up, with checks in the code generator avoid some of the consistency problems in the future. * The model for a channel snapshot was trimmed down to match the information sent via AMI. Many of the field being sent were not useful in the general case. * The model for a bridge snapshot was updated to be more consistent with the other ARI models. Another impact of introducing subtyping was that the swagger-codegen documentation generator was insufficient (at least until it catches up with Swagger 1.2). I wanted it to be easier to generate docs for the API anyways, so I ported the wiki pages to use the Asterisk Swagger generator. In the process, I was able to clean up many of the model links, which would occasionally give inconsistent results on the wiki. I also added error responses to the wiki docs, making the wiki documentation more complete. Finally, since Stasis-HTTP will now be named Asterisk REST Interface (ARI), any new functions and files I created carry the ari_ prefix. I changed a few stasis_http references to ari where it was non-intrusive and made sense. (closes issue ASTERISK-21885) Review: https://reviewboard.asterisk.org/r/2639/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03Shuffle RESTful URL's around.David M. Lee
This patch moves the RESTful URL's around to more appropriate locations for release. The /stasis URL's are moved to /ari, since Asterisk REST Interface was a more appropriate name than Stasis-HTTP. (Most of the code still has stasis_http references, but they will be cleaned up after there are no more outstanding branches that would have merge conflicts with such a change). A larger change was moving the ARI events WebSocket off of the shared /ws URL to its permanent home on /ari/events. The Swagger code generator was extended to handle "upgrade: websocket" and "websocketProtocol:" attributes on an operation. The WebSocket module was modified to better handle WebSocket servers that have a single registered protocol handler. If a client connections does not specify the Sec-WebSocket-Protocol header, and the server has a single protocol handler registered, the WebSocket server will go ahead and accept the client for that subprotocol. (closes issue ASTERISK-21857) Review: https://reviewboard.asterisk.org/r/2621/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393528 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-01ARI: Implement channel dial.Jason Parker
This creates a new outbound channel, and bridges it to a channel already in the Stasis application. (closes issue ASTERISK-21620) Review: https://reviewboard.asterisk.org/r/2634/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393326 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-06-28Change ARI originate to also allow dialing an exten/context/priority.Jason Parker
The old way didn't make much sense, so some of the fields were repurposed. (closes issue ASTERISK-21658) Review: https://reviewboard.asterisk.org/r/2626/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393144 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-06-26ARI: Add support for continuing to a different location in dialplan.Jason Parker
This allows going elsewhere in the dialplan, so that the location can be specified after exiting the Stasis application. (closes issue ASTERISK-21870) Review: https://reviewboard.asterisk.org/r/2644/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@392987 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-06-24Index installed sounds and implement ARI sounds queriesKinsey Moore
This adds support for stasis/sounds and stasis/sounds/{ID} queries via the Asterisk RESTful Interface (ARI, formerly Stasis-HTTP). The following changes have been made to accomplish this: * A modular indexer was created for local media. * A new function to get an ast_format associated with a file extension was added. * Modifications were made to the built-in HTTP server so that URI decoding could be deferred to the URI handler when necessary. * The Stasis-HTTP sounds JSON documentation was modified to handle cases where multiple languages are installed in different formats. * Register and Unregister events for formats were added to the system topic. (closes issue ASTERISK-21584) (closes issue ASTERISK-21585) Review: https://reviewboard.asterisk.org/r/2507/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@392700 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-06-21Fix typo.Jason Parker
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@392464 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-06-18Fix bridge snapshot conversion to JSONKinsey Moore
This makes ast_bridge_snapshot_to_json conform to the swagger Bridge model by adding the two fields it required. Review: https://reviewboard.asterisk.org/r/2583/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@392116 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-06-14Revert parts of r391855 that were not ready to go in to trunkKinsey Moore
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@391856 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-06-14Fix two more possible crashes in CELKinsey Moore
These are locations that should return valid snapshots, but need to be handled if not. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@391855 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-06-10Stasis-HTTP: Flesh out bridge-related capabilitiesKinsey Moore
This adds support for Stasis applications to receive bridge-related messages when the application shows interest in a given bridge. To supplement this work and test it, this also adds support for the following bridge-related Stasis-HTTP functionality: * GET stasis/bridges * GET stasis/bridges/{bridgeId} * POST stasis/bridges * DELETE stasis/bridges/{bridgeId} * POST stasis/bridges/{bridgeId}/addChannel * POST stasis/bridges/{bridgeId}/removeChannel Review: https://reviewboard.asterisk.org/r/2572/ (closes issue ASTERISK-21711) (closes issue ASTERISK-21621) (closes issue ASTERISK-21622) (closes issue ASTERISK-21623) (closes issue ASTERISK-21624) (closes issue ASTERISK-21625) (closes issue ASTERISK-21626) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@391199 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-06-07Implement ARI POST to /channels, to originate a call.Jason Parker
(closes issue ASTERISK-21617) Review: https://reviewboard.asterisk.org/r/2597/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@390885 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-23This patch adds support for controlling a playback operation from theDavid M. Lee
Asterisk REST interface. This adds the /playback/{playbackId}/control resource, which may be POSTed to to pause, unpause, reverse, forward or restart the media playback. Attempts to control a playback that is not currently playing will either return a 404 Not Found (because the playback object no longer exists) or a 409 Conflict (because the playback object is still in the queue to be played). This patch also adds skipms and offsetms parameters to the /channels/{channelId}/play resource. (closes issue ASTERISK-21587) Review: https://reviewboard.asterisk.org/r/2559 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@389603 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-23This patch implements the REST API's for POST /channels/{channelId}/playDavid M. Lee
and GET /playback/{playbackId}. This allows an external application to initiate playback of a sound on a channel while the channel is in the Stasis application. /play commands are issued asynchronously, and return immediately with the URL of the associated /playback resource. Playback commands queue up, playing in succession. The /playback resource shows the state of a playback operation as enqueued, playing or complete. (Although the operation will only be in the 'complete' state for a very short time, since it is almost immediately freed up). (closes issue ASTERISK-21283) (closes issue ASTERISK-21586) Review: https://reviewboard.asterisk.org/r/2531/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@389587 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-21Merge in the bridge_construction branch to make the system use the Bridging API.Richard Mudgett
Breaks many things until they can be reworked. A partial list: chan_agent chan_dahdi, chan_misdn, chan_iax2 native bridging app_queue COLP updates DTMF attended transfers Protocol attended transfers git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@389378 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-10Add channel events for res_stasis appsKinsey Moore
This change adds a framework in res_stasis for handling events from channel topics. JSON event generation and validation code is created from event documentation in rest-api/api-docs/events.json to assist in JSON event generation, ensure consistency, and ensure that accurate documentation is available for ALL events that are received by res_stasis applications. The userevent application has been refactored along with the code that handles userevent channel blob events to pass the headers as key/value pairs in the JSON blob. As a side-effect, app_userevent now handles duplicate keys by overwriting the previous value. Review: https://reviewboard.asterisk.org/r/2428/ (closes issue ASTERISK-21180) Patch-By: Kinsey Moore <kmoore@digium.com> git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@388275 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-08Initial support for endpoints.David M. Lee
An endpoint is an external device/system that may offer/accept channels to/from Asterisk. While this is a very useful concept for end users, it is surprisingly not a core concept within Asterisk itself. This patch defines ast_endpoint as a separate object, which channel drivers may use to expose their concept of an endpoint. As the channel driver creates channels, it can use ast_endpoint_add_channel() to associate channels to the endpoint. This updated the endpoint appropriately, and forwards all of the channel's events to the endpoint's topic. In order to avoid excessive locking on the endpoint object itself, the mutable state is not accessible via getters. Instead, you can create a snapshot using ast_endpoint_snapshot_create() to get a consistent snapshot of the internal state. This patch also includes a set of topics and messages associated with endpoints, and implementations of the endpoint-related RESTful API. chan_sip was updated to create endpoints with SIP peers, but the state of the endpoints is not updated with the state of the peer. Along for the ride in this patch is a Stasis test API. This is a stasis_message_sink object, which can be subscribed to a Stasis topic. It has functions for blocking while waiting for conditions in the message sink to be fulfilled. (closes issue ASTERISK-21421) Review: https://reviewboard.asterisk.org/r/2492/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-04-22This patch adds a RESTful HTTP interface to Asterisk.David M. Lee
The API itself is documented using Swagger, a lightweight mechanism for documenting RESTful API's using JSON. This allows us to use swagger-ui to provide executable documentation for the API, generate client bindings in different languages, and generate a lot of the boilerplate code for implementing the RESTful bindings. The API docs live in the rest-api/ directory. The RESTful bindings are generated from the Swagger API docs using a set of Mustache templates. The code generator is written in Python, and uses Pystache. Pystache has no dependencies, and be installed easily using pip. Code generation code lives in rest-api-templates/. The generated code reduces a lot of boilerplate when it comes to handling HTTP requests. It also helps us have greater consistency in the REST API. (closes issue ASTERISK-20891) Review: https://reviewboard.asterisk.org/r/2376/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@386232 65c4cc65-6c06-0410-ace0-fbb531ad65f3