mirror of
https://github.com/juanfont/headscale.git
synced 2025-08-14 13:51:01 +02:00
Add IP param for non-reusable keys
This commit is contained in:
parent
02bf4b09ab
commit
2014946cd9
@ -26,6 +26,7 @@ func init() {
|
||||
createPreAuthKeyCmd.PersistentFlags().Bool("ephemeral", false, "Preauthkey for ephemeral nodes")
|
||||
createPreAuthKeyCmd.Flags().StringP("expiration", "e", "", "Human-readable expiration of the key (30m, 24h, 365d...)")
|
||||
createPreAuthKeyCmd.Flags().StringP("subnet", "s", "", "Subnet to assign new nodes to")
|
||||
createPreAuthKeyCmd.Flags().String("ip", "", "IP to assign a node to (only supported for non-resuable keys)")
|
||||
}
|
||||
|
||||
var preauthkeysCmd = &cobra.Command{
|
||||
@ -119,6 +120,19 @@ var createPreAuthKeyCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
subnet, _ := cmd.Flags().GetString("subnet")
|
||||
|
||||
if !reusable && subnet == "" {
|
||||
ip, _ := cmd.Flags().GetString("ip")
|
||||
if ip != "" {
|
||||
// If IP is in CIDR notation, strip the last octet
|
||||
if strings.Contains(ip, "/") {
|
||||
ip = strings.Split(ip, "/")[0]
|
||||
}
|
||||
|
||||
subnet = ip + "/32"
|
||||
}
|
||||
}
|
||||
|
||||
k, err := h.CreatePreAuthKeyWithSubnet(n, reusable, ephemeral, expiration, subnet)
|
||||
if strings.HasPrefix(o, "json") {
|
||||
JsonOutput(k, err, o)
|
||||
|
Loading…
Reference in New Issue
Block a user