mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(coderd): add provisioner build version and api_version on serve (#11369)
* assert provisioner daemon version and api_version in unit tests * add build info in HTTP header, extract codersdk.BuildVersionHeader * add api_version to codersdk.ProvisionerDaemon * testutil.MustString -> testutil.MustRandString
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
@@ -41,6 +42,7 @@ type ProvisionerDaemon struct {
|
||||
LastSeenAt NullTime `json:"last_seen_at,omitempty" format:"date-time"`
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
APIVersion string `json:"api_version"`
|
||||
Provisioners []ProvisionerType `json:"provisioners"`
|
||||
Tags map[string]string `json:"tags"`
|
||||
}
|
||||
@@ -212,6 +214,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)
|
||||
|
||||
+1
-1
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user