summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-07-04 16:12:02 -0400
committerGitHub <noreply@github.com>2017-07-04 16:12:02 -0400
commit8ec8948c84e946fde736add0c4e6dd55f6efd1ab (patch)
treeb6388c965c797d4dfe9c860b93b4249107b9a7b0
parent4bd7b68b24137a9f8fe0abc908831cf95bb6c32b (diff)
downloadchat-8ec8948c84e946fde736add0c4e6dd55f6efd1ab.tar.gz
chat-8ec8948c84e946fde736add0c4e6dd55f6efd1ab.tar.bz2
chat-8ec8948c84e946fde736add0c4e6dd55f6efd1ab.zip
PLT-6554 Add config setting to control enabling API version 3 (#6835)
* Add config setting to control enabling API version 3 * Update help text for APIv3 config setting (#6843) * Update configuration_settings.jsx * Update en.json
-rw-r--r--api/admin_test.go22
-rw-r--r--api/api.go5
-rw-r--r--api/context.go4
-rw-r--r--app/diagnostics.go1
-rw-r--r--config/config.json1
-rw-r--r--i18n/en.json4
-rw-r--r--model/config.go6
-rw-r--r--webapp/components/admin_console/configuration_settings.jsx23
-rwxr-xr-xwebapp/i18n/en.json2
9 files changed, 66 insertions, 2 deletions
diff --git a/api/admin_test.go b/api/admin_test.go
index a93257626..d5f24b715 100644
--- a/api/admin_test.go
+++ b/api/admin_test.go
@@ -4,6 +4,7 @@
package api
import (
+ "net/http"
"strings"
"testing"
@@ -652,3 +653,24 @@ func TestGetRecentlyActiveUsers(t *testing.T) {
t.Fatal("should have been at least 2")
}
}
+
+func TestDisableAPIv3(t *testing.T) {
+ th := Setup().InitBasic()
+ Client := th.BasicClient
+
+ enableAPIv3 := *utils.Cfg.ServiceSettings.EnableAPIv3
+ defer func() {
+ *utils.Cfg.ServiceSettings.EnableAPIv3 = enableAPIv3
+ }()
+ *utils.Cfg.ServiceSettings.EnableAPIv3 = false
+
+ _, err := Client.GetUser(th.BasicUser.Id, "")
+
+ if err.StatusCode != http.StatusNotImplemented {
+ t.Fatal("wrong error code")
+ }
+
+ if err.Id != "api.context.v3_disabled.app_error" {
+ t.Fatal("wrong error message")
+ }
+}
diff --git a/api/api.go b/api/api.go
index c9c876b02..7e902c159 100644
--- a/api/api.go
+++ b/api/api.go
@@ -6,6 +6,7 @@ package api
import (
"net/http"
+ l4g "github.com/alecthomas/log4go"
"github.com/gorilla/mux"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/einterfaces"
@@ -115,6 +116,10 @@ func InitApi() {
utils.InitHTML()
app.InitEmailBatching()
+
+ if *utils.Cfg.ServiceSettings.EnableAPIv3 {
+ l4g.Info("API version 3 is scheduled for deprecation. Please see https://api.mattermost.com for details.")
+ }
}
func HandleEtag(etag string, routeName string, w http.ResponseWriter, r *http.Request) bool {
diff --git a/api/context.go b/api/context.go
index 6d1e758e8..09cb1e583 100644
--- a/api/context.go
+++ b/api/context.go
@@ -205,6 +205,10 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
c.Path = "/" + strings.Join(splitURL[2:], "/")
}
+ if h.isApi && !*utils.Cfg.ServiceSettings.EnableAPIv3 {
+ c.Err = model.NewAppError("ServeHTTP", "api.context.v3_disabled.app_error", nil, "", http.StatusNotImplemented)
+ }
+
if c.Err == nil && h.requireUser {
c.UserRequired()
}
diff --git a/app/diagnostics.go b/app/diagnostics.go
index 97f4df0da..04e48088e 100644
--- a/app/diagnostics.go
+++ b/app/diagnostics.go
@@ -163,6 +163,7 @@ func trackConfig() {
"enable_only_admin_integrations": *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations,
"enable_post_username_override": utils.Cfg.ServiceSettings.EnablePostUsernameOverride,
"enable_post_icon_override": utils.Cfg.ServiceSettings.EnablePostIconOverride,
+ "enable_apiv3": *utils.Cfg.ServiceSettings.EnableAPIv3,
"enable_custom_emoji": *utils.Cfg.ServiceSettings.EnableCustomEmoji,
"restrict_custom_emoji_creation": *utils.Cfg.ServiceSettings.RestrictCustomEmojiCreation,
"enable_testing": utils.Cfg.ServiceSettings.EnableTesting,
diff --git a/config/config.json b/config/config.json
index 348467e98..57f4ef263 100644
--- a/config/config.json
+++ b/config/config.json
@@ -21,6 +21,7 @@
"EnableOnlyAdminIntegrations": true,
"EnablePostUsernameOverride": false,
"EnablePostIconOverride": false,
+ "EnableAPIv3": true,
"EnableLinkPreviews": false,
"EnableTesting": false,
"EnableDeveloper": false,
diff --git a/i18n/en.json b/i18n/en.json
index 308374ad4..640ed93ea 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -896,6 +896,10 @@
"translation": "Sorry, we could not find the page."
},
{
+ "id": "api.context.v3_disabled.app_error",
+ "translation": "API version 3 has been disabled on this server. Please use API version 4. See https://api.mattermost.com for details."
+ },
+ {
"id": "api.context.invalid_body_param.app_error",
"translation": "Invalid or missing {{.Name}} in request body"
},
diff --git a/model/config.go b/model/config.go
index 9dedaf2fc..25b4d8632 100644
--- a/model/config.go
+++ b/model/config.go
@@ -142,6 +142,7 @@ type ServiceSettings struct {
EnableOnlyAdminIntegrations *bool
EnablePostUsernameOverride bool
EnablePostIconOverride bool
+ EnableAPIv3 *bool
EnableLinkPreviews *bool
EnableTesting bool
EnableDeveloper *bool
@@ -563,6 +564,11 @@ func (o *Config) SetDefaults() {
o.ServiceSettings.LicenseFileLocation = new(string)
}
+ if o.ServiceSettings.EnableAPIv3 == nil {
+ o.ServiceSettings.EnableAPIv3 = new(bool)
+ *o.ServiceSettings.EnableAPIv3 = true
+ }
+
if o.ServiceSettings.EnableLinkPreviews == nil {
o.ServiceSettings.EnableLinkPreviews = new(bool)
*o.ServiceSettings.EnableLinkPreviews = false
diff --git a/webapp/components/admin_console/configuration_settings.jsx b/webapp/components/admin_console/configuration_settings.jsx
index 72bd0e330..6ac68a3bb 100644
--- a/webapp/components/admin_console/configuration_settings.jsx
+++ b/webapp/components/admin_console/configuration_settings.jsx
@@ -2,7 +2,7 @@
// See License.txt for license information.
import React from 'react';
-import {FormattedMessage} from 'react-intl';
+import {FormattedMessage, FormattedHTMLMessage} from 'react-intl';
import ErrorStore from 'stores/error_store.jsx';
@@ -47,6 +47,7 @@ export default class ConfigurationSettings extends AdminSettings {
config.ServiceSettings.Forward80To443 = this.state.forward80To443;
config.ServiceSettings.ReadTimeout = this.parseIntNonZero(this.state.readTimeout);
config.ServiceSettings.WriteTimeout = this.parseIntNonZero(this.state.writeTimeout);
+ config.ServiceSettings.EnableAPIv3 = this.state.enableAPIv3;
return config;
}
@@ -63,7 +64,8 @@ export default class ConfigurationSettings extends AdminSettings {
letsEncryptCertificateCacheFile: config.ServiceSettings.LetsEncryptCertificateCacheFile,
forward80To443: config.ServiceSettings.Forward80To443,
readTimeout: config.ServiceSettings.ReadTimeout,
- writeTimeout: config.ServiceSettings.WriteTimeout
+ writeTimeout: config.ServiceSettings.WriteTimeout,
+ enableAPIv3: config.ServiceSettings.EnableAPIv3
};
}
@@ -304,6 +306,23 @@ export default class ConfigurationSettings extends AdminSettings {
value={this.state.writeTimeout}
onChange={this.handleChange}
/>
+ <BooleanSetting
+ id='enableAPIv3'
+ label={
+ <FormattedMessage
+ id='admin.service.enableAPIv3'
+ defaultMessage='Allow use of API v3 endpoints:'
+ />
+ }
+ helpText={
+ <FormattedHTMLMessage
+ id='admin.service.enableAPIv3Description'
+ defaultMessage='Set to false to disable all version 3 endpoints of the REST API. Integrations that rely on API v3 will fail and can then be identified for migration to API v4. API v3 is deprecated and will be removed in the near future. See <a href="https://api.mattermost.com" target="_blank">https://api.mattermost.com</a> for details.'
+ />
+ }
+ value={this.state.enableAPIv3}
+ onChange={this.handleChange}
+ />
<WebserverModeDropdownSetting
value={this.state.webserverMode}
onChange={this.handleChange}
diff --git a/webapp/i18n/en.json b/webapp/i18n/en.json
index 037809d1a..8d36cf610 100755
--- a/webapp/i18n/en.json
+++ b/webapp/i18n/en.json
@@ -701,6 +701,8 @@
"admin.service.corsTitle": "Enable cross-origin requests from:",
"admin.service.developerDesc": "When true, JavaScript errors are shown in a purple bar at the top of the user interface. Not recommended for use in production. ",
"admin.service.developerTitle": "Enable Developer Mode: ",
+ "admin.service.enableAPIv3": "Allow use of API v3 endpoints:",
+ "admin.service.enableAPIv3Description": "Set to false to disable all version 3 endpoints of the REST API. Integrations that rely on API v3 will fail and can then be identified for migration to API v4. API v3 is deprecated and will be removed in the near future. See <a href='https://api.mattermost.com' target='_blank'>https://api.mattermost.com</a> for details.",
"admin.service.enforceMfaDesc": "When true, <a href='https://docs.mattermost.com/deployment/auth.html' target='_blank'>multi-factor authentication</a> is required for login. New users will be required to configure MFA on signup. Logged in users without MFA configured are redirected to the MFA setup page until configuration is complete.<br/><br/>If your system has users with login methods other than AD/LDAP and email, MFA must be enforced with the authentication provider outside of Mattermost.",
"admin.service.enforceMfaTitle": "Enforce Multi-factor Authentication:",
"admin.service.forward80To443": "Forward port 80 to 443:",