1
0
mirror of https://github.com/juanfont/headscale.git synced 2025-08-28 13:49:04 +02:00

Moved subnet validation out of CLI

This commit is contained in:
Josef Citrine 2021-11-26 15:54:19 +00:00
parent 16a0c3e55e
commit eceb8d7ca7
2 changed files with 10 additions and 11 deletions

View File

@ -142,17 +142,6 @@ var createPreAuthKeyCmd = &cobra.Command{
subnet, _ := cmd.Flags().GetString("subnet")
if subnet != "" {
ipPrefix, err := netaddr.ParseIPPrefix(subnet)
if err != nil {
ErrorOutput(err, fmt.Sprintf("Error parsing subnet: %s", err), output)
return
}
subnet = ipPrefix.String()
}
if !reusable && subnet == "" {
ip, _ := cmd.Flags().GetString("ip")
if ip != "" {

View File

@ -10,6 +10,7 @@ import (
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"google.golang.org/protobuf/types/known/timestamppb"
"gorm.io/gorm"
"inet.af/netaddr"
)
const (
@ -63,6 +64,15 @@ func (h *Headscale) CreatePreAuthKeyWithSubnet(
return nil, err
}
if subnet != "" {
ipPrefix, err := netaddr.ParseIPPrefix(subnet)
if err != nil {
return nil, err
}
subnet = ipPrefix.String()
}
key := PreAuthKey{
Key: kstr,
NamespaceID: namespace.ID,