Skip to content

Commit 3b280bb

Browse files
authored
support relative paths in scheme service (#9846)
1 parent d2299da commit 3b280bb

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

ydb/core/viewer/json_handlers_scheme.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace NKikimr::NViewer {
55

66
void InitSchemeDirectoryHandler(TJsonHandlers& handlers) {
7-
handlers.AddHandler("/scheme/directory", new TJsonSchemeDirectoryHandler());
7+
handlers.AddHandler("/scheme/directory", new TJsonSchemeDirectoryHandler(), 2);
88
}
99

1010
void InitSchemeJsonHandlers(TJsonHandlers& jsonHandlers) {

ydb/core/viewer/json_local_rpc.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class TJsonLocalRpc : public TViewerPipeClient {
3030

3131
protected:
3232
using TBase::ReplyAndPassAway;
33+
using TRequestProtoType = TProtoRequest;
3334
std::vector<HTTP_METHOD> AllowedMethods = {};
3435
TAutoPtr<TEvLocalRpcPrivate::TEvGrpcRequestResult<TProtoResult>> Result;
3536
NThreading::TFuture<TProtoResponse> RpcFuture;
@@ -40,10 +41,10 @@ class TJsonLocalRpc : public TViewerPipeClient {
4041
}
4142

4243
TJsonLocalRpc(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev)
43-
: TBase(viewer, ev, TProtoRequest::descriptor()->name())
44+
: TBase(viewer, ev, TRequestProtoType::descriptor()->name())
4445
{}
4546

46-
void Params2Proto(const TCgiParameters& params, TProtoRequest& request) {
47+
void Params2Proto(const TCgiParameters& params, TRequestProtoType& request) {
4748
using google::protobuf::Descriptor;
4849
using google::protobuf::Reflection;
4950
using google::protobuf::FieldDescriptor;
@@ -95,12 +96,12 @@ class TJsonLocalRpc : public TViewerPipeClient {
9596
}
9697
}
9798

98-
bool ValidateProto(TProtoRequest& request) {
99+
virtual bool ValidateRequest(TRequestProtoType& request) {
99100
using google::protobuf::Descriptor;
100101
using google::protobuf::Reflection;
101102
using google::protobuf::FieldDescriptor;
102-
const Descriptor& descriptor = *TProtoRequest::GetDescriptor();
103-
const Reflection& reflection = *TProtoRequest::GetReflection();
103+
const Descriptor& descriptor = *TRequestProtoType::GetDescriptor();
104+
const Reflection& reflection = *TRequestProtoType::GetReflection();
104105
for (int idx = 0; idx < descriptor.field_count(); ++idx) {
105106
const FieldDescriptor* field = descriptor.field(idx);
106107
const auto& options(field->options());
@@ -116,7 +117,7 @@ class TJsonLocalRpc : public TViewerPipeClient {
116117
return true;
117118
}
118119

119-
bool Params2Proto(TProtoRequest& request) {
120+
bool Params2Proto(TRequestProtoType& request) {
120121
auto postData = Event->Get()->Request.GetPostContent();
121122
if (!postData.empty()) {
122123
try {
@@ -130,13 +131,13 @@ class TJsonLocalRpc : public TViewerPipeClient {
130131
const auto& params(Event->Get()->Request.GetParams());
131132
Params2Proto(params, request);
132133
}
133-
if (!ValidateProto(request)) {
134+
if (!ValidateRequest(request)) {
134135
return false;
135136
}
136137
return true;
137138
}
138139

139-
void SendGrpcRequest(TProtoRequest&& request) {
140+
void SendGrpcRequest(TRequestProtoType&& request) {
140141
// TODO(xenoxeno): pass trace id
141142
RpcFuture = NRpcService::DoLocalRpc<TRpcEv>(std::move(request), Database, Event->Get()->UserToken, TlsActivationContext->ActorSystem());
142143
RpcFuture.Subscribe([actorId = TBase::SelfId(), actorSystem = TlsActivationContext->ActorSystem()]
@@ -173,7 +174,7 @@ class TJsonLocalRpc : public TViewerPipeClient {
173174
if (TBase::NeedToRedirect()) {
174175
return;
175176
}
176-
TProtoRequest request;
177+
TRequestProtoType request;
177178
if (!Params2Proto(request)) {
178179
return;
179180
}

ydb/core/viewer/scheme_directory.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,29 @@ using TSchemeDirectoryDeleteRpc = TJsonLocalRpc<Ydb::Scheme::RemoveDirectoryRequ
3232

3333
template<typename LocalRpcType>
3434
class TSchemeDirectoryRequest : public LocalRpcType {
35-
public:
35+
protected:
3636
using TBase = LocalRpcType;
37+
using TRequestProtoType = TBase::TRequestProtoType;
38+
using TBase::Database;
3739

40+
public:
3841
TSchemeDirectoryRequest(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev)
3942
: TBase(viewer, ev)
4043
{}
44+
45+
bool ValidateRequest(TRequestProtoType& request) override {
46+
if (TBase::ValidateRequest(request)) {
47+
if (Database && request.path()) {
48+
TString path = request.path();
49+
if (!path.empty() && path[0] != '/') {
50+
path = Database + "/" + path;
51+
request.set_path(path);
52+
}
53+
}
54+
return true;
55+
}
56+
return false;
57+
}
4158
};
4259

4360
class TJsonSchemeDirectoryHandler : public TJsonHandler<TSchemeDirectory> {

0 commit comments

Comments
 (0)