Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: query strength && dst IP "assigned" #12

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions flowdesc/ip_filter_rule.go
Copy link
Collaborator

@tim-ywliu tim-ywliu Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add as below and replace all "any" & "assigned" with const.

const (
	Any      string = "any"
	Assigned string = "assigned"
)

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ const (
Out Direction = "out"
)

const (
Any string = "any"
Assigned string = "assigned"
)

func flowDescErrorf(format string, a ...interface{}) error {
msg := fmt.Sprintf(format, a...)
return fmt.Errorf("flowdesc: %s", msg)
Expand Down Expand Up @@ -144,7 +149,7 @@ func Encode(r *IPFilterRule) (string, error) {
return "", flowDescErrorf("source addresses format error %s", src)
}
} else {
ipFilterRuleStr = append(ipFilterRuleStr, "any")
ipFilterRuleStr = append(ipFilterRuleStr, Any)
}

srcPort := r.SrcPorts.String()
Expand All @@ -168,7 +173,7 @@ func Encode(r *IPFilterRule) (string, error) {
return "", flowDescErrorf("destination addresses format error %s", dst)
}
} else {
ipFilterRuleStr = append(ipFilterRuleStr, "any")
ipFilterRuleStr = append(ipFilterRuleStr, Any)
}

dstPort := r.DstPorts.String()
Expand Down Expand Up @@ -293,7 +298,7 @@ func validAddrsFormat(addrs string) bool {
if addrs[0] == '!' {
return false
}
if addrs == "any" || addrs == "assigned" {
if addrs == Any || addrs == Assigned {
return true
}
_, _, err := net.ParseCIDR(addrs)
Expand All @@ -308,7 +313,7 @@ func parseFlowDescAddrs(addrs string) (string, error) {
if addrs == "" {
return "", flowDescErrorf("Empty string")
}
if addrs == "any" || addrs == "assigned" {
if addrs == Any || addrs == Assigned {
return addrs, nil
}
if addrs[0] == '!' {
Expand Down
8 changes: 7 additions & 1 deletion mongoapi/mongoapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ func RestfulAPIPutOne(collName string, filter bson.M, putData map[string]interfa
}

if existed {
if _, err := collection.UpdateOne(context.TODO(), filter, bson.M{"$set": putData}); err != nil {
var opts *options.UpdateOptions
collation := getCollation(argOpt...)
if collation != nil {
opts = new(options.UpdateOptions)
opts.SetCollation(collation)
}
if _, err := collection.UpdateOne(context.TODO(), filter, bson.M{"$set": putData}, opts); err != nil {
return false, fmt.Errorf("RestfulAPIPutOne UpdateOne err: %+v", err)
}
return true, nil
Expand Down