Skip to content

Commit 1c5b444

Browse files
authored
Merge pull request #1244 from wakatime/misc/clean-naming
Improve naming of heartbeat.SanitizeConfig
2 parents af7d9ce + 4ef4a45 commit 1c5b444

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

cmd/handler/option.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ func WithProjectFiltering() Preprocessor {
119119
func WithHeartbeatSanitization() Preprocessor {
120120
return func(params params.Params) heartbeat.HandleOption {
121121
return heartbeat.WithSanitization(heartbeat.SanitizeConfig{
122-
BranchPatterns: params.Heartbeat.Sanitize.HideBranchNames,
123-
DependencyPatterns: params.Heartbeat.Sanitize.HideDependencies,
124-
FilePatterns: params.Heartbeat.Sanitize.HideFileNames,
125-
HideProjectFolder: params.Heartbeat.Sanitize.HideProjectFolder,
126-
ProjectPatterns: params.Heartbeat.Sanitize.HideProjectNames,
122+
HideBranchPatterns: params.Heartbeat.Sanitize.HideBranchNames,
123+
HideDependencyPatterns: params.Heartbeat.Sanitize.HideDependencies,
124+
HideFilePatterns: params.Heartbeat.Sanitize.HideFileNames,
125+
HideProjectFolder: params.Heartbeat.Sanitize.HideProjectFolder,
126+
HideProjectPatterns: params.Heartbeat.Sanitize.HideProjectNames,
127127
})
128128
}
129129
}

pkg/heartbeat/sanitize.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ import (
1111

1212
// SanitizeConfig defines how a heartbeat should be sanitized.
1313
type SanitizeConfig struct {
14-
// BranchPatterns will be matched against the entity file path and if matching, will obfuscate it.
15-
BranchPatterns []regex.Regex
16-
// DependencyPatterns will be matched against the entity file path and if matching, will omit all dependencies.
17-
DependencyPatterns []regex.Regex
18-
// FilePatterns will be matched against a file entity's name and if matching will obfuscate
14+
// HideBranchPatterns will be matched against the entity file path and if matching, will obfuscate it.
15+
HideBranchPatterns []regex.Regex
16+
// HideDependencyPatterns will be matched against the entity file path and if matching, will omit all dependencies.
17+
HideDependencyPatterns []regex.Regex
18+
// HideFilePatterns will be matched against a file entity's name and if matching will obfuscate
1919
// the file name and common heartbeat meta data (cursor position, dependencies, line number and lines).
20-
FilePatterns []regex.Regex
20+
HideFilePatterns []regex.Regex
2121
// HideProjectFolder determines if project folder should be obfuscated.
2222
HideProjectFolder bool
23-
// ProjectPatterns will be matched against the entity file path and if matching will obfuscate
23+
// HideProjectPatterns will be matched against the entity file path and if matching will obfuscate
2424
// common heartbeat meta data (cursor position, dependencies, line number and lines).
25-
ProjectPatterns []regex.Regex
25+
HideProjectPatterns []regex.Regex
2626
}
2727

2828
// WithSanitization initializes and returns a heartbeat handle option, which
@@ -57,26 +57,26 @@ func Sanitize(ctx context.Context, h Heartbeat, config SanitizeConfig) Heartbeat
5757

5858
// project patterns
5959
if h.Project != nil {
60-
check.Patterns = config.ProjectPatterns
60+
check.Patterns = config.HideProjectPatterns
6161
if ShouldSanitize(ctx, check) {
6262
h = sanitizeMetaData(h)
6363
}
6464
}
6565

6666
// file patterns
67-
check.Patterns = config.FilePatterns
67+
check.Patterns = config.HideFilePatterns
6868
if ShouldSanitize(ctx, check) {
6969
if h.EntityType == FileType {
7070
h.Entity = "HIDDEN" + filepath.Ext(h.Entity)
7171
} else {
7272
h.Entity = "HIDDEN"
7373
}
7474

75-
if len(config.BranchPatterns) == 0 {
75+
if len(config.HideBranchPatterns) == 0 {
7676
h.Branch = nil
7777
}
7878

79-
if len(config.DependencyPatterns) == 0 {
79+
if len(config.HideDependencyPatterns) == 0 {
8080
h.Dependencies = nil
8181
}
8282

@@ -85,15 +85,15 @@ func Sanitize(ctx context.Context, h Heartbeat, config SanitizeConfig) Heartbeat
8585

8686
// branch patterns
8787
if h.Branch != nil {
88-
check.Patterns = config.BranchPatterns
88+
check.Patterns = config.HideBranchPatterns
8989
if ShouldSanitize(ctx, check) {
9090
h.Branch = nil
9191
}
9292
}
9393

9494
// dependency patterns
9595
if h.Dependencies != nil {
96-
check.Patterns = config.DependencyPatterns
96+
check.Patterns = config.HideDependencyPatterns
9797
if ShouldSanitize(ctx, check) {
9898
h.Dependencies = nil
9999
}

pkg/heartbeat/sanitize_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
func TestWithSanitization_ObfuscateFile(t *testing.T) {
1616
opt := heartbeat.WithSanitization(heartbeat.SanitizeConfig{
17-
FilePatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
17+
HideFilePatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
1818
})
1919

2020
handle := opt(func(_ context.Context, hh []heartbeat.Heartbeat) ([]heartbeat.Result, error) {
@@ -112,7 +112,7 @@ func TestSanitize_Obfuscate(t *testing.T) {
112112
for name, test := range tests {
113113
t.Run(name, func(t *testing.T) {
114114
r := heartbeat.Sanitize(ctx, test.Heartbeat, heartbeat.SanitizeConfig{
115-
FilePatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
115+
HideFilePatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
116116
})
117117

118118
assert.Equal(t, test.Expected, r)
@@ -122,8 +122,8 @@ func TestSanitize_Obfuscate(t *testing.T) {
122122

123123
func TestSanitize_ObfuscateFile_SkipBranchIfNotMatching(t *testing.T) {
124124
r := heartbeat.Sanitize(t.Context(), testHeartbeat(), heartbeat.SanitizeConfig{
125-
FilePatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
126-
BranchPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile("not_matching"))},
125+
HideFilePatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
126+
HideBranchPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile("not_matching"))},
127127
})
128128

129129
assert.Equal(t, heartbeat.Heartbeat{
@@ -144,8 +144,8 @@ func TestSanitize_ObfuscateFile_NilFields(t *testing.T) {
144144
h.Dependencies = nil
145145

146146
r := heartbeat.Sanitize(t.Context(), h, heartbeat.SanitizeConfig{
147-
FilePatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
148-
BranchPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
147+
HideFilePatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
148+
HideBranchPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
149149
})
150150

151151
assert.Equal(t, heartbeat.Heartbeat{
@@ -161,7 +161,7 @@ func TestSanitize_ObfuscateFile_NilFields(t *testing.T) {
161161

162162
func TestSanitize_ObfuscateProject(t *testing.T) {
163163
r := heartbeat.Sanitize(t.Context(), testHeartbeat(), heartbeat.SanitizeConfig{
164-
ProjectPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
164+
HideProjectPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
165165
})
166166

167167
assert.Equal(t, heartbeat.Heartbeat{
@@ -179,8 +179,8 @@ func TestSanitize_ObfuscateProject(t *testing.T) {
179179

180180
func TestSanitize_ObfuscateProject_SkipBranchIfNotMatching(t *testing.T) {
181181
r := heartbeat.Sanitize(t.Context(), testHeartbeat(), heartbeat.SanitizeConfig{
182-
ProjectPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
183-
BranchPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile("not_matching"))},
182+
HideProjectPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
183+
HideBranchPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile("not_matching"))},
184184
})
185185

186186
assert.Equal(t, heartbeat.Heartbeat{
@@ -202,8 +202,8 @@ func TestSanitize_ObfuscateProject_NilFields(t *testing.T) {
202202
h.Dependencies = nil
203203

204204
r := heartbeat.Sanitize(t.Context(), h, heartbeat.SanitizeConfig{
205-
ProjectPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
206-
BranchPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
205+
HideProjectPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
206+
HideBranchPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
207207
})
208208

209209
assert.Equal(t, heartbeat.Heartbeat{
@@ -219,7 +219,7 @@ func TestSanitize_ObfuscateProject_NilFields(t *testing.T) {
219219

220220
func TestSanitize_ObfuscateBranch(t *testing.T) {
221221
r := heartbeat.Sanitize(t.Context(), testHeartbeat(), heartbeat.SanitizeConfig{
222-
BranchPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
222+
HideBranchPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
223223
})
224224

225225
assert.Equal(t, heartbeat.Heartbeat{
@@ -243,7 +243,7 @@ func TestSanitize_ObfuscateBranch_NilFields(t *testing.T) {
243243
h.Project = nil
244244

245245
r := heartbeat.Sanitize(t.Context(), h, heartbeat.SanitizeConfig{
246-
BranchPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
246+
HideBranchPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
247247
})
248248

249249
assert.Equal(t, heartbeat.Heartbeat{
@@ -262,7 +262,7 @@ func TestSanitize_ObfuscateBranch_NilFields(t *testing.T) {
262262

263263
func TestSanitize_ObfuscateDependency(t *testing.T) {
264264
r := heartbeat.Sanitize(t.Context(), testHeartbeat(), heartbeat.SanitizeConfig{
265-
DependencyPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
265+
HideDependencyPatterns: []regex.Regex{regex.NewRegexpWrap(regexp.MustCompile(".*"))},
266266
})
267267

268268
assert.Equal(t, heartbeat.Heartbeat{

0 commit comments

Comments
 (0)