Skip to content

Commit 61bef0a

Browse files
committed
pr comments
1 parent 42cae32 commit 61bef0a

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

cli/root.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -840,17 +840,10 @@ func (r *RootCmd) checkVersions(i *clibase.Invocation, client *codersdk.Client,
840840
return xerrors.Errorf("deployment config: %w", err)
841841
}
842842

843-
fmtWarningText := `version mismatch: client %s, server %s
844-
`
845-
// Our installation script doesn't work on Windows, so instead we direct the user
846-
// to the GitHub release page to download the latest installer.
847-
if runtime.GOOS == "windows" {
848-
fmtWarningText += `download the server version from: https://github.com/coder/coder/releases/v%s`
849-
} else {
850-
fmtWarningText += `download the server version with: 'curl -L https://coder.com/install.sh | sh -s -- --version %s'`
851-
}
843+
fmtWarningText := "version mismatch: client %s, server %s\n%s"
844+
852845
warn := cliui.DefaultStyles.Warn
853-
warning := fmt.Sprintf(pretty.Sprint(warn, fmtWarningText), clientVersion, info.Version, strings.TrimPrefix(info.CanonicalVersion(), "v"))
846+
warning := fmt.Sprintf(pretty.Sprint(warn, fmtWarningText), clientVersion, info.Version, strings.TrimPrefix(info.CanonicalVersion(), "v"), info.UpgradeMessage)
854847

855848
// If a custom upgrade message has been set, override the default that we
856849
// display.

coderd/agentapi/servicebanner_internal_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77

88
"golang.org/x/xerrors"
99

10+
"github.com/stretchr/testify/require"
11+
1012
agentproto "github.com/coder/coder/v2/agent/proto"
1113
"github.com/coder/coder/v2/coderd/appearance"
1214
"github.com/coder/coder/v2/codersdk"
13-
"github.com/stretchr/testify/require"
1415
)
1516

1617
func TestGetServiceBanner(t *testing.T) {

coderd/coderd.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ func New(options *Options) *API {
647647
// All CSP errors will be logged
648648
r.Post("/csp/reports", api.logReportCSPViolations)
649649

650-
r.Get("/buildinfo", buildInfo(api.AccessURL))
650+
r.Get("/buildinfo", buildInfo(api.AccessURL, api.DeploymentValues.CLIUpgradeMessage.String()))
651651
// /regions is overridden in the enterprise version
652652
r.Group(func(r chi.Router) {
653653
r.Use(apiKeyMiddleware)
@@ -662,7 +662,6 @@ func New(options *Options) *API {
662662
r.Get("/config", api.deploymentValues)
663663
r.Get("/stats", api.deploymentStats)
664664
r.Get("/ssh", api.sshConfig)
665-
r.Get("/unprivileged", api.unprivilegedConfig)
666665
})
667666
r.Route("/experiments", func(r chi.Router) {
668667
r.Use(apiKeyMiddleware)

coderd/deployment.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,15 @@ func (api *API) deploymentStats(rw http.ResponseWriter, r *http.Request) {
6868
// @Tags General
6969
// @Success 200 {object} codersdk.BuildInfoResponse
7070
// @Router /buildinfo [get]
71-
func buildInfo(accessURL *url.URL) http.HandlerFunc {
71+
func buildInfo(accessURL *url.URL, upgradeMessage string) http.HandlerFunc {
7272
return func(rw http.ResponseWriter, r *http.Request) {
7373
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.BuildInfoResponse{
7474
ExternalURL: buildinfo.ExternalURL(),
7575
Version: buildinfo.Version(),
7676
AgentAPIVersion: AgentAPIVersionREST,
7777
DashboardURL: accessURL.String(),
7878
WorkspaceProxy: false,
79+
UpgradeMessage: upgradeMessage,
7980
})
8081
}
8182
}
@@ -90,17 +91,3 @@ func buildInfo(accessURL *url.URL) http.HandlerFunc {
9091
func (api *API) sshConfig(rw http.ResponseWriter, r *http.Request) {
9192
httpapi.Write(r.Context(), rw, http.StatusOK, api.SSHConfig)
9293
}
93-
94-
// @Summary Unprivileged deployment config.
95-
// @ID unprivileged-deployment-config
96-
// @Security CoderSessionToken
97-
// @Produce json
98-
// @Tags General
99-
// @Success 200 {object} codersdk.UnprivilegedDeploymentConfig
100-
// @Router /deployment/unprivileged [get]
101-
func (api *API) unprivilegedConfig(rw http.ResponseWriter, r *http.Request) {
102-
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.UnprivilegedDeploymentConfig{
103-
SSHConfig: api.SSHConfig,
104-
CLIUpgradeMessage: api.DeploymentValues.CLIUpgradeMessage.String(),
105-
})
106-
}

codersdk/deployment.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import (
44
"context"
55
"encoding/json"
66
"flag"
7+
"fmt"
78
"net/http"
89
"os"
910
"path/filepath"
11+
"runtime"
1012
"strconv"
1113
"strings"
1214
"time"
@@ -1789,6 +1791,7 @@ when required by your organization's security policy.`,
17891791
YAML: "cliUpgradeMessage",
17901792
Group: &deploymentGroupClient,
17911793
Value: &c.CLIUpgradeMessage,
1794+
Default: defaultUpgradeMessage(),
17921795
Hidden: false,
17931796
},
17941797
{
@@ -2063,6 +2066,10 @@ type BuildInfoResponse struct {
20632066
// AgentAPIVersion is the current version of the Agent API (back versions
20642067
// MAY still be supported).
20652068
AgentAPIVersion string `json:"agent_api_version"`
2069+
2070+
// UpgradeMessage is the message displayed to users when an outdated client
2071+
// is detected.
2072+
UpgradeMessage string `json:"upgrade_message"`
20662073
}
20672074

20682075
type WorkspaceProxyBuildInfo struct {
@@ -2320,3 +2327,13 @@ func (c *Client) SSHConfiguration(ctx context.Context) (SSHConfigResponse, error
23202327
var sshConfig SSHConfigResponse
23212328
return sshConfig, json.NewDecoder(res.Body).Decode(&sshConfig)
23222329
}
2330+
2331+
func defaultUpgradeMessage() string {
2332+
// Our installation script doesn't work on Windows, so instead we direct the user
2333+
// to the GitHub release page to download the latest installer.
2334+
version := buildinfo.Version()
2335+
if runtime.GOOS == "windows" {
2336+
return fmt.Sprintf("download the server version from: https://github.com/coder/coder/releases/v%s", version)
2337+
}
2338+
return fmt.Sprintf("download the server version with: 'curl -L https://coder.com/install.sh | sh -s -- --version %s'", version)
2339+
}

0 commit comments

Comments
 (0)