overflow_discovery/service/matcher/redis/protected/redisProtected.go

71 lines
1.1 KiB
Go
Raw Normal View History

2017-11-21 12:47:55 +00:00
package protected
import (
"git.loafle.net/overflow/overflow_discovery/service/matcher"
)
const (
COMPARE_STR_1 = "-"
COMPARE_STR_2 = "DENIED"
)
type RedisProtectedMatcher struct {
matcher.Matchers
}
func (r *RedisProtectedMatcher) ServiceName() string {
2017-11-22 10:07:56 +00:00
return "Redis:Protected"
2017-11-21 12:47:55 +00:00
}
func (r *RedisProtectedMatcher) IsPrePacket() bool {
return true
}
func (r *RedisProtectedMatcher) HasResponse(index int) bool {
return true
}
func (r *RedisProtectedMatcher) IsError(info matcher.MatchInfo, index int, packet *matcher.Packet) bool {
return false
}
func (r *RedisProtectedMatcher) Match(info matcher.MatchInfo, index int, packet *matcher.Packet) bool {
if packet == nil {
return false
}
switch index {
case 0:
str := string(packet.Buffer[:packet.Len])
if str == "" {
return false
}
if len(str) <= 0 {
return false
}
firstCompare := str[0:1]
seconcdCompare := str[1 : len(COMPARE_STR_2)+1]
if firstCompare != COMPARE_STR_1 {
return false
}
if seconcdCompare != COMPARE_STR_2 {
return false
}
return true
}
return false
}
func NewMatcher() matcher.Matcher {
m := &RedisProtectedMatcher{}
return m
}