diff --git a/plugins/restful/adapter_handle.c b/plugins/restful/adapter_handle.c index 6a2b0bee..e7cdeb0b 100644 --- a/plugins/restful/adapter_handle.c +++ b/plugins/restful/adapter_handle.c @@ -62,6 +62,30 @@ void handle_add_adapter(nng_aio *aio) }) } +void handle_update_adapter(nng_aio *aio) +{ + neu_plugin_t *plugin = neu_rest_get_plugin(); + + NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT( + aio, neu_json_update_node_req_t, neu_json_decode_update_node_req, { + int ret = 0; + neu_reqresp_head_t header = { 0 }; + neu_req_update_node_t cmd = { 0 }; + + header.ctx = aio; + header.type = NEU_REQ_UPDATE_NODE; + strcpy(cmd.node, req->name); + strcpy(cmd.new_name, req->new_name); + + ret = neu_plugin_op(plugin, header, &cmd); + if (ret != 0) { + NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, { + neu_http_response(aio, NEU_ERR_IS_BUSY, result_error); + }); + } + }) +} + void handle_del_adapter(nng_aio *aio) { neu_plugin_t *plugin = neu_rest_get_plugin(); diff --git a/plugins/restful/adapter_handle.h b/plugins/restful/adapter_handle.h index 693263d5..924d3403 100644 --- a/plugins/restful/adapter_handle.h +++ b/plugins/restful/adapter_handle.h @@ -24,6 +24,7 @@ #include "adapter.h" void handle_add_adapter(nng_aio *aio); +void handle_update_adapter(nng_aio *aio); void handle_del_adapter(nng_aio *aio); void handle_get_adapter(nng_aio *aio); void handle_get_adapter_resp(nng_aio *aio, neu_resp_get_node_t *nodes); diff --git a/plugins/restful/handle.c b/plugins/restful/handle.c index 913aacb4..21f9cb03 100644 --- a/plugins/restful/handle.c +++ b/plugins/restful/handle.c @@ -216,6 +216,12 @@ static struct neu_http_handler rest_handlers[] = { .url = "/api/v2/node", .value.handler = handle_add_adapter, }, + { + .method = NEU_HTTP_METHOD_PUT, + .type = NEU_HTTP_HANDLER_FUNCTION, + .url = "/api/v2/node", + .value.handler = handle_update_adapter, + }, { .method = NEU_HTTP_METHOD_DELETE, .type = NEU_HTTP_HANDLER_FUNCTION,