We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8efee0e commit 7404c28Copy full SHA for 7404c28
3 files changed
pkg/tools/tools.go
@@ -21,6 +21,8 @@ import (
21
"strconv"
22
"strings"
23
24
+ "github.com/gobwas/glob"
25
+
26
"github.com/TencentBlueKing/bk-bscp/pkg/i18n"
27
"github.com/TencentBlueKing/bk-bscp/pkg/kit"
28
)
@@ -287,8 +289,11 @@ func MatchPattern(name string, match []string) bool {
287
289
}
288
290
291
for _, m := range match {
- ok, _ := path.Match(m, name)
- if ok {
292
+ g, err := glob.Compile(m)
293
+ if err != nil {
294
+ continue
295
+ }
296
+ if g.Match(name) {
297
return true
298
299
pkg/tools/tools_test.go
@@ -141,3 +141,26 @@ func TestSplitPathAndName(t *testing.T) {
141
142
143
144
145
+func TestMatch(t *testing.T) {
146
+ tests := []struct {
147
+ input string
148
+ patterns []string
149
+ expected bool
150
+ }{
151
+ {"file.txt", []string{"*.txt"}, true},
152
+ {"file.txt", []string{"file.txt"}, true},
153
+ {"file.txt", []string{"file.*"}, true},
154
+ {"file.txt", []string{"file"}, false},
155
+ {"file.txt", []string{"file.txt*"}, true},
156
+ {"key1", []string{"{key1,key2}"}, true},
157
+ {"key2", []string{"{key1,key2}"}, true},
158
+ {"key3", []string{"key1", "key2", "key3"}, true},
159
160
+ for _, test := range tests {
161
+ result := MatchPattern(test.input, test.patterns)
162
+ if result != test.expected {
163
+ t.Errorf("MatchPattern(%s, %v) = %t, want %t", test.input, test.patterns, result, test.expected)
164
165
166
+}
pkg/types/cache.go
@@ -14,10 +14,10 @@ package types
14
15
import (
16
"fmt"
17
- "path"
18
19
"time"
20
"github.com/samber/lo"
"github.com/TencentBlueKing/bk-bscp/pkg/dal/table"
@@ -175,12 +175,12 @@ func (c *CredentialCache) MatchKv(app, key string) bool {
175
return false
176
177
178
- for _, v := range scopes {
179
- ok, err := path.Match(v, key)
+ for _, s := range scopes {
+ g, err := glob.Compile(s)
180
if err != nil {
181
- return false
182
183
+ if g.Match(key) {
184
185
186
0 commit comments