Skip to content

Commit 857b20e

Browse files
authored
correctly pass, merge and check body parameters in local-rpc calls (#10601)
1 parent 7b9578c commit 857b20e

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

ydb/core/viewer/json_local_rpc.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,9 @@ class TJsonLocalRpc : public TViewerPipeClient {
128128
ReplyAndPassAway(GetHTTPBADREQUEST("text/plain", e.what()));
129129
return false;
130130
}
131-
} else {
132-
const auto& params(Event->Get()->Request.GetParams());
133-
Params2Proto(params, request);
134131
}
132+
const auto& params(Event->Get()->Request.GetParams());
133+
Params2Proto(params, request);
135134
if (!ValidateRequest(request)) {
136135
return false;
137136
}

ydb/core/viewer/json_pipe_req.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "json_pipe_req.h"
2+
#include <library/cpp/json/json_reader.h>
23
#include <library/cpp/json/json_writer.h>
34

45
namespace NKikimr::NViewer {
@@ -25,7 +26,28 @@ TViewerPipeClient::TViewerPipeClient(IViewer* viewer, NMon::TEvHttpInfo::TPtr& e
2526
: Viewer(viewer)
2627
, Event(ev)
2728
{
28-
InitConfig(Event->Get()->Request.GetParams());
29+
TCgiParameters params = Event->Get()->Request.GetParams();
30+
if (Event->Get()->Request.GetHeader("Content-Type") == "application/json") {
31+
NJson::TJsonValue jsonData;
32+
if (NJson::ReadJsonTree(Event->Get()->Request.GetPostContent(), &jsonData)) {
33+
if (jsonData.IsMap()) {
34+
for (const auto& [key, value] : jsonData.GetMap()) {
35+
switch (value.GetType()) {
36+
case NJson::EJsonValueType::JSON_STRING:
37+
case NJson::EJsonValueType::JSON_INTEGER:
38+
case NJson::EJsonValueType::JSON_UINTEGER:
39+
case NJson::EJsonValueType::JSON_DOUBLE:
40+
case NJson::EJsonValueType::JSON_BOOLEAN:
41+
params.InsertUnescaped(key, value.GetStringRobust());
42+
break;
43+
default:
44+
break;
45+
}
46+
}
47+
}
48+
}
49+
}
50+
InitConfig(params);
2951
NWilson::TTraceId traceId;
3052
TStringBuf traceparent = Event->Get()->Request.GetHeader("traceparent");
3153
if (traceparent) {
@@ -645,10 +667,20 @@ TRequestState TViewerPipeClient::GetRequest() const {
645667
}
646668

647669
void TViewerPipeClient::ReplyAndPassAway(TString data, const TString& error) {
670+
TString message = error;
648671
Send(Event->Sender, new NMon::TEvHttpInfoRes(data, 0, NMon::IEvHttpInfoRes::EContentType::Custom));
672+
if (message.empty()) {
673+
TStringBuf dataParser(data);
674+
if (dataParser.NextTok(' ') == "HTTP/1.1") {
675+
TStringBuf code = dataParser.NextTok(' ');
676+
if (code.size() == 3 && code[0] != '2') {
677+
message = dataParser.NextTok('\n');
678+
}
679+
}
680+
}
649681
if (Span) {
650-
if (error) {
651-
Span.EndError(error);
682+
if (message) {
683+
Span.EndError(message);
652684
} else {
653685
Span.EndOk();
654686
}

ydb/public/api/protos/ydb_scheme.proto

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ package Ydb.Scheme;
55
option java_package = "com.yandex.ydb.scheme";
66
option java_outer_classname = "SchemeOperationProtos";
77

8+
import "ydb/public/api/protos/annotations/validation.proto";
89
import "ydb/public/api/protos/ydb_common.proto";
910
import "ydb/public/api/protos/ydb_operation.proto";
1011

1112
// Create directory.
1213
// All intermediate directories must be created
1314
message MakeDirectoryRequest {
1415
Ydb.Operations.OperationParams operation_params = 1;
15-
string path = 2;
16+
string path = 2 [(required) = true];
1617
}
1718

1819
message MakeDirectoryResponse {
@@ -22,7 +23,7 @@ message MakeDirectoryResponse {
2223
// Remove directory
2324
message RemoveDirectoryRequest {
2425
Ydb.Operations.OperationParams operation_params = 1;
25-
string path = 2;
26+
string path = 2 [(required) = true];
2627
}
2728

2829
message RemoveDirectoryResponse {
@@ -32,7 +33,7 @@ message RemoveDirectoryResponse {
3233
// List directory
3334
message ListDirectoryRequest {
3435
Ydb.Operations.OperationParams operation_params = 1;
35-
string path = 2;
36+
string path = 2 [(required) = true];
3637
}
3738

3839
message ListDirectoryResponse {
@@ -93,7 +94,7 @@ message ListDirectoryResult {
9394
// Returns information about object with given path
9495
message DescribePathRequest {
9596
Ydb.Operations.OperationParams operation_params = 1;
96-
string path = 2;
97+
string path = 2 [(required) = true];
9798
}
9899

99100
message DescribePathResponse {
@@ -121,7 +122,7 @@ message PermissionsAction {
121122
// Modify permissions of given object
122123
message ModifyPermissionsRequest {
123124
Ydb.Operations.OperationParams operation_params = 1;
124-
string path = 2;
125+
string path = 2 [(required) = true];
125126
repeated PermissionsAction actions = 3;
126127
// Clear all permissions on the object for all subjects
127128
bool clear_permissions = 4;

0 commit comments

Comments
 (0)