forked from markxfl/kazoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HELP-40835: storage updates (2600hz#5385)
* remove UI metadata * start to define http handler schema * update spec and naming * log the handler being used * update the attachments to accept HTTP handler * handle decoding error response * make sure the verb is properly created * create per-test IDs * remove redundant call * start to exercise the storage API * add take_value/{2,3} to kz_json * add httpd server for recv http requests from kazoo * start httpd * verify returned contents match * add come cleanup help. start httpd with log id * add logging metadata to help correlate logs * refactor compose voicemail into smaller functions * some dialyzing * separate storing meta from store url creation * move encoding multipart to kz_http_util * handle undefined owner_id * add a blocking wait for requests to come in * create a vmbox and message to trigger storage * handle storage put_attachment return * fix binding key for storage plan cache * add http storage backend doc * vmbox API test module * test that we recv the MP3 on our http server * make sure vmboxes are started * fix code complaint * update schema doc and what not * dialyzer updates * add empty response headers on error * formatting * spelling updates * handle multipart response * build multipart body if configured to do so * ask for multipart bodies * use cowlib boundary creator * validate multipart response * document multipart * update schema generated docs * separate concerns a bit * set default headers if not supplied by the handler module * detect the crossbar url/port better * accept a port argument * log successful store * when fetching owner's plan, if missing, try account's * add default resp_headers pre-load storage ids for account (2600hz#5375) add type for storage keys missing export from kzd_users missed copyright update
- Loading branch information
1 parent
cb03a8c
commit 41c9065
Showing
46 changed files
with
1,531 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# HTTP Storage Backend | ||
|
||
## Using the HTTP storage backend | ||
|
||
When you maintain your own web server, you can opt to store attachments like voicemail messages on your system (letting you provide additional services to your customers). | ||
|
||
### Create the storage backend | ||
|
||
First, create a UUID: | ||
|
||
```shell | ||
echo $(tr -dc a-f0-9 < /dev/urandom | dd bs=32 count=1 2> /dev/null) | ||
403f90f67d1b71341f2ea6426eed3d90 | ||
``` | ||
|
||
This UUID will be your reference to your HTTP server in the storage plan. | ||
|
||
There are two main pieces of the storage plan to configure now: the `attachments` where you'll define the HTTP server information, and the `plan` where you'll configure KAZOO to use your HTTP server. | ||
|
||
For instance, you can store new voicemails with a storage config like the following: | ||
```json | ||
{ | ||
"data": { | ||
"attachments": { | ||
"{UUID}": { | ||
"handler": "http", | ||
"name": "My HTTP server", | ||
"settings": { | ||
"url": "http://my.http.server:37635/some_prefix", | ||
"verb": "POST" | ||
} | ||
} | ||
}, | ||
"plan": { | ||
"modb": { | ||
"types": { | ||
"mailbox_message": { | ||
"attachments": { | ||
"handler": "{UUID}" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
PUT-ing this to `/v2/accounts/{ACCOUNT_ID}/storage` will result in your web server receiving a PUT/POST to `/some_prefix/{ACCOUNT_ID}/{TEST_ID}/{RANDOM}_test_credentials_file.txt`. The text file will contain something like `some random content: {RANDOM}`. Respond with a 201 to let KAZOO know the reception occurred. | ||
|
||
Next, KAZOO will attempt to GET that attachment back. Your web server will see a request for `/some_prefix/{ACCOUNT_ID}/{TEST_ID}/{RANDOM}_test_credentials_file.txt` and expects to see a 200 OK and the contents. | ||
|
||
If both the PUT/POST and the GET are successful, the API request to create the storage config will return a 201. You can now safely delete `{RANDOM}_test_credentials_file.txt` from your web server. | ||
|
||
### On save | ||
|
||
Now, when a voicemail is saved to the account, your web server will receive a PUT/POST request to `PUT req /some_prefix/{ACCOUNT_ID}/{MESSAGE_ID}/uploaded_file_{TIMESTAMP}.mp3` with the binary data as the body. Your web server will then need to respond with a 201 to let KAZOO know storing the data was successful. | ||
|
||
!!!note save processing of the file for a later process; return the 201 to KAZOO as soon as your server confirms storing the file was successful locally. | ||
|
||
### Multipart requests | ||
|
||
If you want to receive both the binary data and the JSON metadata, you can add `"send_multipart":true` to the settings of the handler: | ||
|
||
```json | ||
"{UUID}": { | ||
"handler": "http", | ||
"name": "My HTTP server", | ||
"settings": { | ||
"url": "http://my.http.server:37635/some_prefix", | ||
"verb": "POST", | ||
"send_multipart":true | ||
} | ||
} | ||
``` | ||
|
||
On save, KAZOO will send a `multipart/mixed` request that will something like: | ||
|
||
``` | ||
{BOUNDARY} | ||
content-type: application/json | ||
{"name":"mailbox 1010 message MM-DD-YYYY HH:MM:SS","description":"voicemail message with media","source_type":"voicemail","source_id":"{SOURCE_ID}","media_source":"recording","streamable":true,"utc_seconds":{TIMESTAMP},"metadata":{"timestamp":{TIMESTAMP},"from":"{SIP_FROM}","to":"{SIP_TO}","caller_id_number":"{CID_NUMBER}","caller_id_name":"{CID_NAME}","call_id":"{CALL_ID}","folder":"new","length":1,"media_id":"{MEDIA_ID}"},"id":"{MEDIA_ID}"} | ||
{BOUNDARY} | ||
content-type: audio/mp3 | ||
{BINARY_DATA} | ||
{BOUNDARY} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.