Skip to content

correctly pass, merge and check body parameters in local-rpc calls #10601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions ydb/core/viewer/json_local_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,9 @@ class TJsonLocalRpc : public TViewerPipeClient {
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;
}
Expand Down
38 changes: 35 additions & 3 deletions ydb/core/viewer/json_pipe_req.cpp
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand Down
11 changes: 6 additions & 5 deletions ydb/public/api/protos/ydb_scheme.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ 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";

// Create directory.
// All intermediate directories must be created
message MakeDirectoryRequest {
Ydb.Operations.OperationParams operation_params = 1;
string path = 2;
string path = 2 [(required) = true];
}

message MakeDirectoryResponse {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
Loading