mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-14 13:24:34 +02:00
26 lines
545 B
Go
26 lines
545 B
Go
package clialert
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
|
)
|
|
|
|
// SanitizeScope validates ip and range and sets the scope accordingly to our case convention.
|
|
func SanitizeScope(scope, ip, ipRange string) (string, error) {
|
|
if ipRange != "" {
|
|
_, _, err := net.ParseCIDR(ipRange)
|
|
if err != nil {
|
|
return "", fmt.Errorf("%s is not a valid range", ipRange)
|
|
}
|
|
}
|
|
|
|
if ip != "" {
|
|
if net.ParseIP(ip) == nil {
|
|
return "", fmt.Errorf("%s is not a valid ip", ip)
|
|
}
|
|
}
|
|
|
|
return types.NormalizeScope(scope), nil
|
|
}
|