mirror of
https://github.com/emqx/neuron.git
synced 2026-10-17 04:40:42 +08:00
feat(restful): template add tags api
This commit is contained in:
@@ -112,6 +112,9 @@ static struct neu_http_handler cors_handler[] = {
|
||||
{
|
||||
.url = "/api/v2/template",
|
||||
},
|
||||
{
|
||||
.url = "/api/v2/template/tag",
|
||||
},
|
||||
};
|
||||
|
||||
static struct neu_http_handler rest_handlers[] = {
|
||||
@@ -357,6 +360,12 @@ static struct neu_http_handler rest_handlers[] = {
|
||||
.url = "/api/v2/template",
|
||||
.value.handler = handle_get_template,
|
||||
},
|
||||
{
|
||||
.method = NEU_HTTP_METHOD_POST,
|
||||
.type = NEU_HTTP_HANDLER_FUNCTION,
|
||||
.url = "/api/v2/template/tag",
|
||||
.value.handler = handle_add_template_tags,
|
||||
},
|
||||
};
|
||||
|
||||
void neu_rest_handler(const struct neu_http_handler **handlers, uint32_t *size)
|
||||
|
||||
@@ -197,6 +197,7 @@ static int dashb_plugin_request(neu_plugin_t * plugin,
|
||||
(neu_resp_get_driver_group_t *) data);
|
||||
break;
|
||||
case NEU_RESP_ADD_TAG:
|
||||
case NEU_RESP_ADD_TEMPLATE_TAG:
|
||||
handle_add_tags_resp(header->ctx, (neu_resp_add_tag_t *) data);
|
||||
break;
|
||||
case NEU_RESP_UPDATE_TAG:
|
||||
|
||||
@@ -157,6 +157,7 @@ void handle_add_template(nng_aio *aio)
|
||||
}
|
||||
|
||||
if (0 != ret) {
|
||||
neu_reqresp_template_fini(&cmd);
|
||||
NEU_JSON_RESPONSE_ERROR(
|
||||
ret, { neu_http_response(aio, ret, result_error); });
|
||||
}
|
||||
@@ -319,3 +320,55 @@ void handle_get_templates_resp(nng_aio *aio, neu_resp_get_templates_t *resp)
|
||||
neu_resp_get_templates_fini(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
static int send_template_tags_req(nng_aio *aio, neu_reqresp_type_e type,
|
||||
neu_json_template_mod_tags_req_t *req)
|
||||
{
|
||||
neu_plugin_t *plugin = neu_rest_get_plugin();
|
||||
|
||||
int ret = 0;
|
||||
int i = 0;
|
||||
|
||||
neu_reqresp_head_t header = {
|
||||
.ctx = aio,
|
||||
.type = type,
|
||||
};
|
||||
|
||||
neu_req_add_template_tag_t cmd = { 0 };
|
||||
strcpy(cmd.tmpl, req->tmpl);
|
||||
strcpy(cmd.group, req->group);
|
||||
|
||||
cmd.tags = calloc(req->n_tag, sizeof(neu_datatag_t));
|
||||
if (NULL == cmd.tags) {
|
||||
return NEU_ERR_EINTERNAL;
|
||||
}
|
||||
|
||||
for (i = 0; i < req->n_tag; i++) {
|
||||
cmd.n_tag += 1;
|
||||
if (0 != (ret = set_tag_by_json(&cmd.tags[i], &req->tags[i]))) {
|
||||
neu_req_add_template_tag_fini(&cmd);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 != neu_plugin_op(plugin, header, &cmd)) {
|
||||
neu_req_add_template_tag_fini(&cmd);
|
||||
return NEU_ERR_IS_BUSY;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void handle_add_template_tags(nng_aio *aio)
|
||||
{
|
||||
NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT(
|
||||
aio, neu_json_template_mod_tags_req_t,
|
||||
neu_json_decode_template_mod_tags_req, {
|
||||
int ret =
|
||||
send_template_tags_req(aio, NEU_REQ_ADD_TEMPLATE_TAG, req);
|
||||
if (0 != ret) {
|
||||
NEU_JSON_RESPONSE_ERROR(
|
||||
ret, { neu_http_response(aio, ret, result_error); });
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -30,4 +30,6 @@ void handle_get_template(nng_aio *aio);
|
||||
void handle_get_template_resp(nng_aio *aio, neu_resp_get_template_t *resp);
|
||||
void handle_get_templates_resp(nng_aio *aio, neu_resp_get_templates_t *resp);
|
||||
|
||||
void handle_add_template_tags(nng_aio *aio);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user