summaryrefslogtreecommitdiff
path: root/res/ari
diff options
context:
space:
mode:
authorScott Emidy <jemidy@digium.com>2015-08-06 15:18:04 -0500
committerScott Emidy <jemidy@digium.com>2015-08-06 17:41:11 -0500
commit78364132ce94d9ded24ae6e6ab44b97d256b506d (patch)
treea4277262f837478a57ae5a6cc03347dddbb35f30 /res/ari
parentc07fa843ec49a114473fe3b5609d00f80ace1b3d (diff)
ARI: Deleting log channels
An http request can be sent to delete a log channel in Asterisk. The command "curl -v -u user:pass -X DELETE 'http://localhost:8088 /ari/asterisk/logging/mylog'" can be run in the terminal to access the newly implemented functionally for ARI. * Able to delete log channels using ARI ASTERISK-25252 Change-Id: Id6eeb54ebcc511595f0418d586ff55914bc3aae6
Diffstat (limited to 'res/ari')
-rw-r--r--res/ari/ari_model_validators.c49
-rw-r--r--res/ari/ari_model_validators.h4
-rw-r--r--res/ari/resource_asterisk.c23
-rw-r--r--res/ari/resource_asterisk.h13
4 files changed, 79 insertions, 10 deletions
diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c
index 120daf546..26e9b74b7 100644
--- a/res/ari/ari_model_validators.c
+++ b/res/ari/ari_model_validators.c
@@ -366,18 +366,19 @@ int ast_ari_validate_log_channel(struct ast_json *json)
{
int res = 1;
struct ast_json_iter *iter;
- int has_logging_levels = 0;
+ int has_configuration = 0;
int has_name = 0;
+ int has_status = 0;
+ int has_type = 0;
for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
- if (strcmp("logging_levels", ast_json_object_iter_key(iter)) == 0) {
+ if (strcmp("configuration", ast_json_object_iter_key(iter)) == 0) {
int prop_is_valid;
- has_logging_levels = 1;
- prop_is_valid = ast_ari_validate_list(
- ast_json_object_iter_value(iter),
- ast_ari_validate_string);
+ has_configuration = 1;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
if (!prop_is_valid) {
- ast_log(LOG_ERROR, "ARI LogChannel field logging_levels failed validation\n");
+ ast_log(LOG_ERROR, "ARI LogChannel field configuration failed validation\n");
res = 0;
}
} else
@@ -391,6 +392,26 @@ int ast_ari_validate_log_channel(struct ast_json *json)
res = 0;
}
} else
+ if (strcmp("status", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_status = 1;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI LogChannel field status failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_type = 1;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI LogChannel field type failed validation\n");
+ res = 0;
+ }
+ } else
{
ast_log(LOG_ERROR,
"ARI LogChannel has undocumented field %s\n",
@@ -399,8 +420,8 @@ int ast_ari_validate_log_channel(struct ast_json *json)
}
}
- if (!has_logging_levels) {
- ast_log(LOG_ERROR, "ARI LogChannel missing required field logging_levels\n");
+ if (!has_configuration) {
+ ast_log(LOG_ERROR, "ARI LogChannel missing required field configuration\n");
res = 0;
}
@@ -409,6 +430,16 @@ int ast_ari_validate_log_channel(struct ast_json *json)
res = 0;
}
+ if (!has_status) {
+ ast_log(LOG_ERROR, "ARI LogChannel missing required field status\n");
+ res = 0;
+ }
+
+ if (!has_type) {
+ ast_log(LOG_ERROR, "ARI LogChannel missing required field type\n");
+ res = 0;
+ }
+
return res;
}
diff --git a/res/ari/ari_model_validators.h b/res/ari/ari_model_validators.h
index fa393448d..b181506d2 100644
--- a/res/ari/ari_model_validators.h
+++ b/res/ari/ari_model_validators.h
@@ -1302,8 +1302,10 @@ ari_validator ast_ari_validate_application_fn(void);
* - attribute: string (required)
* - value: string (required)
* LogChannel
- * - logging_levels: List[string] (required)
+ * - configuration: string (required)
* - name: string (required)
+ * - status: string (required)
+ * - type: string (required)
* Module
* - description: string (required)
* - name: string (required)
diff --git a/res/ari/resource_asterisk.c b/res/ari/resource_asterisk.c
index e227951e2..d2e77f504 100644
--- a/res/ari/resource_asterisk.c
+++ b/res/ari/resource_asterisk.c
@@ -653,6 +653,29 @@ void ast_ari_asterisk_rotate_log(struct ast_variable *headers,
ast_ari_response_no_content(response);
}
+void ast_ari_asterisk_delete_log(struct ast_variable *headers,
+ struct ast_ari_asterisk_delete_log_args *args,
+ struct ast_ari_response *response)
+{
+ int res;
+
+ ast_assert(response != NULL);
+
+ res = ast_logger_remove_channel(args->log_channel_name);
+
+ if (res == AST_LOGGER_FAILURE) {
+ ast_ari_response_error(response, 404, "Not Found",
+ "Log channel does not exist");
+ return;
+ } else if (res == AST_LOGGER_ALLOC_ERROR) {
+ ast_ari_response_error(response, 500, "Internal Server Error",
+ "Allocation failed");
+ return;
+ }
+
+ ast_ari_response_no_content(response);
+}
+
void ast_ari_asterisk_get_global_var(struct ast_variable *headers,
struct ast_ari_asterisk_get_global_var_args *args,
struct ast_ari_response *response)
diff --git a/res/ari/resource_asterisk.h b/res/ari/resource_asterisk.h
index e271b0547..00f463cee 100644
--- a/res/ari/resource_asterisk.h
+++ b/res/ari/resource_asterisk.h
@@ -194,6 +194,19 @@ struct ast_ari_asterisk_reload_module_args {
* \param[out] response HTTP response
*/
void ast_ari_asterisk_reload_module(struct ast_variable *headers, struct ast_ari_asterisk_reload_module_args *args, struct ast_ari_response *response);
+/*! Argument struct for ast_ari_asterisk_delete_log() */
+struct ast_ari_asterisk_delete_log_args {
+ /*! Log channels name */
+ const char *log_channel_name;
+};
+/*!
+ * \brief Deletes a log channel.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void ast_ari_asterisk_delete_log(struct ast_variable *headers, struct ast_ari_asterisk_delete_log_args *args, struct ast_ari_response *response);
/*! Argument struct for ast_ari_asterisk_rotate_log() */
struct ast_ari_asterisk_rotate_log_args {
/*! Log channel's name */