Skip to content

Commit a3b340a

Browse files
fedor-mironadameat
authored andcommitted
YQL-18117: Implement block tz date (#3366)
1 parent b530042 commit a3b340a

File tree

18 files changed

+869
-146
lines changed

18 files changed

+869
-146
lines changed

ydb/core/viewer/json_handlers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct TJsonHandlers {
7474
json << ',';
7575
}
7676
TString name = itJson->first;
77-
json << "\"/" << name << '"' << ":{";
77+
json << "\"/viewer" << name << '"' << ":{";
7878
json << "\"get\":{";
7979
json << "\"tags\":[\"" << TTagInfo::TagName << "\"],";
8080
json << "\"produces\":[\"application/json\"],";

ydb/core/viewer/json_whoami.h

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22
#include <ydb/library/actors/core/actor_bootstrapped.h>
33
#include <ydb/library/actors/core/mon.h>
4+
#include <library/cpp/json/json_value.h>
5+
#include <library/cpp/json/json_writer.h>
46
#include <ydb/core/base/tablet_pipe.h>
57
#include <ydb/library/services/services.pb.h>
68
#include <ydb/core/tx/schemeshard/schemeshard.h>
@@ -14,7 +16,6 @@ using namespace NActors;
1416

1517
class TJsonWhoAmI : public TActorBootstrapped<TJsonWhoAmI> {
1618
IViewer* Viewer;
17-
TJsonSettings JsonSettings;
1819
NMon::TEvHttpInfo::TPtr Event;
1920

2021
public:
@@ -28,18 +29,48 @@ class TJsonWhoAmI : public TActorBootstrapped<TJsonWhoAmI> {
2829
{}
2930

3031
void Bootstrap(const TActorContext& ctx) {
31-
const auto& params(Event->Get()->Request.GetParams());
32-
JsonSettings.EnumAsNumbers = !FromStringWithDefault<bool>(params.Get("enums"), false);
33-
JsonSettings.UI64AsString = !FromStringWithDefault<bool>(params.Get("ui64"), false);
3432
ReplyAndDie(ctx);
3533
}
3634

35+
bool CheckGroupMembership(std::unique_ptr<NACLib::TUserToken>& token, const NProtoBuf::RepeatedPtrField<TString>& sids) {
36+
if (sids.empty()) {
37+
return true;
38+
}
39+
for (const auto& sid : sids) {
40+
if (token->IsExist(sid)) {
41+
return true;
42+
}
43+
}
44+
return false;
45+
}
46+
3747
void ReplyAndDie(const TActorContext &ctx) {
3848
NACLibProto::TUserToken userToken;
3949
Y_PROTOBUF_SUPPRESS_NODISCARD userToken.ParseFromString(Event->Get()->UserToken);
40-
TStringStream json;
41-
TProtoToJson::ProtoToJson(json, userToken, JsonSettings);
42-
ctx.Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get()) + json.Str(), 0, NMon::IEvHttpInfoRes::EContentType::Custom));
50+
NJson::TJsonValue json(NJson::JSON_MAP);
51+
if (userToken.HasUserSID()) {
52+
json["UserSID"] = userToken.GetUserSID();
53+
}
54+
if (userToken.HasGroupSIDs() && userToken.GetGroupSIDs().BucketsSize() > 0) {
55+
NJson::TJsonValue& groupSIDs(json["GroupSIDs"]);
56+
groupSIDs.SetType(NJson::JSON_ARRAY);
57+
for (const auto& buckets : userToken.GetGroupSIDs().GetBuckets()) {
58+
for (const auto& group : buckets.GetValues()) {
59+
groupSIDs.AppendValue(group);
60+
}
61+
}
62+
}
63+
if (userToken.HasOriginalUserToken()) {
64+
json["OriginalUserToken"] = userToken.GetOriginalUserToken();
65+
}
66+
if (userToken.HasAuthType()) {
67+
json["AuthType"] = userToken.GetAuthType();
68+
}
69+
auto token = std::make_unique<NACLib::TUserToken>(userToken);
70+
json["IsViewerAllowed"] = CheckGroupMembership(token, AppData()->DomainsConfig.GetSecurityConfig().GetViewerAllowedSIDs());
71+
json["IsMonitoringAllowed"] = CheckGroupMembership(token, AppData()->DomainsConfig.GetSecurityConfig().GetMonitoringAllowedSIDs());
72+
json["IsAdministrationAllowed"] = CheckGroupMembership(token, AppData()->DomainsConfig.GetSecurityConfig().GetAdministrationAllowedSIDs());
73+
ctx.Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get()) + NJson::WriteJson(json, false), 0, NMon::IEvHttpInfoRes::EContentType::Custom));
4374
Die(ctx);
4475
}
4576

@@ -52,17 +83,52 @@ class TJsonWhoAmI : public TActorBootstrapped<TJsonWhoAmI> {
5283
template <>
5384
struct TJsonRequestSchema<TJsonWhoAmI> {
5485
static TString GetSchema() {
55-
TStringStream stream;
56-
TProtoToJson::ProtoToJsonSchema<NACLibProto::TUserToken>(stream);
57-
return stream.Str();
86+
return R"___(
87+
{
88+
"type": "object",
89+
"title": "WhoAmI",
90+
"properties": {
91+
"UserSID": {
92+
"type": "string",
93+
"description": "User ID / name"
94+
},
95+
"GroupSID": {
96+
"type": "array",
97+
"items": {
98+
"type": "string"
99+
},
100+
"description": "User groups"
101+
},
102+
"OriginalUserToken": {
103+
"type": "string",
104+
"description": "User's token used to authenticate"
105+
},
106+
"AuthType": {
107+
"type": "string",
108+
"description": "Authentication type"
109+
},
110+
"IsViewerAllowed": {
111+
"type": "boolean",
112+
"description": "Is user allowed to view data"
113+
},
114+
"IsMonitoringAllowed": {
115+
"type": "boolean",
116+
"description": "Is user allowed to view deeper and make simple changes"
117+
},
118+
"IsAdministrationAllowed": {
119+
"type": "boolean",
120+
"description": "Is user allowed to do unrestricted changes in the system"
121+
}
122+
}
123+
}
124+
)___";
58125
}
59126
};
60127

61128
template <>
62129
struct TJsonRequestParameters<TJsonWhoAmI> {
63130
static TString GetParameters() {
64-
return R"___([{"name":"enums","in":"query","description":"convert enums to strings","required":false,"type":"boolean"},
65-
{"name":"ui64","in":"query","description":"return ui64 as numbers","required":false,"type":"boolean"}])___";
131+
return "[]";
66132
}
67133
};
68134

ydb/library/yql/minikql/computation/mkql_block_reader.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,37 @@ class TTupleBlockItemConverter : public IBlockItemConverter {
195195
mutable TVector<TBlockItem> Items;
196196
};
197197

198+
template <typename TTzDate, bool Nullable>
199+
class TTzDateBlockItemConverter : public IBlockItemConverter {
200+
public:
201+
using TLayout = typename NYql::NUdf::TDataType<TTzDate>::TLayout;
202+
203+
NUdf::TUnboxedValuePod MakeValue(TBlockItem item, const THolderFactory& holderFactory) const final {
204+
Y_UNUSED(holderFactory);
205+
if constexpr (Nullable) {
206+
if (!item) {
207+
return {};
208+
}
209+
}
210+
211+
NUdf::TUnboxedValuePod value {item.Get<TLayout>()};
212+
value.SetTimezoneId(item.GetTimezoneId());
213+
return value;
214+
}
215+
216+
TBlockItem MakeItem(const NUdf::TUnboxedValuePod& value) const final {
217+
if constexpr (Nullable) {
218+
if (!value) {
219+
return {};
220+
}
221+
}
222+
223+
TBlockItem item {value.Get<TLayout>()};
224+
item.SetTimezoneId(value.GetTimezoneId());
225+
return item;
226+
}
227+
};
228+
198229
class TExternalOptionalBlockItemConverter : public IBlockItemConverter {
199230
public:
200231
TExternalOptionalBlockItemConverter(std::unique_ptr<IBlockItemConverter>&& inner)
@@ -229,6 +260,8 @@ struct TConverterTraits {
229260
template <typename TStringType, bool Nullable, NUdf::EDataSlot TOriginal = NUdf::EDataSlot::String, NUdf::EPgStringType PgString = NUdf::EPgStringType::None>
230261
using TStrings = TStringBlockItemConverter<TStringType, Nullable, PgString>;
231262
using TExtOptional = TExternalOptionalBlockItemConverter;
263+
template<typename TTzDate, bool Nullable>
264+
using TTzDateConverter = TTzDateBlockItemConverter<TTzDate, Nullable>;
232265

233266
static std::unique_ptr<TResult> MakePg(const NUdf::TPgTypeDescription& desc, const NUdf::IPgBuilder* pgBuilder) {
234267
if (desc.PassByValue) {
@@ -258,6 +291,15 @@ struct TConverterTraits {
258291
return std::make_unique<TResourceBlockItemConverter<false>>();
259292
}
260293
}
294+
295+
template<typename TTzDate>
296+
static std::unique_ptr<TResult> MakeTzDate(bool isOptional) {
297+
if (isOptional) {
298+
return std::make_unique<TTzDateConverter<TTzDate, true>>();
299+
} else {
300+
return std::make_unique<TTzDateConverter<TTzDate, false>>();
301+
}
302+
}
261303
};
262304

263305
} // namespace

0 commit comments

Comments
 (0)