Skip to content

Commit 843f830

Browse files
Minor modifications
1 parent 9959e8d commit 843f830

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

dbms/src/Common/SensitiveDataMasker.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# include <iostream>
1919
#endif
2020

21+
2122
namespace DB
2223
{
2324
namespace ErrorCodes
@@ -57,7 +58,7 @@ class SensitiveDataMasker::MaskingRule
5758
DB::ErrorCodes::CANNOT_COMPILE_REGEXP);
5859
}
5960

60-
int apply(std::string & data) const
61+
uint64_t apply(std::string & data) const
6162
{
6263
auto m = RE2::GlobalReplace(&data, regexp, replacement);
6364
matches_count += m;
@@ -69,6 +70,7 @@ class SensitiveDataMasker::MaskingRule
6970
uint64_t getMatchesCount() const { return matches_count; }
7071
};
7172

73+
7274
SensitiveDataMasker::SensitiveDataMasker(const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix)
7375
{
7476
Poco::Util::AbstractConfiguration::Keys keys;
@@ -85,23 +87,19 @@ SensitiveDataMasker::SensitiveDataMasker(const Poco::Util::AbstractConfiguration
8587

8688
auto rule_name = config.getString(rule_config_prefix + ".name", rule_config_prefix);
8789

88-
if (used_names.count(rule_name) == 0)
89-
{
90-
used_names.insert(rule_name);
91-
}
92-
else
90+
if (!used_names.insert(rule_name).second)
9391
{
9492
throw Exception(
95-
"query_masking_rules configuration contains more than one rule named '" + rule_name + "'.",
93+
"Query_masking_rules configuration contains more than one rule named '" + rule_name + "'.",
9694
ErrorCodes::INVALID_CONFIG_PARAMETER);
9795
}
9896

9997
auto regexp = config.getString(rule_config_prefix + ".regexp", "");
10098

101-
if (regexp == "")
99+
if (regexp.empty())
102100
{
103101
throw Exception(
104-
"query_masking_rules configuration, rule '" + rule_name + "' has no <regexp> node or <regexp> is empty.",
102+
"Query_masking_rules configuration, rule '" + rule_name + "' has no <regexp> node or <regexp> is empty.",
105103
ErrorCodes::NO_ELEMENTS_IN_CONFIG);
106104
}
107105

@@ -122,7 +120,8 @@ SensitiveDataMasker::SensitiveDataMasker(const Poco::Util::AbstractConfiguration
122120
LOG_WARNING(logger, "Unused param " << config_prefix << '.' << rule);
123121
}
124122
}
125-
auto rules_count = this->rulesCount();
123+
124+
auto rules_count = rulesCount();
126125
if (rules_count > 0)
127126
{
128127
LOG_INFO(logger, rules_count << " query masking rules loaded.");
@@ -138,13 +137,11 @@ void SensitiveDataMasker::addMaskingRule(
138137
}
139138

140139

141-
int SensitiveDataMasker::wipeSensitiveData(std::string & data) const
140+
size_t SensitiveDataMasker::wipeSensitiveData(std::string & data) const
142141
{
143-
int matches = 0;
142+
size_t matches = 0;
144143
for (auto & rule : all_masking_rules)
145-
{
146144
matches += rule->apply(data);
147-
}
148145
return matches;
149146
}
150147

@@ -159,7 +156,7 @@ void SensitiveDataMasker::printStats()
159156
}
160157
#endif
161158

162-
unsigned long SensitiveDataMasker::rulesCount() const
159+
size_t SensitiveDataMasker::rulesCount() const
163160
{
164161
return all_masking_rules.size();
165162
}

dbms/src/Common/SensitiveDataMasker.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <memory>
44
#include <vector>
5+
#include <cstdint>
6+
57

68
namespace Poco
79
{
@@ -22,14 +24,18 @@ class SensitiveDataMasker
2224
public:
2325
SensitiveDataMasker(const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix);
2426
~SensitiveDataMasker();
27+
28+
/// Returns the number of matched rules.
29+
size_t wipeSensitiveData(std::string & data) const;
30+
31+
/// Used in tests.
2532
void addMaskingRule(const std::string & name, const std::string & regexp_string, const std::string & replacement_string);
26-
int wipeSensitiveData(std::string & data) const;
2733

2834
#ifndef NDEBUG
2935
void printStats();
3036
#endif
3137

32-
unsigned long rulesCount() const;
38+
size_t rulesCount() const;
3339
};
3440

3541
};

0 commit comments

Comments
 (0)