diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-06-19 13:46:51 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-06-19 10:46:51 -0700 |
commit | 1d66e64e54c59ea9184bd614790498451d025e25 (patch) | |
tree | 605353f462cde5eac7c36bec4a4b7d05e6fede2b /model/client4.go | |
parent | 59088a1687b999e40d7468ad27997d2ec78a294e (diff) | |
download | chat-1d66e64e54c59ea9184bd614790498451d025e25.tar.gz chat-1d66e64e54c59ea9184bd614790498451d025e25.tar.bz2 chat-1d66e64e54c59ea9184bd614790498451d025e25.zip |
Add POST and DELETE /license endpoints for v4 (#6665)
* Add POST and DELETE /license endpoints for v4
* Fix comment text
Diffstat (limited to 'model/client4.go')
-rw-r--r-- | model/client4.go | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/model/client4.go b/model/client4.go index c692a8415..cfecd7b25 100644 --- a/model/client4.go +++ b/model/client4.go @@ -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. |