diff --git a/api4/cloud.go b/api4/cloud.go index d517291d48..b9beec397b 100644 --- a/api4/cloud.go +++ b/api4/cloud.go @@ -52,6 +52,9 @@ func (api *API) InitCloud() { // POST /api/v4/cloud/webhook api.BaseRoutes.Cloud.Handle("/webhook", api.CloudAPIKeyRequired(handleCWSWebhook)).Methods("POST") + + // GET /api/v4/cloud/cws-health-check + api.BaseRoutes.Cloud.Handle("/check-cws-connection", api.APIHandler(handleCheckCWSConnection)).Methods("GET") } func getSubscription(c *Context, w http.ResponseWriter, r *http.Request) { @@ -746,3 +749,12 @@ func handleCWSWebhook(c *Context, w http.ResponseWriter, r *http.Request) { ReturnStatusOK(w) } + +func handleCheckCWSConnection(c *Context, w http.ResponseWriter, r *http.Request) { + if err := c.App.Cloud().CheckCWSConnection(); err != nil { + c.Err = model.NewAppError("Api4.handleCWSHealthCheck", "api.server.cws.health_check.app_error", nil, "CWS Server is not available.", http.StatusInternalServerError) + return + } + + ReturnStatusOK(w) +} diff --git a/einterfaces/cloud.go b/einterfaces/cloud.go index 0c70c02cf3..dadca484ff 100644 --- a/einterfaces/cloud.go +++ b/einterfaces/cloud.go @@ -45,4 +45,6 @@ type CloudInterface interface { CreateOrUpdateSubscriptionHistoryEvent(userID string, userCount int) (*model.SubscriptionHistory, error) HandleLicenseChange() error + + CheckCWSConnection() error } diff --git a/einterfaces/mocks/CloudInterface.go b/einterfaces/mocks/CloudInterface.go index a447399cd8..b0ef53c14f 100644 --- a/einterfaces/mocks/CloudInterface.go +++ b/einterfaces/mocks/CloudInterface.go @@ -60,6 +60,20 @@ func (_m *CloudInterface) ChangeSubscription(userID string, subscriptionID strin return r0, r1 } +// CheckCWSConnection provides a mock function with given fields: +func (_m *CloudInterface) CheckCWSConnection() error { + ret := _m.Called() + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + // ConfirmCustomerPayment provides a mock function with given fields: userID, confirmRequest func (_m *CloudInterface) ConfirmCustomerPayment(userID string, confirmRequest *model.ConfirmPaymentMethodRequest) error { ret := _m.Called(userID, confirmRequest) diff --git a/i18n/en.json b/i18n/en.json index a4cde3d1c8..93716f8a4b 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -2575,6 +2575,10 @@ "id": "api.scheme.patch_scheme.license.error", "translation": "Your license does not support update permissions schemes" }, + { + "id": "api.server.cws.health_check.app_error", + "translation": "CWS Server is not available." + }, { "id": "api.server.hosted_signup_unavailable.error", "translation": "Portal unavailable for self-hosted signup." diff --git a/model/client4.go b/model/client4.go index 298334d71a..85699eac6c 100644 --- a/model/client4.go +++ b/model/client4.go @@ -8700,6 +8700,17 @@ func (c *Client4) AddUserToGroupSyncables(userID string) (*Response, error) { return BuildResponse(r), nil } +func (c *Client4) CheckCWSConnection() (*Response, error) { + r, err := c.DoAPIGet(c.cloudRoute()+"/healthz", "") + + if err != nil { + return BuildResponse(r), err + } + defer closeBody(r) + + return BuildResponse(r), nil +} + // Worktemplates sections func (c *Client4) worktemplatesRoute() string {