Skip to content

Commit c0815af

Browse files
authored
SecureDebugString() helper (#4492)
1 parent 3bcfc2d commit c0815af

File tree

6 files changed

+26
-41
lines changed

6 files changed

+26
-41
lines changed

ydb/core/persqueue/partition_monitoring.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@
2323

2424
namespace NKikimr::NPQ {
2525

26-
TString PrintConfig(const NKikimrPQ::TPQTabletConfig& cfg) {
27-
TSecurityTextFormatPrinter<NKikimrPQ::TPQTabletConfig> printer;
28-
printer.SetSingleLineMode(true);
29-
TString string;
30-
printer.PrintToString(cfg, &string);
31-
return string;
32-
}
33-
3426
void HtmlOutput(IOutputStream& out, const TString& line, const std::deque<std::pair<TKey, ui32>>& keys) {
3527
HTML(out) {
3628
TABLE() {
@@ -116,7 +108,7 @@ void TPartition::HandleMonitoring(TEvPQ::TEvMonRequest::TPtr& ev, const TActorCo
116108
out << "AvgWriteSize per " << avg.GetDuration().ToString() << " is " << avg.GetValue() << " bytes";
117109
res.push_back(out.Str()); out.Clear();
118110
}
119-
out << PrintConfig(Config); res.push_back(out.Str()); out.Clear();
111+
out << SecureDebugString(Config); res.push_back(out.Str()); out.Clear();
120112
HTML(out) {
121113
DIV_CLASS_ID("tab-pane fade", Sprintf("partition_%u", Partition.InternalPartitionId)) {
122114
TABLE_SORTABLE_CLASS("table") {

ydb/core/tx/replication/common/sensitive_event_pb.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ namespace NKikimr::NReplication {
1010
template <typename TEv, typename TRecord, ui32 EventType>
1111
struct TSensitiveEventPB: public NActors::TEventPB<TEv, TRecord, EventType> {
1212
TString ToString() const override {
13-
TSecurityTextFormatPrinter<TRecord> printer;
14-
printer.SetSingleLineMode(true);
15-
TString string;
16-
printer.PrintToString(this->Record, &string);
17-
return TStringBuilder() << this->ToStringHeader() << " " << string;
13+
return TStringBuilder() << this->ToStringHeader() << " " << SecureDebugString<TRecord>(this->Record);
1814
}
1915
};
2016

ydb/core/tx/schemeshard/schemeshard__operation.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@ NKikimrScheme::TEvModifySchemeTransaction GetRecordForPrint(const NKikimrScheme:
8787
return recordForPrint;
8888
}
8989

90-
TString PrintSecurely(const NKikimrScheme::TEvModifySchemeTransaction& record) {
91-
TSecurityTextFormatPrinter<NKikimrScheme::TEvModifySchemeTransaction> printer;
92-
printer.SetSingleLineMode(true);
93-
TString string;
94-
printer.PrintToString(record, &string);
95-
return string;
96-
}
97-
9890
THolder<TProposeResponse> TSchemeShard::IgniteOperation(TProposeRequest& request, TOperationContext& context) {
9991
THolder<TProposeResponse> response = nullptr;
10092

@@ -193,7 +185,7 @@ THolder<TProposeResponse> TSchemeShard::IgniteOperation(TProposeRequest& request
193185
<< ", already accepted parts: " << operation->Parts.size()
194186
<< ", propose result status: " << NKikimrScheme::EStatus_Name(response->Record.GetStatus())
195187
<< ", with reason: " << response->Record.GetReason()
196-
<< ", tx message: " << PrintSecurely(record));
188+
<< ", tx message: " << SecureDebugString(record));
197189
}
198190

199191
Y_VERIFY_S(context.IsUndoChangesSafe(),
@@ -204,7 +196,7 @@ THolder<TProposeResponse> TSchemeShard::IgniteOperation(TProposeRequest& request
204196
<< ", already accepted parts: " << operation->Parts.size()
205197
<< ", propose result status: " << NKikimrScheme::EStatus_Name(response->Record.GetStatus())
206198
<< ", with reason: " << response->Record.GetReason()
207-
<< ", tx message: " << PrintSecurely(record));
199+
<< ", tx message: " << SecureDebugString(record));
208200

209201
context.OnComplete = {}; // recreate
210202
context.DbChanges = {};
@@ -247,7 +239,7 @@ struct TSchemeShard::TTxOperationPropose: public NTabletFlatExecutor::TTransacti
247239

248240
LOG_DEBUG_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
249241
"TTxOperationPropose Execute"
250-
<< ", message: " << PrintSecurely(Request->Get()->Record)
242+
<< ", message: " << SecureDebugString(Request->Get()->Record)
251243
<< ", at schemeshard: " << selfId);
252244

253245
txc.DB.NoMoreReadsForTx();

ydb/core/tx/tx_proxy/schemereq.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#include "proxy.h"
22

3-
#include <ydb/core/docapi/traits.h>
4-
#include <ydb/core/tx/schemeshard/schemeshard.h>
5-
#include <ydb/core/protos/flat_scheme_op.pb.h>
6-
#include <ydb/public/api/protos/ydb_issue_message.pb.h>
7-
#include <ydb/core/base/tablet_pipe.h>
83
#include <ydb/core/base/appdata.h>
9-
#include <ydb/core/base/tx_processing.h>
10-
#include <ydb/library/ydb_issue/issue_helpers.h>
114
#include <ydb/core/base/path.h>
12-
5+
#include <ydb/core/base/tablet_pipe.h>
6+
#include <ydb/core/base/tx_processing.h>
7+
#include <ydb/core/docapi/traits.h>
8+
#include <ydb/core/protos/flat_scheme_op.pb.h>
9+
#include <ydb/core/tx/schemeshard/schemeshard.h>
1310
#include <ydb/library/aclib/aclib.h>
14-
1511
#include <ydb/library/actors/core/hfunc.h>
12+
#include <ydb/library/protobuf_printer/security_printer.h>
13+
#include <ydb/library/ydb_issue/issue_helpers.h>
14+
#include <ydb/public/api/protos/ydb_issue_message.pb.h>
15+
1616
#include <util/string/cast.h>
1717

1818
namespace NKikimr {
@@ -1168,7 +1168,7 @@ void TFlatSchemeReq::Bootstrap(const TActorContext &ctx) {
11681168
"Actor# " << ctx.SelfID.ToString()
11691169
<< " txid# " << TxId
11701170
<< " Bootstrap EvSchemeRequest"
1171-
<< " record: " << GetRequestProto().DebugString());
1171+
<< " record: " << SecureDebugString(GetRequestProto()));
11721172
Y_ABORT_UNLESS(GetRequestEv().HasModifyScheme());
11731173
Y_ABORT_UNLESS(!GetRequestEv().HasTransactionalModification());
11741174

@@ -1303,7 +1303,7 @@ void TSchemeTransactionalReq::Bootstrap(const TActorContext &ctx) {
13031303
"Actor# " << ctx.SelfID.ToString()
13041304
<< " txid# " << TxId
13051305
<< " Bootstrap EvSchemeRequest"
1306-
<< " record: " << GetRequestProto().DebugString());
1306+
<< " record: " << SecureDebugString(GetRequestProto()));
13071307
Y_ABORT_UNLESS(!GetRequestEv().HasModifyScheme());
13081308
Y_ABORT_UNLESS(GetRequestEv().HasTransactionalModification());
13091309

ydb/library/grpc/server/logger.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ template <typename TMsg>
5050
inline TString FormatMessage(const TMsg& message, bool ok = true) {
5151
if (ok) {
5252
if (LogBodyEnabled) {
53-
TString text;
54-
NKikimr::TSecurityTextFormatPrinter<TMsg> printer;
55-
printer.SetSingleLineMode(true);
56-
printer.PrintToString(message, &text);
57-
return text;
53+
return NKikimr::SecureDebugString<TMsg>(message);
5854
} else {
5955
return "<hidden>";
6056
}

ydb/library/protobuf_printer/security_printer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,13 @@ class TSecurityTextFormatPrinter : public google::protobuf::TextFormat::Printer
3434
}
3535
};
3636

37+
template <typename TMsg>
38+
inline TString SecureDebugString(const TMsg& message) {
39+
TString result;
40+
TSecurityTextFormatPrinter<TMsg> printer;
41+
printer.SetSingleLineMode(true);
42+
printer.PrintToString(message, &result);
43+
return result;
44+
}
45+
3746
} // namespace NKikimr

0 commit comments

Comments
 (0)