overflow_discovery/service/matcher/redis/protected/redisProtected.go
crusader 3081c408fd ing
2017-11-22 19:07:56 +09:00

71 lines
1.1 KiB
Go

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 {
return "Redis:Protected"
}
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
}