Skip to content
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
add build info in HTTP header, extract codersdk.BuildVersionHeader
  • Loading branch information
johnstcn committed Jan 2, 2024
commit fc13323b4b05a0335e23d483a2b7f3b943efd9e7
3 changes: 2 additions & 1 deletion cli/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/coder/coder/v2/cli/clitest"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/pty/ptytest"
)

Expand Down Expand Up @@ -58,7 +59,7 @@ func TestLogin(t *testing.T) {
t.Parallel()

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Coder-Build-Version", "something")
w.Header().Set(codersdk.BuildVersionHeader, "something")
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("Not Found"))
}))
Expand Down
2 changes: 1 addition & 1 deletion coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ func New(options *Options) *API {
// Build-Version is helpful for debugging.
func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("X-Coder-Build-Version", buildinfo.Version())
w.Header().Add(codersdk.BuildVersionHeader, buildinfo.Version())
next.ServeHTTP(w, r)
})
},
Expand Down
3 changes: 3 additions & 0 deletions codersdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ const (

// ProvisionerDaemonPSK contains the authentication pre-shared key for an external provisioner daemon
ProvisionerDaemonPSK = "Coder-Provisioner-Daemon-PSK"

// BuildVersionHeader contains build information of Coder.
BuildVersionHeader = "X-Coder-Build-Version"
)

// loggableMimeTypes is a list of MIME types that are safe to log
Expand Down
2 changes: 2 additions & 0 deletions codersdk/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"golang.org/x/xerrors"
"nhooyr.io/websocket"

"github.com/coder/coder/v2/buildinfo"
"github.com/coder/coder/v2/codersdk/drpc"
"github.com/coder/coder/v2/provisionerd/proto"
"github.com/coder/coder/v2/provisionerd/runner"
Expand Down Expand Up @@ -212,6 +213,7 @@ func (c *Client) ServeProvisionerDaemon(ctx context.Context, req ServeProvisione
}
headers := http.Header{}

headers.Set(BuildVersionHeader, buildinfo.Version())
if req.PreSharedKey == "" {
// use session token if we don't have a PSK.
jar, err := cookiejar.New(nil)
Expand Down
2 changes: 1 addition & 1 deletion codersdk/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (c *Client) HasFirstUser(ctx context.Context) (bool, error) {
if res.StatusCode == http.StatusNotFound {
// ensure we are talking to coder and not
// some other service that returns 404
v := res.Header.Get("X-Coder-Build-Version")
v := res.Header.Get(BuildVersionHeader)
if v == "" {
return false, xerrors.Errorf("missing build version header, not a coder instance")
}
Expand Down
4 changes: 3 additions & 1 deletion enterprise/coderd/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ func (api *API) provisionerDaemonServe(rw http.ResponseWriter, r *http.Request)
authCtx = dbauthz.AsSystemRestricted(ctx)
}

versionHdrVal := r.Header.Get(codersdk.BuildVersionHeader)

// Create the daemon in the database.
now := dbtime.Now()
daemon, err := api.Database.UpsertProvisionerDaemon(authCtx, database.UpsertProvisionerDaemonParams{
Expand All @@ -241,7 +243,7 @@ func (api *API) provisionerDaemonServe(rw http.ResponseWriter, r *http.Request)
Tags: tags,
CreatedAt: now,
LastSeenAt: sql.NullTime{Time: now, Valid: true},
Version: "", // TODO: provisionerd needs to send version
Version: versionHdrVal,
APIVersion: "1.0",
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion enterprise/wsproxy/wsproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
// Build-Version is helpful for debugging.
func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("X-Coder-Build-Version", buildinfo.Version())
w.Header().Add(codersdk.BuildVersionHeader, buildinfo.Version())
next.ServeHTTP(w, r)
})
},
Expand Down