- Notifications
You must be signed in to change notification settings - Fork928
fix: fix --header flag in CLI#8023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -21,16 +21,13 @@ import ( | ||
"text/tabwriter" | ||
"time" | ||
"github.com/charmbracelet/lipgloss" | ||
"github.com/mattn/go-isatty" | ||
"github.com/mitchellh/go-wordwrap" | ||
"golang.org/x/exp/slices" | ||
"golang.org/x/xerrors" | ||
"cdr.dev/slog" | ||
"github.com/coder/coder/buildinfo" | ||
"github.com/coder/coder/cli/clibase" | ||
"github.com/coder/coder/cli/cliui" | ||
@@ -430,6 +427,15 @@ type RootCmd struct { | ||
} | ||
func addTelemetryHeader(client *codersdk.Client, inv *clibase.Invocation) { | ||
transport, ok := client.HTTPClient.Transport.(*headerTransport) | ||
if !ok { | ||
transport = &headerTransport{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm a bit worried about losing headers in a situation where we think it's safe to wrap the transport and we end up with a type that's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Yeah I'm unsure either but I don't think it will happen in practice, the addTelemetryHeader fn is called immediately after creating the client Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. | ||
transport: client.HTTPClient.Transport, | ||
header: http.Header{}, | ||
} | ||
client.HTTPClient.Transport = transport | ||
} | ||
var topts []telemetry.CLIOption | ||
for _, opt := range inv.Command.FullOptions() { | ||
if opt.ValueSource == clibase.ValueSourceNone || opt.ValueSource == clibase.ValueSourceDefault { | ||
@@ -459,10 +465,7 @@ func addTelemetryHeader(client *codersdk.Client, inv *clibase.Invocation) { | ||
return | ||
} | ||
transport.header.Add(codersdk.CLITelemetryHeader, s) | ||
} | ||
// InitClient sets client to a new client. | ||
@@ -560,18 +563,17 @@ func (r *RootCmd) setClient(client *codersdk.Client, serverURL *url.URL) error { | ||
transport: http.DefaultTransport, | ||
header: http.Header{}, | ||
} | ||
for _, header := range r.header { | ||
parts := strings.SplitN(header, "=", 2) | ||
if len(parts) < 2 { | ||
return xerrors.Errorf("split header %q had less than two parts", header) | ||
} | ||
transport.header.Add(parts[0], parts[1]) | ||
} | ||
client.URL = serverURL | ||
client.HTTPClient = &http.Client{ | ||
Transport: transport, | ||
} | ||
return nil | ||
} | ||