feat: Add support for update checks and notifications (#4810)

Co-authored-by: Kira Pilot <kira@coder.com>
This commit is contained in:
Mathias Fredriksson
2022-12-01 19:43:28 +02:00
committed by GitHub
co-authored by Kira Pilot
parent 4f1cf6c9d8
commit d9f2aaf3b4
32 changed files with 1088 additions and 22 deletions
+1
View File
@@ -41,6 +41,7 @@ type DeploymentConfig struct {
Provisioner *ProvisionerConfig `json:"provisioner" typescript:",notnull"`
APIRateLimit *DeploymentConfigField[int] `json:"api_rate_limit" typescript:",notnull"`
Experimental *DeploymentConfigField[bool] `json:"experimental" typescript:",notnull"`
UpdateCheck *DeploymentConfigField[bool] `json:"update_check" typescript:",notnull"`
}
type DERP struct {
+37
View File
@@ -0,0 +1,37 @@
package codersdk
import (
"context"
"encoding/json"
"net/http"
)
// UpdateCheckResponse contains information
// on the latest release of Coder.
type UpdateCheckResponse struct {
// Current is a boolean indicating whether the
// server version is the same as the latest.
Current bool `json:"current"`
// Version is the semantic version for the latest
// release of Coder.
Version string `json:"version"`
// URL to download the latest release of Coder.
URL string `json:"url"`
}
// UpdateCheck returns information about the latest release version of
// Coder and whether or not the server is running the latest release.
func (c *Client) UpdateCheck(ctx context.Context) (UpdateCheckResponse, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/updatecheck", nil)
if err != nil {
return UpdateCheckResponse{}, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return UpdateCheckResponse{}, readBodyAsError(res)
}
var buildInfo UpdateCheckResponse
return buildInfo, json.NewDecoder(res.Body).Decode(&buildInfo)
}