From 93b2d6317a094df9951736c1baa32f612179cec0 Mon Sep 17 00:00:00 2001 From: ShiChangkuo <55725251+ShiChangkuo@users.noreply.github.com> Date: Wed, 6 Nov 2019 09:30:53 +0800 Subject: [PATCH] Fix two bugs for terraform-provider-huaweicloud (#225) * remove github.com/Unknwon/com in vendor github.com/Unknwon/com has changed to github.com/unknwon/com Signed-off-by: ShiChangkuo * add github.com/unknwon/com in vendor github.com/Unknwon/com has changed to github.com/unknwon/com Signed-off-by: ShiChangkuo * import github.com/unknwon/com in related files due to github.com/Unknwon/com has changed to github.com/unknwon/com, we should re-import it in huaweicloud/util.go * Log fault message when build compute instance failed --- go.mod | 4 +- go.sum | 5 +- ...esource_huaweicloud_compute_instance_v2.go | 5 ++ huaweicloud/util.go | 2 +- vendor/github.com/Unknwon/com/.travis.yml | 13 ----- .../{Unknwon => unknwon}/com/.gitignore | 0 vendor/github.com/unknwon/com/.travis.yml | 15 ++++++ .../{Unknwon => unknwon}/com/LICENSE | 0 .../{Unknwon => unknwon}/com/README.md | 6 +-- .../{Unknwon => unknwon}/com/cmd.go | 2 +- .../{Unknwon => unknwon}/com/convert.go | 10 ++++ .../{Unknwon => unknwon}/com/dir.go | 53 +++++++++++++++++-- .../{Unknwon => unknwon}/com/file.go | 0 vendor/github.com/unknwon/com/go.mod | 8 +++ vendor/github.com/unknwon/com/go.sum | 8 +++ .../{Unknwon => unknwon}/com/html.go | 2 +- .../{Unknwon => unknwon}/com/http.go | 2 +- .../{Unknwon => unknwon}/com/math.go | 4 +- .../{Unknwon => unknwon}/com/path.go | 0 .../{Unknwon => unknwon}/com/regex.go | 6 +-- .../{Unknwon => unknwon}/com/slice.go | 2 +- .../{Unknwon => unknwon}/com/string.go | 52 ++++++++++-------- .../{Unknwon => unknwon}/com/time.go | 0 .../{Unknwon => unknwon}/com/url.go | 0 vendor/modules.txt | 4 +- 25 files changed, 145 insertions(+), 58 deletions(-) delete mode 100644 vendor/github.com/Unknwon/com/.travis.yml rename vendor/github.com/{Unknwon => unknwon}/com/.gitignore (100%) create mode 100644 vendor/github.com/unknwon/com/.travis.yml rename vendor/github.com/{Unknwon => unknwon}/com/LICENSE (100%) rename vendor/github.com/{Unknwon => unknwon}/com/README.md (74%) rename vendor/github.com/{Unknwon => unknwon}/com/cmd.go (99%) rename vendor/github.com/{Unknwon => unknwon}/com/convert.go (94%) rename vendor/github.com/{Unknwon => unknwon}/com/dir.go (70%) rename vendor/github.com/{Unknwon => unknwon}/com/file.go (100%) create mode 100644 vendor/github.com/unknwon/com/go.mod create mode 100644 vendor/github.com/unknwon/com/go.sum rename vendor/github.com/{Unknwon => unknwon}/com/html.go (97%) rename vendor/github.com/{Unknwon => unknwon}/com/http.go (98%) rename vendor/github.com/{Unknwon => unknwon}/com/math.go (92%) rename vendor/github.com/{Unknwon => unknwon}/com/path.go (100%) rename vendor/github.com/{Unknwon => unknwon}/com/regex.go (89%) rename vendor/github.com/{Unknwon => unknwon}/com/slice.go (97%) rename vendor/github.com/{Unknwon => unknwon}/com/string.go (84%) rename vendor/github.com/{Unknwon => unknwon}/com/time.go (100%) rename vendor/github.com/{Unknwon => unknwon}/com/url.go (100%) diff --git a/go.mod b/go.mod index 2c19b83e1a..1aded92d76 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,15 @@ module github.com/terraform-providers/terraform-provider-huaweicloud require ( - github.com/Unknwon/com v0.0.0-20151008135407-28b053d5a292 github.com/aws/aws-sdk-go v1.22.0 - github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/go-cleanhttp v0.5.1 github.com/hashicorp/terraform-plugin-sdk v1.0.0 github.com/huaweicloud/golangsdk v0.0.0-20191105032058-c1a523be9414 github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a github.com/mitchellh/go-homedir v1.1.0 - github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect github.com/stretchr/testify v1.3.0 + github.com/unknwon/com v1.0.1 gopkg.in/yaml.v2 v2.2.2 ) diff --git a/go.sum b/go.sum index 6587b68ac6..02cd720535 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,6 @@ cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbf cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/Unknwon/com v0.0.0-20151008135407-28b053d5a292 h1:tuQ7w+my8a8mkwN7x2TSd7OzTjkZ7rAeSyH4xncuAMI= -github.com/Unknwon/com v0.0.0-20151008135407-28b053d5a292/go.mod h1:KYCjqMOeHpNuTOiFQU6WEcTG7poCJrUs0YgyHNtn1no= github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= @@ -188,6 +186,7 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 h1:Jpy1PXuP99tXNrhbq2BaPz9B+jNAvH1JPQQpG/9GCXY= github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa h1:E+gaaifzi2xF65PbDmuKI3PhLWY6G5opMLniFq8vmXA= github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa/go.mod h1:2RVY1rIf+2J2o/IM9+vPq9RzmHDSseB7FoXiSNIUsoU= github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc= @@ -200,6 +199,8 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/ulikunitz/xz v0.5.5 h1:pFrO0lVpTBXLpYw+pnLj6TbvHuyjXMfjGeCwSqCVwok= github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= +github.com/unknwon/com v1.0.1 h1:3d1LTxD+Lnf3soQiD4Cp/0BRB+Rsa/+RTvz8GMMzIXs= +github.com/unknwon/com v1.0.1/go.mod h1:tOOxU81rwgoCLoOVVPHb6T/wt8HZygqH5id+GNnlCXM= github.com/vmihailenco/msgpack v3.3.3+incompatible h1:wapg9xDUZDzGCNFlwc5SqI1rvcciqcxEHac4CYj89xI= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/zclconf/go-cty v1.0.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= diff --git a/huaweicloud/resource_huaweicloud_compute_instance_v2.go b/huaweicloud/resource_huaweicloud_compute_instance_v2.go index 6b2e2a61bd..f9e3794f78 100644 --- a/huaweicloud/resource_huaweicloud_compute_instance_v2.go +++ b/huaweicloud/resource_huaweicloud_compute_instance_v2.go @@ -823,6 +823,11 @@ func ServerV2StateRefreshFunc(client *golangsdk.ServiceClient, instanceID string return nil, "", err } + // get fault message when status is ERROR + if s.Status == "ERROR" { + fault := fmt.Errorf("[error code: %d, message: %s]", s.Fault.Code, s.Fault.Message) + return s, "ERROR", fault + } return s, s.Status, nil } } diff --git a/huaweicloud/util.go b/huaweicloud/util.go index 39b3d141b7..fa31e0dfe8 100644 --- a/huaweicloud/util.go +++ b/huaweicloud/util.go @@ -7,10 +7,10 @@ import ( "strings" "time" - "github.com/Unknwon/com" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/huaweicloud/golangsdk" + "github.com/unknwon/com" ) // BuildRequest takes an opts struct and builds a request body for diff --git a/vendor/github.com/Unknwon/com/.travis.yml b/vendor/github.com/Unknwon/com/.travis.yml deleted file mode 100644 index 882eb2d122..0000000000 --- a/vendor/github.com/Unknwon/com/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: go - -go: - - 1.2 - - 1.3 - - 1.4 - - tip - -install: go get -v -t - -notifications: - email: - - u@gogs.io \ No newline at end of file diff --git a/vendor/github.com/Unknwon/com/.gitignore b/vendor/github.com/unknwon/com/.gitignore similarity index 100% rename from vendor/github.com/Unknwon/com/.gitignore rename to vendor/github.com/unknwon/com/.gitignore diff --git a/vendor/github.com/unknwon/com/.travis.yml b/vendor/github.com/unknwon/com/.travis.yml new file mode 100644 index 0000000000..b36cd5c197 --- /dev/null +++ b/vendor/github.com/unknwon/com/.travis.yml @@ -0,0 +1,15 @@ +language: go + +go: + - 1.3.x + - 1.4.x + - 1.5.x + - 1.6.x + - 1.7.x + - 1.8.x + - 1.9.x + - 1.10.x + - 1.11.x + - 1.12.x + +install: go get -v -t diff --git a/vendor/github.com/Unknwon/com/LICENSE b/vendor/github.com/unknwon/com/LICENSE similarity index 100% rename from vendor/github.com/Unknwon/com/LICENSE rename to vendor/github.com/unknwon/com/LICENSE diff --git a/vendor/github.com/Unknwon/com/README.md b/vendor/github.com/unknwon/com/README.md similarity index 74% rename from vendor/github.com/Unknwon/com/README.md rename to vendor/github.com/unknwon/com/README.md index 8d821abd65..da0a23bc99 100644 --- a/vendor/github.com/Unknwon/com/README.md +++ b/vendor/github.com/unknwon/com/README.md @@ -1,13 +1,13 @@ Common Functions ================ -[![Build Status](https://travis-ci.org/Unknwon/com.svg)](https://travis-ci.org/Unknwon/com) [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/Unknwon/com) +[![Build Status](https://travis-ci.org/unknwon/com.svg)](https://travis-ci.org/unknwon/com) [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/unknwon/com) This is an open source project for commonly used functions for the Go programming language. -This package need >= **go 1.2** +This package need >= **go 1.3** -Code Convention: based on [Go Code Convention](https://github.com/Unknwon/go-code-convention). +Code Convention: based on [Go Code Convention](https://github.com/unknwon/go-code-convention). ## Contribute diff --git a/vendor/github.com/Unknwon/com/cmd.go b/vendor/github.com/unknwon/com/cmd.go similarity index 99% rename from vendor/github.com/Unknwon/com/cmd.go rename to vendor/github.com/unknwon/com/cmd.go index dc7086d8f7..5b4bbaee97 100644 --- a/vendor/github.com/Unknwon/com/cmd.go +++ b/vendor/github.com/unknwon/com/cmd.go @@ -1,4 +1,4 @@ -// +build go1.2 +// +build go1.3 // Copyright 2013 com authors // diff --git a/vendor/github.com/Unknwon/com/convert.go b/vendor/github.com/unknwon/com/convert.go similarity index 94% rename from vendor/github.com/Unknwon/com/convert.go rename to vendor/github.com/unknwon/com/convert.go index 25b3e0e562..bf24aa8bc3 100644 --- a/vendor/github.com/Unknwon/com/convert.go +++ b/vendor/github.com/unknwon/com/convert.go @@ -41,6 +41,11 @@ func (f StrTo) Int64() (int64, error) { return int64(v), err } +func (f StrTo) Float64() (float64, error) { + v, err := strconv.ParseFloat(f.String(), 64) + return float64(v), err +} + func (f StrTo) MustUint8() uint8 { v, _ := f.Uint8() return v @@ -56,6 +61,11 @@ func (f StrTo) MustInt64() int64 { return v } +func (f StrTo) MustFloat64() float64 { + v, _ := f.Float64() + return v +} + func (f StrTo) String() string { if f.Exist() { return string(f) diff --git a/vendor/github.com/Unknwon/com/dir.go b/vendor/github.com/unknwon/com/dir.go similarity index 70% rename from vendor/github.com/Unknwon/com/dir.go rename to vendor/github.com/unknwon/com/dir.go index c126d79da8..c16e9de333 100644 --- a/vendor/github.com/Unknwon/com/dir.go +++ b/vendor/github.com/unknwon/com/dir.go @@ -32,7 +32,7 @@ func IsDir(dir string) bool { return f.IsDir() } -func statDir(dirPath, recPath string, includeDir, isDirOnly bool) ([]string, error) { +func statDir(dirPath, recPath string, includeDir, isDirOnly, followSymlinks bool) ([]string, error) { dir, err := os.Open(dirPath) if err != nil { return nil, err @@ -56,13 +56,29 @@ func statDir(dirPath, recPath string, includeDir, isDirOnly bool) ([]string, err if includeDir { statList = append(statList, relPath+"/") } - s, err := statDir(curPath, relPath, includeDir, isDirOnly) + s, err := statDir(curPath, relPath, includeDir, isDirOnly, followSymlinks) if err != nil { return nil, err } statList = append(statList, s...) } else if !isDirOnly { statList = append(statList, relPath) + } else if followSymlinks && fi.Mode()&os.ModeSymlink != 0 { + link, err := os.Readlink(curPath) + if err != nil { + return nil, err + } + + if IsDir(link) { + if includeDir { + statList = append(statList, relPath+"/") + } + s, err := statDir(curPath, relPath, includeDir, isDirOnly, followSymlinks) + if err != nil { + return nil, err + } + statList = append(statList, s...) + } } } return statList, nil @@ -84,7 +100,26 @@ func StatDir(rootPath string, includeDir ...bool) ([]string, error) { if len(includeDir) >= 1 { isIncludeDir = includeDir[0] } - return statDir(rootPath, "", isIncludeDir, false) + return statDir(rootPath, "", isIncludeDir, false, false) +} + +// LstatDir gathers information of given directory by depth-first. +// It returns slice of file list, follows symbolic links and includes subdirectories if enabled; +// it returns error and nil slice when error occurs in underlying functions, +// or given path is not a directory or does not exist. +// +// Slice does not include given path itself. +// If subdirectories is enabled, they will have suffix '/'. +func LstatDir(rootPath string, includeDir ...bool) ([]string, error) { + if !IsDir(rootPath) { + return nil, errors.New("not a directory or does not exist: " + rootPath) + } + + isIncludeDir := false + if len(includeDir) >= 1 { + isIncludeDir = includeDir[0] + } + return statDir(rootPath, "", isIncludeDir, false, true) } // GetAllSubDirs returns all subdirectories of given root path. @@ -93,7 +128,17 @@ func GetAllSubDirs(rootPath string) ([]string, error) { if !IsDir(rootPath) { return nil, errors.New("not a directory or does not exist: " + rootPath) } - return statDir(rootPath, "", true, true) + return statDir(rootPath, "", true, true, false) +} + +// LgetAllSubDirs returns all subdirectories of given root path, including +// following symbolic links, if any. +// Slice does not include given path itself. +func LgetAllSubDirs(rootPath string) ([]string, error) { + if !IsDir(rootPath) { + return nil, errors.New("not a directory or does not exist: " + rootPath) + } + return statDir(rootPath, "", true, true, true) } // GetFileListBySuffix returns an ordered list of file paths. diff --git a/vendor/github.com/Unknwon/com/file.go b/vendor/github.com/unknwon/com/file.go similarity index 100% rename from vendor/github.com/Unknwon/com/file.go rename to vendor/github.com/unknwon/com/file.go diff --git a/vendor/github.com/unknwon/com/go.mod b/vendor/github.com/unknwon/com/go.mod new file mode 100644 index 0000000000..43834a963c --- /dev/null +++ b/vendor/github.com/unknwon/com/go.mod @@ -0,0 +1,8 @@ +module github.com/unknwon/com + +require ( + github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect + github.com/jtolds/gls v4.2.1+incompatible // indirect + github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect + github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c +) diff --git a/vendor/github.com/unknwon/com/go.sum b/vendor/github.com/unknwon/com/go.sum new file mode 100644 index 0000000000..3fcc30358b --- /dev/null +++ b/vendor/github.com/unknwon/com/go.sum @@ -0,0 +1,8 @@ +github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg= +github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE= +github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 h1:Jpy1PXuP99tXNrhbq2BaPz9B+jNAvH1JPQQpG/9GCXY= +github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c h1:Ho+uVpkel/udgjbwB5Lktg9BtvJSh2DT0Hi6LPSyI2w= +github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= diff --git a/vendor/github.com/Unknwon/com/html.go b/vendor/github.com/unknwon/com/html.go similarity index 97% rename from vendor/github.com/Unknwon/com/html.go rename to vendor/github.com/unknwon/com/html.go index 762d94b050..8a99df4e08 100644 --- a/vendor/github.com/Unknwon/com/html.go +++ b/vendor/github.com/unknwon/com/html.go @@ -36,7 +36,7 @@ func HtmlEncode(str string) string { return html.EscapeString(str) } -// decode string to html chars +// HtmlDecode decodes string to html chars func HtmlDecode(str string) string { return html.UnescapeString(str) } diff --git a/vendor/github.com/Unknwon/com/http.go b/vendor/github.com/unknwon/com/http.go similarity index 98% rename from vendor/github.com/Unknwon/com/http.go rename to vendor/github.com/unknwon/com/http.go index 3415059ae9..cf0820f378 100644 --- a/vendor/github.com/Unknwon/com/http.go +++ b/vendor/github.com/unknwon/com/http.go @@ -177,7 +177,7 @@ func FetchFiles(client *http.Client, files []RawFile, header http.Header) error return nil } -// FetchFiles uses command `curl` to fetch files specified by the rawURL field in parallel. +// FetchFilesCurl uses command `curl` to fetch files specified by the rawURL field in parallel. func FetchFilesCurl(files []RawFile, curlOptions ...string) error { ch := make(chan error, len(files)) for i := range files { diff --git a/vendor/github.com/Unknwon/com/math.go b/vendor/github.com/unknwon/com/math.go similarity index 92% rename from vendor/github.com/Unknwon/com/math.go rename to vendor/github.com/unknwon/com/math.go index 99c56b6594..62b77e87c8 100644 --- a/vendor/github.com/Unknwon/com/math.go +++ b/vendor/github.com/unknwon/com/math.go @@ -14,12 +14,12 @@ package com -// PowInt is int type of math.Pow function. +// PowInt is int type of math.Pow function. func PowInt(x int, y int) int { if y <= 0 { return 1 } else { - if y % 2 == 0 { + if y%2 == 0 { sqrt := PowInt(x, y/2) return sqrt * sqrt } else { diff --git a/vendor/github.com/Unknwon/com/path.go b/vendor/github.com/unknwon/com/path.go similarity index 100% rename from vendor/github.com/Unknwon/com/path.go rename to vendor/github.com/unknwon/com/path.go diff --git a/vendor/github.com/Unknwon/com/regex.go b/vendor/github.com/unknwon/com/regex.go similarity index 89% rename from vendor/github.com/Unknwon/com/regex.go rename to vendor/github.com/unknwon/com/regex.go index 765bfc4311..14926474e0 100644 --- a/vendor/github.com/Unknwon/com/regex.go +++ b/vendor/github.com/unknwon/com/regex.go @@ -37,19 +37,19 @@ func init() { regex_url = regexp.MustCompile(regex_url_pattern) } -// validate string is an email address, if not return false +// IsEmail validates string is an email address, if not return false // basically validation can match 99% cases func IsEmail(email string) bool { return regex_email.MatchString(email) } -// validate string is an email address, if not return false +// IsEmailRFC validates string is an email address, if not return false // this validation omits RFC 2822 func IsEmailRFC(email string) bool { return regex_strict_email.MatchString(email) } -// validate string is a url link, if not return false +// IsUrl validates string is a url link, if not return false // simple validation can match 99% cases func IsUrl(url string) bool { return regex_url.MatchString(url) diff --git a/vendor/github.com/Unknwon/com/slice.go b/vendor/github.com/unknwon/com/slice.go similarity index 97% rename from vendor/github.com/Unknwon/com/slice.go rename to vendor/github.com/unknwon/com/slice.go index 27801a4d7d..c3c9ab2e72 100644 --- a/vendor/github.com/Unknwon/com/slice.go +++ b/vendor/github.com/unknwon/com/slice.go @@ -44,7 +44,7 @@ func CompareSliceStr(s1, s2 []string) bool { return true } -// CompareSliceStr compares two 'string' type slices. +// CompareSliceStrU compares two 'string' type slices. // It returns true if elements are the same, and ignores the order. func CompareSliceStrU(s1, s2 []string) bool { if len(s1) != len(s2) { diff --git a/vendor/github.com/Unknwon/com/string.go b/vendor/github.com/unknwon/com/string.go similarity index 84% rename from vendor/github.com/Unknwon/com/string.go rename to vendor/github.com/unknwon/com/string.go index 4c79820f1f..7080d174a8 100644 --- a/vendor/github.com/Unknwon/com/string.go +++ b/vendor/github.com/unknwon/com/string.go @@ -19,9 +19,7 @@ import ( "crypto/aes" "crypto/cipher" "crypto/rand" - "encoding/base64" "errors" - "io" r "math/rand" "strconv" "strings" @@ -30,41 +28,53 @@ import ( "unicode/utf8" ) -// AESEncrypt encrypts text and given key with AES. -func AESEncrypt(key, text []byte) ([]byte, error) { +// AESGCMEncrypt encrypts plaintext with the given key using AES in GCM mode. +func AESGCMEncrypt(key, plaintext []byte) ([]byte, error) { block, err := aes.NewCipher(key) if err != nil { return nil, err } - b := base64.StdEncoding.EncodeToString(text) - ciphertext := make([]byte, aes.BlockSize+len(b)) - iv := ciphertext[:aes.BlockSize] - if _, err := io.ReadFull(rand.Reader, iv); err != nil { + + gcm, err := cipher.NewGCM(block) + if err != nil { return nil, err } - cfb := cipher.NewCFBEncrypter(block, iv) - cfb.XORKeyStream(ciphertext[aes.BlockSize:], []byte(b)) - return ciphertext, nil + + nonce := make([]byte, gcm.NonceSize()) + if _, err := rand.Read(nonce); err != nil { + return nil, err + } + + ciphertext := gcm.Seal(nil, nonce, plaintext, nil) + return append(nonce, ciphertext...), nil } -// AESDecrypt decrypts text and given key with AES. -func AESDecrypt(key, text []byte) ([]byte, error) { +// AESGCMDecrypt decrypts ciphertext with the given key using AES in GCM mode. +func AESGCMDecrypt(key, ciphertext []byte) ([]byte, error) { block, err := aes.NewCipher(key) if err != nil { return nil, err } - if len(text) < aes.BlockSize { - return nil, errors.New("ciphertext too short") + + gcm, err := cipher.NewGCM(block) + if err != nil { + return nil, err + } + + size := gcm.NonceSize() + if len(ciphertext)-size <= 0 { + return nil, errors.New("Ciphertext is empty") } - iv := text[:aes.BlockSize] - text = text[aes.BlockSize:] - cfb := cipher.NewCFBDecrypter(block, iv) - cfb.XORKeyStream(text, text) - data, err := base64.StdEncoding.DecodeString(string(text)) + + nonce := ciphertext[:size] + ciphertext = ciphertext[size:] + + plainText, err := gcm.Open(nil, nonce, ciphertext, nil) if err != nil { return nil, err } - return data, nil + + return plainText, nil } // IsLetter returns true if the 'l' is an English letter. diff --git a/vendor/github.com/Unknwon/com/time.go b/vendor/github.com/unknwon/com/time.go similarity index 100% rename from vendor/github.com/Unknwon/com/time.go rename to vendor/github.com/unknwon/com/time.go diff --git a/vendor/github.com/Unknwon/com/url.go b/vendor/github.com/unknwon/com/url.go similarity index 100% rename from vendor/github.com/Unknwon/com/url.go rename to vendor/github.com/unknwon/com/url.go diff --git a/vendor/modules.txt b/vendor/modules.txt index a00cfe65d9..6acc3b6383 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -6,8 +6,6 @@ cloud.google.com/go/internal/optional cloud.google.com/go/internal/trace cloud.google.com/go/internal/version cloud.google.com/go/compute/metadata -# github.com/Unknwon/com v0.0.0-20151008135407-28b053d5a292 -github.com/Unknwon/com # github.com/agext/levenshtein v1.2.2 github.com/agext/levenshtein # github.com/apparentlymart/go-cidr v1.0.1 @@ -341,6 +339,8 @@ github.com/ulikunitz/xz github.com/ulikunitz/xz/internal/xlog github.com/ulikunitz/xz/lzma github.com/ulikunitz/xz/internal/hash +# github.com/unknwon/com v1.0.1 +github.com/unknwon/com # github.com/vmihailenco/msgpack v3.3.3+incompatible github.com/vmihailenco/msgpack github.com/vmihailenco/msgpack/codes