()
| 15 | ) |
| 16 | |
| 17 | func (r *RootCmd) netcheck() *serpent.Command { |
| 18 | cmd := &serpent.Command{ |
| 19 | Use: "netcheck", |
| 20 | Short: "Print network debug information for DERP and STUN", |
| 21 | Handler: func(inv *serpent.Invocation) error { |
| 22 | client, err := r.InitClient(inv) |
| 23 | if err != nil { |
| 24 | return err |
| 25 | } |
| 26 | |
| 27 | ctx, cancel := context.WithTimeout(inv.Context(), 30*time.Second) |
| 28 | defer cancel() |
| 29 | |
| 30 | connInfo, err := workspacesdk.New(client).AgentConnectionInfoGeneric(ctx) |
| 31 | if err != nil { |
| 32 | return err |
| 33 | } |
| 34 | |
| 35 | _, _ = fmt.Fprint(inv.Stderr, "Gathering a network report. This may take a few seconds...\n\n") |
| 36 | |
| 37 | var derpReport derphealth.Report |
| 38 | derpReport.Run(ctx, &derphealth.ReportOptions{ |
| 39 | DERPMap: connInfo.DERPMap, |
| 40 | DERPTLSConfig: r.tlsConfig, |
| 41 | }) |
| 42 | |
| 43 | ifReport, err := healthsdk.RunInterfacesReport() |
| 44 | if err != nil { |
| 45 | return xerrors.Errorf("failed to run interfaces report: %w", err) |
| 46 | } |
| 47 | |
| 48 | report := healthsdk.ClientNetcheckReport{ |
| 49 | DERP: healthsdk.DERPHealthReport(derpReport), |
| 50 | Interfaces: ifReport, |
| 51 | } |
| 52 | |
| 53 | raw, err := json.MarshalIndent(report, "", " ") |
| 54 | if err != nil { |
| 55 | return err |
| 56 | } |
| 57 | |
| 58 | n, err := inv.Stdout.Write(raw) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | if n != len(raw) { |
| 63 | return xerrors.Errorf("failed to write all bytes to stdout; wrote %d, len %d", n, len(raw)) |
| 64 | } |
| 65 | |
| 66 | _, _ = inv.Stdout.Write([]byte("\n")) |
| 67 | return nil |
| 68 | }, |
| 69 | } |
| 70 | |
| 71 | cmd.Options = serpent.OptionSet{} |
| 72 | return cmd |
| 73 | } |
no test coverage detected