2021-04-28 16:15:45 +02:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2021-04-30 00:23:26 +02:00
|
|
|
var RoutesCmd = &cobra.Command{
|
|
|
|
Use: "routes",
|
|
|
|
Short: "Manage the routes of Headscale",
|
|
|
|
}
|
|
|
|
|
2021-04-28 16:15:45 +02:00
|
|
|
var ListRoutesCmd = &cobra.Command{
|
2021-04-30 00:23:26 +02:00
|
|
|
Use: "list NODE",
|
2021-04-28 16:15:45 +02:00
|
|
|
Short: "List the routes exposed by this node",
|
|
|
|
Args: func(cmd *cobra.Command, args []string) error {
|
2021-04-30 00:23:26 +02:00
|
|
|
if len(args) < 1 {
|
2021-04-28 16:15:45 +02:00
|
|
|
return fmt.Errorf("Missing parameters")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2021-04-30 00:23:26 +02:00
|
|
|
n, err := cmd.Flags().GetString("namespace")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error getting namespace: %s", err)
|
|
|
|
}
|
|
|
|
|
2021-04-28 16:15:45 +02:00
|
|
|
h, err := getHeadscaleApp()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error initializing: %s", err)
|
|
|
|
}
|
2021-04-30 00:23:26 +02:00
|
|
|
routes, err := h.GetNodeRoutes(n, args[0])
|
2021-04-28 16:15:45 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
2021-04-28 16:55:29 +02:00
|
|
|
fmt.Println(routes)
|
2021-04-28 16:15:45 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var EnableRouteCmd = &cobra.Command{
|
2021-04-30 00:23:26 +02:00
|
|
|
Use: "enable node-name route",
|
2021-04-28 16:15:45 +02:00
|
|
|
Short: "Allows exposing a route declared by this node to the rest of the nodes",
|
|
|
|
Args: func(cmd *cobra.Command, args []string) error {
|
2021-04-30 00:23:26 +02:00
|
|
|
if len(args) < 2 {
|
2021-04-28 16:15:45 +02:00
|
|
|
return fmt.Errorf("Missing parameters")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2021-04-30 00:23:26 +02:00
|
|
|
n, err := cmd.Flags().GetString("namespace")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error getting namespace: %s", err)
|
|
|
|
}
|
|
|
|
|
2021-04-28 16:15:45 +02:00
|
|
|
h, err := getHeadscaleApp()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error initializing: %s", err)
|
|
|
|
}
|
2021-04-30 00:23:26 +02:00
|
|
|
err = h.EnableNodeRoute(n, args[0], args[1])
|
2021-04-28 16:15:45 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|