2022-03-08 14:47:55 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-05-31 16:06:42 +02:00
|
|
|
"time"
|
2023-05-29 13:52:22 +02:00
|
|
|
|
2024-05-27 08:39:18 +02:00
|
|
|
"github.com/netbirdio/netbird/util"
|
|
|
|
|
2022-03-08 14:47:55 +01:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2022-03-26 12:08:54 +01:00
|
|
|
"github.com/netbirdio/netbird/client/proto"
|
2022-03-08 14:47:55 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var downCmd = &cobra.Command{
|
|
|
|
Use: "down",
|
2022-05-22 18:53:47 +02:00
|
|
|
Short: "down netbird connections",
|
2022-03-08 14:47:55 +01:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2023-01-17 19:16:50 +01:00
|
|
|
SetFlagsFromEnvVars(rootCmd)
|
2022-03-08 14:47:55 +01:00
|
|
|
|
2022-05-25 19:41:03 +02:00
|
|
|
cmd.SetOut(cmd.OutOrStdout())
|
2022-05-22 18:53:47 +02:00
|
|
|
|
2022-05-25 19:41:03 +02:00
|
|
|
err := util.InitLog(logLevel, "console")
|
2022-03-10 18:14:07 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed initializing log %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-07-17 16:26:06 +02:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*7)
|
2022-03-08 14:47:55 +01:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
conn, err := DialClientGRPCServer(ctx, daemonAddr)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed to connect to service CLI interface %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
daemonClient := proto.NewDaemonServiceClient(conn)
|
|
|
|
|
|
|
|
if _, err := daemonClient.Down(ctx, &proto.DownRequest{}); err != nil {
|
|
|
|
log.Errorf("call service down method: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
2024-09-02 19:19:14 +02:00
|
|
|
|
|
|
|
cmd.Println("Disconnected")
|
2022-03-08 14:47:55 +01:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|