diff options
author | Alexey Efimov <xeno@ydb.tech> | 2024-10-18 21:16:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-18 19:16:24 +0000 |
commit | 857b20e06a4717c0b6cad0f64cb53a226f1ce894 (patch) | |
tree | 7fb73f14a44c2e8df1ec0b9557d76cd3b17e9a9c | |
parent | 7b9578cf0d27b671e203cf4f36551b593927c25c (diff) | |
download | ydb-857b20e06a4717c0b6cad0f64cb53a226f1ce894.tar.gz |
correctly pass, merge and check body parameters in local-rpc calls (#10601)
-rw-r--r-- | ydb/core/viewer/json_local_rpc.h | 5 | ||||
-rw-r--r-- | ydb/core/viewer/json_pipe_req.cpp | 38 | ||||
-rw-r--r-- | ydb/public/api/protos/ydb_scheme.proto | 11 |
3 files changed, 43 insertions, 11 deletions
diff --git a/ydb/core/viewer/json_local_rpc.h b/ydb/core/viewer/json_local_rpc.h index b9d9677684..9e9df12320 100644 --- a/ydb/core/viewer/json_local_rpc.h +++ b/ydb/core/viewer/json_local_rpc.h @@ -128,10 +128,9 @@ public: ReplyAndPassAway(GetHTTPBADREQUEST("text/plain", e.what())); return false; } - } else { - const auto& params(Event->Get()->Request.GetParams()); - Params2Proto(params, request); } + const auto& params(Event->Get()->Request.GetParams()); + Params2Proto(params, request); if (!ValidateRequest(request)) { return false; } diff --git a/ydb/core/viewer/json_pipe_req.cpp b/ydb/core/viewer/json_pipe_req.cpp index b2fc57d9b2..52777ea849 100644 --- a/ydb/core/viewer/json_pipe_req.cpp +++ b/ydb/core/viewer/json_pipe_req.cpp @@ -1,4 +1,5 @@ #include "json_pipe_req.h" +#include <library/cpp/json/json_reader.h> #include <library/cpp/json/json_writer.h> namespace NKikimr::NViewer { @@ -25,7 +26,28 @@ TViewerPipeClient::TViewerPipeClient(IViewer* viewer, NMon::TEvHttpInfo::TPtr& e : Viewer(viewer) , Event(ev) { - InitConfig(Event->Get()->Request.GetParams()); + TCgiParameters params = Event->Get()->Request.GetParams(); + if (Event->Get()->Request.GetHeader("Content-Type") == "application/json") { + NJson::TJsonValue jsonData; + if (NJson::ReadJsonTree(Event->Get()->Request.GetPostContent(), &jsonData)) { + if (jsonData.IsMap()) { + for (const auto& [key, value] : jsonData.GetMap()) { + switch (value.GetType()) { + case NJson::EJsonValueType::JSON_STRING: + case NJson::EJsonValueType::JSON_INTEGER: + case NJson::EJsonValueType::JSON_UINTEGER: + case NJson::EJsonValueType::JSON_DOUBLE: + case NJson::EJsonValueType::JSON_BOOLEAN: + params.InsertUnescaped(key, value.GetStringRobust()); + break; + default: + break; + } + } + } + } + } + InitConfig(params); NWilson::TTraceId traceId; TStringBuf traceparent = Event->Get()->Request.GetHeader("traceparent"); if (traceparent) { @@ -645,10 +667,20 @@ TRequestState TViewerPipeClient::GetRequest() const { } void TViewerPipeClient::ReplyAndPassAway(TString data, const TString& error) { + TString message = error; Send(Event->Sender, new NMon::TEvHttpInfoRes(data, 0, NMon::IEvHttpInfoRes::EContentType::Custom)); + if (message.empty()) { + TStringBuf dataParser(data); + if (dataParser.NextTok(' ') == "HTTP/1.1") { + TStringBuf code = dataParser.NextTok(' '); + if (code.size() == 3 && code[0] != '2') { + message = dataParser.NextTok('\n'); + } + } + } if (Span) { - if (error) { - Span.EndError(error); + if (message) { + Span.EndError(message); } else { Span.EndOk(); } diff --git a/ydb/public/api/protos/ydb_scheme.proto b/ydb/public/api/protos/ydb_scheme.proto index 4ddcafc40a..e7ddf9ce28 100644 --- a/ydb/public/api/protos/ydb_scheme.proto +++ b/ydb/public/api/protos/ydb_scheme.proto @@ -5,6 +5,7 @@ package Ydb.Scheme; option java_package = "com.yandex.ydb.scheme"; option java_outer_classname = "SchemeOperationProtos"; +import "ydb/public/api/protos/annotations/validation.proto"; import "ydb/public/api/protos/ydb_common.proto"; import "ydb/public/api/protos/ydb_operation.proto"; @@ -12,7 +13,7 @@ import "ydb/public/api/protos/ydb_operation.proto"; // All intermediate directories must be created message MakeDirectoryRequest { Ydb.Operations.OperationParams operation_params = 1; - string path = 2; + string path = 2 [(required) = true]; } message MakeDirectoryResponse { @@ -22,7 +23,7 @@ message MakeDirectoryResponse { // Remove directory message RemoveDirectoryRequest { Ydb.Operations.OperationParams operation_params = 1; - string path = 2; + string path = 2 [(required) = true]; } message RemoveDirectoryResponse { @@ -32,7 +33,7 @@ message RemoveDirectoryResponse { // List directory message ListDirectoryRequest { Ydb.Operations.OperationParams operation_params = 1; - string path = 2; + string path = 2 [(required) = true]; } message ListDirectoryResponse { @@ -93,7 +94,7 @@ message ListDirectoryResult { // Returns information about object with given path message DescribePathRequest { Ydb.Operations.OperationParams operation_params = 1; - string path = 2; + string path = 2 [(required) = true]; } message DescribePathResponse { @@ -121,7 +122,7 @@ message PermissionsAction { // Modify permissions of given object message ModifyPermissionsRequest { Ydb.Operations.OperationParams operation_params = 1; - string path = 2; + string path = 2 [(required) = true]; repeated PermissionsAction actions = 3; // Clear all permissions on the object for all subjects bool clear_permissions = 4; |