Skip to content

feat: add header-process flag #9059

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename header-process to header-command
  • Loading branch information
code-asher committed Aug 14, 2023
commit 4a439ce775388f561738feb6fdf47a606a60c511
14 changes: 7 additions & 7 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const (
varAgentToken = "agent-token"
varAgentURL = "agent-url"
varHeader = "header"
varHeaderProcess = "header-process"
varHeaderCommand = "header-command"
varNoOpen = "no-open"
varNoVersionCheck = "no-version-warning"
varNoFeatureWarning = "no-feature-warning"
Expand Down Expand Up @@ -359,10 +359,10 @@ func (r *RootCmd) Command(subcommands []*clibase.Cmd) (*clibase.Cmd, error) {
Group: globalGroup,
},
{
Flag: varHeaderProcess,
Env: "CODER_HEADER_PROCESS",
Flag: varHeaderCommand,
Env: "CODER_HEADER_COMMAND",
Description: "An external process that outputs JSON-encoded key-value pairs to be used as additional HTTP headers added to all requests.",
Value: clibase.StringOf(&r.headerProcess),
Value: clibase.StringOf(&r.headerCommand),
Group: globalGroup,
},
{
Expand Down Expand Up @@ -446,7 +446,7 @@ type RootCmd struct {
token string
globalConfig string
header []string
headerProcess string
headerCommand string
agentToken string
agentURL *url.URL
forceTTY bool
Expand Down Expand Up @@ -612,15 +612,15 @@ func (r *RootCmd) setClient(ctx context.Context, client *codersdk.Client, server
}
transport.header.Add(parts[0], parts[1])
}
if r.headerProcess != "" {
if r.headerCommand != "" {
shell := "sh"
caller := "-c"
if runtime.GOOS == "windows" {
shell = "cmd.exe"
caller = "/c"
}
// #nosec
cmd := exec.CommandContext(ctx, shell, caller, r.headerProcess)
cmd := exec.CommandContext(ctx, shell, caller, r.headerCommand)
cmd.Env = append(os.Environ(), "CODER_URL="+serverURL.String())
out, err := cmd.Output()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cli/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestRoot(t *testing.T) {
"--no-version-warning",
"--header", "X-Testing=wow",
"--header", "Cool-Header=Dean was Here!",
"--header-process", "printf '{\"X-Process-Testing\": \"very-wow-'"+coderURLEnv+"'\"}'",
"--header-command", "printf '{\"X-Process-Testing\": \"very-wow-'"+coderURLEnv+"'\"}'",
"login", srv.URL,
)
inv.Stdout = buf
Expand All @@ -107,7 +107,7 @@ func TestRoot(t *testing.T) {
}

// TestDERPHeaders ensures that the client sends the global `--header`s and
// `--header-process` to the DERP server when connecting.
// `--header-command` to the DERP server when connecting.
func TestDERPHeaders(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -169,7 +169,7 @@ func TestDERPHeaders(t *testing.T) {
"--no-version-warning",
"ping", workspace.Name,
"-n", "1",
"--header-process", "printf '{\"X-Process-Testing\": \"very-wow\"}'",
"--header-command", "printf '{\"X-Process-Testing\": \"very-wow\"}'",
}
for k, v := range expectedHeaders {
if k != "X-Process-Testing" {
Expand Down
4 changes: 2 additions & 2 deletions cli/testdata/coder_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ variables or flags.
Additional HTTP headers added to all requests. Provide as key=value.
Can be specified multiple times.

--header-process string, $CODER_HEADER_PROCESS
An external process that outputs JSON-encoded key-value pairs to be
--header-command string, $CODER_HEADER_COMMAND
An external command that outputs JSON-encoded key-value pairs to be
used as additional HTTP headers added to all requests.

--no-feature-warning bool, $CODER_NO_FEATURE_WARNING
Expand Down
6 changes: 3 additions & 3 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ Path to the global `coder` config directory.

Additional HTTP headers added to all requests. Provide as key=value. Can be specified multiple times.

### --header-process
### --header-command

| | |
| ----------- | ---------------------------------- |
| Type | <code>string</code> |
| Environment | <code>$CODER_HEADER_PROCESS</code> |
| Environment | <code>$CODER_HEADER_COMMAND</code> |

An external process that outputs JSON-encoded key-value pairs to be used as additional HTTP headers added to all requests.
An external command that outputs JSON-encoded key-value pairs to be used as additional HTTP headers added to all requests.

### --no-feature-warning

Expand Down
4 changes: 2 additions & 2 deletions enterprise/cli/testdata/coder_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ variables or flags.
Additional HTTP headers added to all requests. Provide as key=value.
Can be specified multiple times.

--header-process string, $CODER_HEADER_PROCESS
An external process that outputs JSON-encoded key-value pairs to be
--header-command string, $CODER_HEADER_COMMAND
An external command that outputs JSON-encoded key-value pairs to be
used as additional HTTP headers added to all requests.

--no-feature-warning bool, $CODER_NO_FEATURE_WARNING
Expand Down