Skip to content

Commit e61eb04

Browse files
authored
Merge bf6e347 into f2efea6
2 parents f2efea6 + bf6e347 commit e61eb04

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

ydb/core/viewer/json_whoami.h

Lines changed: 38 additions & 7 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.HasOriginalUserToken();
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

0 commit comments

Comments
 (0)