Skip to content

Commit

Permalink
fixed issue #360
Browse files Browse the repository at this point in the history
  • Loading branch information
samson4649 committed May 10, 2022
1 parent d6e1d10 commit 8be9e96
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions cmd/headscale/cli/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8be9e96

Please sign in to comment.