summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/platform/model/utils.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2016-11-12 22:00:53 +0100
committerWim <wim@42.be>2016-11-12 22:00:53 +0100
commit1d5cd1d7c479c382c9cddaf02f1e59bf55971f12 (patch)
treeabaf22fc41326750e376f0831537bbbbe769d5b2 /vendor/github.com/mattermost/platform/model/utils.go
parent08ebee6b4faf677da159db1cffea292050492fd5 (diff)
downloadmatterbridge-msglm-1d5cd1d7c479c382c9cddaf02f1e59bf55971f12.tar.gz
matterbridge-msglm-1d5cd1d7c479c382c9cddaf02f1e59bf55971f12.tar.bz2
matterbridge-msglm-1d5cd1d7c479c382c9cddaf02f1e59bf55971f12.zip
Sync with mattermost 3.5.0
Diffstat (limited to 'vendor/github.com/mattermost/platform/model/utils.go')
-rw-r--r--vendor/github.com/mattermost/platform/model/utils.go101
1 files changed, 54 insertions, 47 deletions
diff --git a/vendor/github.com/mattermost/platform/model/utils.go b/vendor/github.com/mattermost/platform/model/utils.go
index a4a4208c..457b64c0 100644
--- a/vendor/github.com/mattermost/platform/model/utils.go
+++ b/vendor/github.com/mattermost/platform/model/utils.go
@@ -10,6 +10,7 @@ import (
"encoding/json"
"fmt"
"io"
+ "io/ioutil"
"net/mail"
"net/url"
"regexp"
@@ -74,13 +75,21 @@ func (er *AppError) ToJson() string {
// AppErrorFromJson will decode the input and return an AppError
func AppErrorFromJson(data io.Reader) *AppError {
- decoder := json.NewDecoder(data)
+ str := ""
+ bytes, rerr := ioutil.ReadAll(data)
+ if rerr != nil {
+ str = rerr.Error()
+ } else {
+ str = string(bytes)
+ }
+
+ decoder := json.NewDecoder(strings.NewReader(str))
var er AppError
err := decoder.Decode(&er)
if err == nil {
return &er
} else {
- return NewLocAppError("AppErrorFromJson", "model.utils.decode_json.app_error", nil, err.Error())
+ return NewLocAppError("AppErrorFromJson", "model.utils.decode_json.app_error", nil, "body: "+str)
}
}
@@ -166,6 +175,23 @@ func ArrayFromJson(data io.Reader) []string {
}
}
+func ArrayFromInterface(data interface{}) []string {
+ stringArray := []string{}
+
+ dataArray, ok := data.([]interface{})
+ if !ok {
+ return stringArray
+ }
+
+ for _, v := range dataArray {
+ if str, ok := v.(string); ok {
+ stringArray = append(stringArray, str)
+ }
+ }
+
+ return stringArray
+}
+
func StringInterfaceToJson(objmap map[string]interface{}) string {
if b, err := json.Marshal(objmap); err != nil {
return ""
@@ -227,58 +253,15 @@ func IsValidEmail(email string) bool {
}
var reservedName = []string{
- "www",
- "web",
+ "signup",
+ "login",
"admin",
- "support",
- "notify",
- "test",
- "demo",
- "mail",
- "team",
"channel",
- "internal",
- "localhost",
- "dockerhost",
- "stag",
"post",
- "cluster",
"api",
"oauth",
}
-var wwwStart = regexp.MustCompile(`^www`)
-var betaStart = regexp.MustCompile(`^beta`)
-var ciStart = regexp.MustCompile(`^ci`)
-
-func GetSubDomain(s string) (string, string) {
- s = strings.Replace(s, "http://", "", 1)
- s = strings.Replace(s, "https://", "", 1)
-
- match := wwwStart.MatchString(s)
- if match {
- return "", ""
- }
-
- match = betaStart.MatchString(s)
- if match {
- return "", ""
- }
-
- match = ciStart.MatchString(s)
- if match {
- return "", ""
- }
-
- parts := strings.Split(s, ".")
-
- if len(parts) != 3 {
- return "", ""
- }
-
- return parts[0], parts[1]
-}
-
func IsValidChannelIdentifier(s string) bool {
if !IsValidAlphaNum(s, true) {
@@ -413,6 +396,18 @@ func IsValidHttpsUrl(rawUrl string) bool {
return true
}
+func IsValidTurnOrStunServer(rawUri string) bool {
+ if strings.Index(rawUri, "turn:") != 0 && strings.Index(rawUri, "stun:") != 0 {
+ return false
+ }
+
+ if _, err := url.ParseRequestURI(rawUri); err != nil {
+ return false
+ }
+
+ return true
+}
+
func IsSafeLink(link *string) bool {
if link != nil {
if IsValidHttpUrl(*link) {
@@ -426,3 +421,15 @@ func IsSafeLink(link *string) bool {
return true
}
+
+func IsValidWebsocketUrl(rawUrl string) bool {
+ if strings.Index(rawUrl, "ws://") != 0 && strings.Index(rawUrl, "wss://") != 0 {
+ return false
+ }
+
+ if _, err := url.ParseRequestURI(rawUrl); err != nil {
+ return false
+ }
+
+ return true
+}