Add POST and DELETE /license endpoints for v4 (#6665)

* Add POST and DELETE /license endpoints for v4

* Fix comment text
Этот коммит содержится в:
Joram Wilander
2017-06-19 13:46:51 -04:00
коммит произвёл Christopher Speller
родитель 59088a1687
Коммит 1d66e64e54
4 изменённых файлов: 164 добавлений и 7 удалений

Просмотреть файл

@@ -1835,7 +1835,7 @@ func (c *Client4) InvalidateCaches() (bool, *Response) {
}
}
// UpdateConfig will update the server configuration
// UpdateConfig will update the server configuration.
func (c *Client4) UpdateConfig(config *Config) (*Config, *Response) {
if r, err := c.DoApiPut(c.GetConfigRoute(), config.ToJson()); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
@@ -1845,6 +1845,50 @@ func (c *Client4) UpdateConfig(config *Config) (*Config, *Response) {
}
}
// UploadLicenseFile will add a license file to the system.
func (c *Client4) UploadLicenseFile(data []byte) (bool, *Response) {
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
if part, err := writer.CreateFormFile("license", "test-license.mattermost-license"); err != nil {
return false, &Response{Error: NewAppError("UploadLicenseFile", "model.client.set_profile_user.no_file.app_error", nil, err.Error(), http.StatusBadRequest)}
} else if _, err = io.Copy(part, bytes.NewBuffer(data)); err != nil {
return false, &Response{Error: NewAppError("UploadLicenseFile", "model.client.set_profile_user.no_file.app_error", nil, err.Error(), http.StatusBadRequest)}
}
if err := writer.Close(); err != nil {
return false, &Response{Error: NewAppError("UploadLicenseFile", "model.client.set_profile_user.writer.app_error", nil, err.Error(), http.StatusBadRequest)}
}
rq, _ := http.NewRequest("POST", c.ApiUrl+c.GetLicenseRoute(), bytes.NewReader(body.Bytes()))
rq.Header.Set("Content-Type", writer.FormDataContentType())
rq.Close = true
if len(c.AuthToken) > 0 {
rq.Header.Set(HEADER_AUTH, c.AuthType+" "+c.AuthToken)
}
if rp, err := c.HttpClient.Do(rq); err != nil {
return false, &Response{StatusCode: http.StatusForbidden, Error: NewAppError(c.GetLicenseRoute(), "model.client.connecting.app_error", nil, err.Error(), http.StatusForbidden)}
} else if rp.StatusCode >= 300 {
return false, &Response{StatusCode: rp.StatusCode, Error: AppErrorFromJson(rp.Body)}
} else {
defer closeBody(rp)
return CheckStatusOK(rp), BuildResponse(rp)
}
}
// RemoveLicenseFile will remove the server license it exists. Note that this will
// disable all enterprise features.
func (c *Client4) RemoveLicenseFile() (bool, *Response) {
if r, err := c.DoApiDelete(c.GetLicenseRoute()); err != nil {
return false, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return CheckStatusOK(r), BuildResponse(r)
}
}
// Webhooks Section
// CreateIncomingWebhook creates an incoming webhook for a channel.