1
0
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:
Josef Citrine 2021-10-08 16:57:32 +01:00
parent 02bf4b09ab
commit 2014946cd9

View File

@ -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)