network_service_matcher/redis/protected/redisProtected.go

75 lines
1.2 KiB
Go
Raw Normal View History

2017-12-04 07:27:08 +00:00
package protected
import (
cnsm "git.loafle.net/commons_go/network_service_matcher"
)
const (
COMPARE_STR_1 = "-"
COMPARE_STR_2 = "DENIED"
)
type RedisProtectedMatcher struct {
cnsm.Matchers
}
func (r *RedisProtectedMatcher) ServiceName() string {
2018-03-29 13:55:08 +00:00
return "REDIS"
}
func (r *RedisProtectedMatcher) String() string {
2017-12-04 07:27:08 +00:00
return "Redis:Protected"
}
func (r *RedisProtectedMatcher) IsPrePacket() bool {
return true
}
func (r *RedisProtectedMatcher) HasResponse(index int) bool {
return true
}
func (r *RedisProtectedMatcher) IsError(info cnsm.MatchInfo, index int, packet *cnsm.Packet) bool {
return false
}
func (r *RedisProtectedMatcher) Match(info cnsm.MatchInfo, index int, packet *cnsm.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() cnsm.Matcher {
m := &RedisProtectedMatcher{}
return m
}