Attempt to dry up CLI client, add proepr config

This commit is trying to DRY up the initiation of the gRPC client in
each command:

It renames the function to CLI instead of GRPC as it actually set up a
CLI client, not a generic grpc client

It also moves the configuration of address, timeout (which is now
consistent) and api to use Viper, allowing users to set it via env vars
and configuration file
This commit is contained in:
Kristoffer Dalby 2021-11-07 09:41:14 +00:00
parent ce3f79a3bf
commit 2dfd42f80c
7 changed files with 54 additions and 75 deletions

View file

@ -1,9 +1,7 @@
package cli
import (
"context"
"fmt"
"time"
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/rs/zerolog/log"
@ -51,10 +49,8 @@ var createNodeCmd = &cobra.Command{
return
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, client, conn, cancel := getHeadscaleCLIClient()
defer cancel()
client, conn := getHeadscaleGRPCClient(ctx)
defer conn.Close()
name, err := cmd.Flags().GetString("name")