diff options
author | Matt Jordan <mjordan@digium.com> | 2015-07-08 16:39:35 -0500 |
---|---|---|
committer | Matt Jordan <mjordan@digium.com> | 2015-07-16 20:38:57 -0500 |
commit | 254d07b15b6f6a741c1293cf9d26a2a235e795ed (patch) | |
tree | 0a1d7d9e98f5bd166fd74f575ea6d46c8ddf2b53 /res/ari/ari_model_validators.c | |
parent | af9ee2910d4f791243fa9c6ef98dd53264acc445 (diff) |
ARI: Add support for push configuration of dynamic object
This patch adds support for push configuration of dynamic, i.e.,
sorcery, objects in Asterisk. It adds three new REST API calls to the
'asterisk' resource:
* GET /asterisk/{configClass}/{objectType}/{id}: retrieve the current
object given its ID. This returns back a list of ConfigTuples, which
define the fields and their present values that make up the object.
* PUT /asterisk/{configClass}/{objectType}/{id}: create or update an
object. A body may be passed with the request that contains fields to
populate in the object. The same format as what is retrieved using
the GET operation is used for the body, save that we specify that the
list of fields to update are contained in the "fields" attribute.
* DELETE /asterisk/{configClass}/{objectType}/{id}: remove a dynamic
object from its backing storage.
Note that the success/failure of these operations is somewhat
configuration dependent, i.e., you must be using a sorcery wizard that
supports the operation in question. If a sorcery wizard does not support
the create or delete mechanisms, then the REST API call will fail with a
403 forbidden.
ASTERISK-25238 #close
Change-Id: I28cd5c7bf6f67f8e9e437ff097f8fd171d30ff5c
Diffstat (limited to 'res/ari/ari_model_validators.c')
-rw-r--r-- | res/ari/ari_model_validators.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c index ca72f93bd..fa16aea20 100644 --- a/res/ari/ari_model_validators.c +++ b/res/ari/ari_model_validators.c @@ -308,6 +308,60 @@ ari_validator ast_ari_validate_config_info_fn(void) return ast_ari_validate_config_info; } +int ast_ari_validate_config_tuple(struct ast_json *json) +{ + int res = 1; + struct ast_json_iter *iter; + int has_attribute = 0; + int has_value = 0; + + for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) { + if (strcmp("attribute", ast_json_object_iter_key(iter)) == 0) { + int prop_is_valid; + has_attribute = 1; + prop_is_valid = ast_ari_validate_string( + ast_json_object_iter_value(iter)); + if (!prop_is_valid) { + ast_log(LOG_ERROR, "ARI ConfigTuple field attribute failed validation\n"); + res = 0; + } + } else + if (strcmp("value", ast_json_object_iter_key(iter)) == 0) { + int prop_is_valid; + has_value = 1; + prop_is_valid = ast_ari_validate_string( + ast_json_object_iter_value(iter)); + if (!prop_is_valid) { + ast_log(LOG_ERROR, "ARI ConfigTuple field value failed validation\n"); + res = 0; + } + } else + { + ast_log(LOG_ERROR, + "ARI ConfigTuple has undocumented field %s\n", + ast_json_object_iter_key(iter)); + res = 0; + } + } + + if (!has_attribute) { + ast_log(LOG_ERROR, "ARI ConfigTuple missing required field attribute\n"); + res = 0; + } + + if (!has_value) { + ast_log(LOG_ERROR, "ARI ConfigTuple missing required field value\n"); + res = 0; + } + + return res; +} + +ari_validator ast_ari_validate_config_tuple_fn(void) +{ + return ast_ari_validate_config_tuple; +} + int ast_ari_validate_module(struct ast_json *json) { int res = 1; |