1
0
mirror of https://github.com/juanfont/headscale.git synced 2024-12-20 19:09:07 +01:00

fixed issue #360

This commit is contained in:
Samuel Lock 2022-05-10 20:51:14 +10:00
parent d6e1d10b12
commit 8be9e9655c

View File

@ -24,6 +24,8 @@ func init() {
enableRouteCmd.Flags(). enableRouteCmd.Flags().
StringSliceP("route", "r", []string{}, "List (or repeated flags) of routes to enable") StringSliceP("route", "r", []string{}, "List (or repeated flags) of routes to enable")
enableRouteCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)") enableRouteCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)")
enableRouteCmd.Flags().BoolP("all", "a", false, "All routes from host")
err = enableRouteCmd.MarkFlagRequired("identifier") err = enableRouteCmd.MarkFlagRequired("identifier")
if err != nil { if err != nil {
log.Fatalf(err.Error()) log.Fatalf(err.Error())
@ -125,20 +127,41 @@ omit the route you do not want to enable.
return return
} }
routes, err := cmd.Flags().GetStringSlice("route") ctx, client, conn, cancel := getHeadscaleCLIClient()
defer cancel()
defer conn.Close()
routes := []string{}
isAll, _ := cmd.Flags().GetBool("all")
if isAll == true {
// x := v1.NewHeadscaleServiceClient(conn)
// machine, err := x.GetMachineByID(machineID)
response, err := client.GetMachineRoute(ctx, &v1.GetMachineRouteRequest{
MachineId: machineID,
})
if err != nil {
ErrorOutput(
err,
fmt.Sprintf(
"Cannot get machine routes: %s\n",
status.Convert(err).Message(),
),
output,
)
}
routes = response.GetRoutes().GetAdvertisedRoutes()
} else {
routes, err = cmd.Flags().GetStringSlice("route")
if err != nil { if err != nil {
ErrorOutput( ErrorOutput(
err, err,
fmt.Sprintf("Error getting routes from flag: %s", err), fmt.Sprintf("Error getting routes from flag: %s", err),
output, output,
) )
return return
} }
}
ctx, client, conn, cancel := getHeadscaleCLIClient()
defer cancel()
defer conn.Close()
request := &v1.EnableMachineRoutesRequest{ request := &v1.EnableMachineRoutesRequest{
MachineId: machineID, MachineId: machineID,