Skip to content

Commit 6bc56e8

Browse files
johnstcnmafredri
andauthored
fix: use serpent.String instead of serpent.URL for CODER_AGENT_URL (#173)
Co-authored-by: Mathias Fredriksson <[email protected]>
1 parent c08151b commit 6bc56e8

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

cmd/envbuilder/main.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"net/http"
9+
"net/url"
910
"os"
1011
"slices"
1112
"strings"
@@ -31,10 +32,14 @@ func main() {
3132
Handler: func(inv *serpent.Invocation) error {
3233
var sendLogs func(ctx context.Context, log ...agentsdk.Log) error
3334
if options.CoderAgentToken != "" {
34-
if options.CoderAgentURL == nil {
35+
if options.CoderAgentURL == "" {
3536
return errors.New("CODER_AGENT_URL must be set if CODER_AGENT_TOKEN is set")
3637
}
37-
client := agentsdk.New(options.CoderAgentURL)
38+
u, err := url.Parse(options.CoderAgentURL)
39+
if err != nil {
40+
return fmt.Errorf("unable to parse CODER_AGENT_URL as URL: %w", err)
41+
}
42+
client := agentsdk.New(u)
3843
client.SetSessionToken(options.CoderAgentToken)
3944
client.SDK.HTTPClient = &http.Client{
4045
Transport: &http.Transport{

options.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package envbuilder
22

33
import (
4-
"net/url"
54
"strings"
65

76
"github.com/coder/coder/v2/codersdk"
@@ -132,7 +131,8 @@ type Options struct {
132131
Filesystem billy.Filesystem
133132
// These options are specifically used when envbuilder is invoked as part of a
134133
// Coder workspace.
135-
CoderAgentURL *url.URL
134+
// Revert to `*url.URL` once https://github.com/coder/serpent/issues/14 is fixed.
135+
CoderAgentURL string
136136
// CoderAgentToken is the authentication token for a Coder agent.
137137
CoderAgentToken string
138138
// CoderAgentSubsystem is the Coder agent subsystems to report when forwarding
@@ -375,7 +375,7 @@ func (o *Options) CLI() serpent.OptionSet {
375375
{
376376
Flag: "coder-agent-url",
377377
Env: "CODER_AGENT_URL",
378-
Value: serpent.URLOf(o.CoderAgentURL),
378+
Value: serpent.StringOf(&o.CoderAgentURL),
379379
Description: "URL of the Coder deployment. If CODER_AGENT_TOKEN is also " +
380380
"set, logs from envbuilder will be forwarded here and will be " +
381381
"visible in the workspace build logs.",

testdata/options.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ OPTIONS:
2828
Authentication token for a Coder agent. If this is set, then
2929
CODER_AGENT_URL must also be set.
3030

31-
--coder-agent-url url, $CODER_AGENT_URL
31+
--coder-agent-url string, $CODER_AGENT_URL
3232
URL of the Coder deployment. If CODER_AGENT_TOKEN is also set, logs
3333
from envbuilder will be forwarded here and will be visible in the
3434
workspace build logs.

0 commit comments

Comments
 (0)