From 8be9e9655c567e70cb1f2ccc244abb6381a165bd Mon Sep 17 00:00:00 2001 From: Samuel Lock Date: Tue, 10 May 2022 20:51:14 +1000 Subject: [PATCH] fixed issue #360 --- cmd/headscale/cli/routes.go | 45 ++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/cmd/headscale/cli/routes.go b/cmd/headscale/cli/routes.go index dc060fba..e1deb79e 100644 --- a/cmd/headscale/cli/routes.go +++ b/cmd/headscale/cli/routes.go @@ -24,6 +24,8 @@ func init() { enableRouteCmd.Flags(). StringSliceP("route", "r", []string{}, "List (or repeated flags) of routes to enable") enableRouteCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)") + enableRouteCmd.Flags().BoolP("all", "a", false, "All routes from host") + err = enableRouteCmd.MarkFlagRequired("identifier") if err != nil { log.Fatalf(err.Error()) @@ -125,21 +127,42 @@ omit the route you do not want to enable. return } - routes, err := cmd.Flags().GetStringSlice("route") - if err != nil { - ErrorOutput( - err, - fmt.Sprintf("Error getting routes from flag: %s", err), - output, - ) - - return - } - 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 { + ErrorOutput( + err, + fmt.Sprintf("Error getting routes from flag: %s", err), + output, + ) + return + } + } + request := &v1.EnableMachineRoutesRequest{ MachineId: machineID, Routes: routes,