Skip to content

fix: use serpent.String instead of serpent.URL for CODER_AGENT_URL #173

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 2 commits into from
May 3, 2024
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
9 changes: 7 additions & 2 deletions cmd/envbuilder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"net/http"
"net/url"
"os"
"slices"
"strings"
Expand All @@ -31,10 +32,14 @@ func main() {
Handler: func(inv *serpent.Invocation) error {
var sendLogs func(ctx context.Context, log ...agentsdk.Log) error
if options.CoderAgentToken != "" {
if options.CoderAgentURL == nil {
if options.CoderAgentURL == "" {
return errors.New("CODER_AGENT_URL must be set if CODER_AGENT_TOKEN is set")
}
client := agentsdk.New(options.CoderAgentURL)
u, err := url.Parse(options.CoderAgentURL)
if err != nil {
return fmt.Errorf("invalid value for CODER_AGENT_URL: %w", err)
}
client := agentsdk.New(u)
client.SetSessionToken(options.CoderAgentToken)
client.SDK.HTTPClient = &http.Client{
Transport: &http.Transport{
Expand Down
5 changes: 2 additions & 3 deletions options.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package envbuilder

import (
"net/url"
"strings"

"github.com/coder/coder/v2/codersdk"
Expand Down Expand Up @@ -132,7 +131,7 @@ type Options struct {
Filesystem billy.Filesystem
// These options are specifically used when envbuilder is invoked as part of a
// Coder workspace.
CoderAgentURL *url.URL
CoderAgentURL string
// CoderAgentToken is the authentication token for a Coder agent.
CoderAgentToken string
// CoderAgentSubsystem is the Coder agent subsystems to report when forwarding
Expand Down Expand Up @@ -375,7 +374,7 @@ func (o *Options) CLI() serpent.OptionSet {
{
Flag: "coder-agent-url",
Env: "CODER_AGENT_URL",
Value: serpent.URLOf(o.CoderAgentURL),
Value: serpent.StringOf(&o.CoderAgentURL),
Description: "URL of the Coder deployment. If CODER_AGENT_TOKEN is also " +
"set, logs from envbuilder will be forwarded here and will be " +
"visible in the workspace build logs.",
Expand Down
2 changes: 1 addition & 1 deletion testdata/options.golden
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ OPTIONS:
Authentication token for a Coder agent. If this is set, then
CODER_AGENT_URL must also be set.

--coder-agent-url url, $CODER_AGENT_URL
--coder-agent-url string, $CODER_AGENT_URL
URL of the Coder deployment. If CODER_AGENT_TOKEN is also set, logs
from envbuilder will be forwarded here and will be visible in the
workspace build logs.
Expand Down
Loading