You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ti...@apache.org on 2021/04/22 13:49:20 UTC
[servicecomb-kie] branch master updated: List operation support
wildcard match method (#181)
This is an automated email from the ASF dual-hosted git repository.
tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-kie.git
The following commit(s) were added to refs/heads/master by this push:
new 3e1a0e3 List operation support wildcard match method (#181)
3e1a0e3 is described below
commit 3e1a0e392e677d0ad3fb28e3651db8d360bc322a
Author: little-cui <su...@qq.com>
AuthorDate: Thu Apr 22 21:49:10 2021 +0800
List operation support wildcard match method (#181)
---
pkg/validate/instance.go | 2 +-
server/service/mongo/kv/kv_dao.go | 10 ++++++++--
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/pkg/validate/instance.go b/pkg/validate/instance.go
index 1cebe73..fe1c2ab 100644
--- a/pkg/validate/instance.go
+++ b/pkg/validate/instance.go
@@ -5,7 +5,7 @@ var defaultValidator = NewValidator()
const (
key = "key"
commonNameRegexString = `^[a-zA-Z0-9]*$|^[a-zA-Z0-9][a-zA-Z0-9_\-.]*[a-zA-Z0-9]$`
- getKeyRegexString = `^[a-zA-Z0-9]*$|^[a-zA-Z0-9][a-zA-Z0-9_\-.]*[a-zA-Z0-9]$|^beginWith\([a-zA-Z0-9][a-zA-Z0-9_\-.]*\)$`
+ getKeyRegexString = `^[a-zA-Z0-9]*$|^[a-zA-Z0-9][a-zA-Z0-9_\-.]*[a-zA-Z0-9]$|^beginWith\([a-zA-Z0-9][a-zA-Z0-9_\-.]*\)$|^wildcard\([a-zA-Z0-9][a-zA-Z0-9_\-.*]*\)$`
asciiRegexString = `^[\x00-\x7F]*$`
allCharString = `.*`
)
diff --git a/server/service/mongo/kv/kv_dao.go b/server/service/mongo/kv/kv_dao.go
index 138776f..378e559 100644
--- a/server/service/mongo/kv/kv_dao.go
+++ b/server/service/mongo/kv/kv_dao.go
@@ -123,8 +123,14 @@ func findKV(ctx context.Context, domain string, project string, opts service.Fin
filter := bson.M{"domain": domain, "project": project}
if opts.Key != "" {
filter["key"] = opts.Key
- if strings.HasPrefix(opts.Key, "beginWith") {
- filter["key"] = bson.M{"$regex": getValue(opts.Key), "$options": "$i"}
+ switch {
+ case strings.HasPrefix(opts.Key, "beginWith("):
+ value := strings.ReplaceAll(getValue(opts.Key), ".", "\\.")
+ filter["key"] = bson.M{"$regex": value, "$options": "$i"}
+ case strings.HasPrefix(opts.Key, "wildcard("):
+ value := strings.ReplaceAll(getValue(opts.Key), ".", "\\.")
+ value = strings.ReplaceAll(value, "*", ".*")
+ filter["key"] = bson.M{"$regex": value, "$options": "$i"}
}
}
if len(opts.Labels) != 0 {