Commit be66ed9d by Oleg Gaidarenko Committed by GitHub

Chore: explore possibilities of using makefile (#17039)

* Chore: explore possibilities of using makefile

This is an exploratory commit - I wanted to see how
revive/gosec linters could be integrated with makefile and our build scripts.

Looks better then I expected :)

* Chore: make revive happy

Revive execution was not supplied with path, if you restore there is couple
errors that were popping up - so I fixed them

* Chore: make revive happy
parent 8483a836
...@@ -79,10 +79,12 @@ debug.test ...@@ -79,10 +79,12 @@ debug.test
/scripts/build/release_publisher/release_publisher /scripts/build/release_publisher/release_publisher
*.patch *.patch
# Ignoring frontend packages specifics # Ignoring frontend packages specifics
/packages/**/dist /packages/**/dist
/packages/**/compiled /packages/**/compiled
/packages/**/.rpt2_cache /packages/**/.rpt2_cache
theOutput/ theOutput/
# Ignore go local build dependencies
/scripts/go/bin/**
-include local/Makefile -include local/Makefile
.PHONY: all deps-go deps-js deps build-go build-server build-cli build-js build build-docker-dev build-docker-full lint-go test-go test-js test run clean .PHONY: all deps-go deps-js deps build-go build-server build-cli build-js build build-docker-dev build-docker-full lint-go test-go test-js test run clean gosec revive
GO := GO111MODULE=on go
GO_FILES := ./pkg/...
all: deps build all: deps build
...@@ -66,3 +69,24 @@ clean: ...@@ -66,3 +69,24 @@ clean:
node_modules: package.json yarn.lock node_modules: package.json yarn.lock
@echo "install frontend dependencies" @echo "install frontend dependencies"
yarn install --pure-lockfile --no-progress yarn install --pure-lockfile --no-progress
scripts/go/bin/revive: scripts/go/go.mod
@cd scripts/go; \
$(GO) build -o ./bin/revive github.com/mgechev/revive
scripts/go/bin/gosec: scripts/go/go.mod
@cd scripts/go; \
$(GO) build -o ./bin/gosec github.com/securego/gosec/cmd/gosec
revive: scripts/go/bin/revive
@scripts/go/bin/revive \
-formatter stylish \
-config ./scripts/go/configs/revive.toml \
$(GO_FILES)
# TODO recheck the rules and leave only necessary exclusions
gosec: scripts/go/bin/gosec
@scripts/go/bin/gosec -quiet \
-exclude=G104,G107,G201,G202,G204,G301,G304,G401,G402,G501 \
-conf=./scripts/go/configs/gosec.json \
$(GO_FILES)
...@@ -21,7 +21,7 @@ var ( ...@@ -21,7 +21,7 @@ var (
IoHelper m.IoUtil = IoUtilImp{} IoHelper m.IoUtil = IoUtilImp{}
HttpClient http.Client HttpClient http.Client
grafanaVersion string grafanaVersion string
NotFoundError = errors.New("404 not found error") ErrNotFoundError = errors.New("404 not found error")
) )
func Init(version string, skipTLSVerify bool) { func Init(version string, skipTLSVerify bool) {
...@@ -131,7 +131,7 @@ func GetPlugin(pluginId, repoUrl string) (m.Plugin, error) { ...@@ -131,7 +131,7 @@ func GetPlugin(pluginId, repoUrl string) (m.Plugin, error) {
if err != nil { if err != nil {
logger.Info("Failed to send request: ", err) logger.Info("Failed to send request: ", err)
if err == NotFoundError { if err == ErrNotFoundError {
return m.Plugin{}, fmt.Errorf("Failed to find requested plugin, check if the plugin_id is correct. error: %v", err) return m.Plugin{}, fmt.Errorf("Failed to find requested plugin, check if the plugin_id is correct. error: %v", err)
} }
return m.Plugin{}, fmt.Errorf("Failed to send request. error: %v", err) return m.Plugin{}, fmt.Errorf("Failed to send request. error: %v", err)
...@@ -174,7 +174,7 @@ func sendRequest(repoUrl string, subPaths ...string) ([]byte, error) { ...@@ -174,7 +174,7 @@ func sendRequest(repoUrl string, subPaths ...string) ([]byte, error) {
} }
if res.StatusCode == 404 { if res.StatusCode == 404 {
return []byte{}, NotFoundError return []byte{}, ErrNotFoundError
} }
if res.StatusCode/100 != 2 { if res.StatusCode/100 != 2 {
return []byte{}, fmt.Errorf("Api returned invalid status: %s", res.Status) return []byte{}, fmt.Errorf("Api returned invalid status: %s", res.Status)
......
...@@ -31,12 +31,12 @@ func isDevEnvironment() bool { ...@@ -31,12 +31,12 @@ func isDevEnvironment() bool {
defaultsPath := filepath.Join(exPath, "../conf/defaults.ini") defaultsPath := filepath.Join(exPath, "../conf/defaults.ini")
_, err = os.Stat(defaultsPath) _, err = os.Stat(defaultsPath)
return err == nil return err == nil
} else { }
// But at the same time there are per platform directories that contain the binaries and can also be used. // But at the same time there are per platform directories that contain the binaries and can also be used.
defaultsPath := filepath.Join(exPath, "../../conf/defaults.ini") defaultsPath := filepath.Join(exPath, "../../conf/defaults.ini")
_, err = os.Stat(defaultsPath) _, err = os.Stat(defaultsPath)
return err == nil return err == nil
}
} }
func returnOsDefault(currentOs string) string { func returnOsDefault(currentOs string) string {
......
...@@ -9,7 +9,7 @@ var ( ...@@ -9,7 +9,7 @@ var (
ErrProviderDeniedRequest = errors.New("Login provider denied login request") ErrProviderDeniedRequest = errors.New("Login provider denied login request")
ErrSignUpNotAllowed = errors.New("Signup is not allowed for this adapter") ErrSignUpNotAllowed = errors.New("Signup is not allowed for this adapter")
ErrTooManyLoginAttempts = errors.New("Too many consecutive incorrect login attempts for user. Login for user temporarily blocked") ErrTooManyLoginAttempts = errors.New("Too many consecutive incorrect login attempts for user. Login for user temporarily blocked")
ErrPasswordEmpty = errors.New("No password provided.") ErrPasswordEmpty = errors.New("No password provided")
ErrUsersQuotaReached = errors.New("Users quota reached") ErrUsersQuotaReached = errors.New("Users quota reached")
ErrGettingUserQuota = errors.New("Error getting user quota") ErrGettingUserQuota = errors.New("Error getting user quota")
) )
...@@ -25,9 +25,8 @@ func (dpm *DashboardProvisionerMock) Provision() error { ...@@ -25,9 +25,8 @@ func (dpm *DashboardProvisionerMock) Provision() error {
dpm.Calls.Provision = append(dpm.Calls.Provision, nil) dpm.Calls.Provision = append(dpm.Calls.Provision, nil)
if dpm.ProvisionFunc != nil { if dpm.ProvisionFunc != nil {
return dpm.ProvisionFunc() return dpm.ProvisionFunc()
} else {
return nil
} }
return nil
} }
func (dpm *DashboardProvisionerMock) PollChanges(ctx context.Context) { func (dpm *DashboardProvisionerMock) PollChanges(ctx context.Context) {
...@@ -41,7 +40,6 @@ func (dpm *DashboardProvisionerMock) GetProvisionerResolvedPath(name string) str ...@@ -41,7 +40,6 @@ func (dpm *DashboardProvisionerMock) GetProvisionerResolvedPath(name string) str
dpm.Calls.PollChanges = append(dpm.Calls.GetProvisionerResolvedPath, name) dpm.Calls.PollChanges = append(dpm.Calls.GetProvisionerResolvedPath, name)
if dpm.GetProvisionerResolvedPathFunc != nil { if dpm.GetProvisionerResolvedPathFunc != nil {
return dpm.GetProvisionerResolvedPathFunc(name) return dpm.GetProvisionerResolvedPathFunc(name)
} else {
return ""
} }
return ""
} }
...@@ -25,34 +25,30 @@ func (mock *ProvisioningServiceMock) ProvisionDatasources() error { ...@@ -25,34 +25,30 @@ func (mock *ProvisioningServiceMock) ProvisionDatasources() error {
mock.Calls.ProvisionDatasources = append(mock.Calls.ProvisionDatasources, nil) mock.Calls.ProvisionDatasources = append(mock.Calls.ProvisionDatasources, nil)
if mock.ProvisionDatasourcesFunc != nil { if mock.ProvisionDatasourcesFunc != nil {
return mock.ProvisionDatasourcesFunc() return mock.ProvisionDatasourcesFunc()
} else {
return nil
} }
return nil
} }
func (mock *ProvisioningServiceMock) ProvisionNotifications() error { func (mock *ProvisioningServiceMock) ProvisionNotifications() error {
mock.Calls.ProvisionNotifications = append(mock.Calls.ProvisionNotifications, nil) mock.Calls.ProvisionNotifications = append(mock.Calls.ProvisionNotifications, nil)
if mock.ProvisionNotificationsFunc != nil { if mock.ProvisionNotificationsFunc != nil {
return mock.ProvisionNotificationsFunc() return mock.ProvisionNotificationsFunc()
} else {
return nil
} }
return nil
} }
func (mock *ProvisioningServiceMock) ProvisionDashboards() error { func (mock *ProvisioningServiceMock) ProvisionDashboards() error {
mock.Calls.ProvisionDashboards = append(mock.Calls.ProvisionDashboards, nil) mock.Calls.ProvisionDashboards = append(mock.Calls.ProvisionDashboards, nil)
if mock.ProvisionDashboardsFunc != nil { if mock.ProvisionDashboardsFunc != nil {
return mock.ProvisionDashboardsFunc() return mock.ProvisionDashboardsFunc()
} else {
return nil
} }
return nil
} }
func (mock *ProvisioningServiceMock) GetDashboardProvisionerResolvedPath(name string) string { func (mock *ProvisioningServiceMock) GetDashboardProvisionerResolvedPath(name string) string {
mock.Calls.GetDashboardProvisionerResolvedPath = append(mock.Calls.GetDashboardProvisionerResolvedPath, name) mock.Calls.GetDashboardProvisionerResolvedPath = append(mock.Calls.GetDashboardProvisionerResolvedPath, name)
if mock.GetDashboardProvisionerResolvedPathFunc != nil { if mock.GetDashboardProvisionerResolvedPathFunc != nil {
return mock.GetDashboardProvisionerResolvedPathFunc(name) return mock.GetDashboardProvisionerResolvedPathFunc(name)
} else {
return ""
} }
return ""
} }
// A set of value types to use in provisioning. They add custom unmarshaling logic that puts the string values // Package values is a set of value types to use in provisioning. They add custom unmarshaling logic that puts the string values
// through os.ExpandEnv. // through os.ExpandEnv.
// Usage: // Usage:
// type Data struct { // type Data struct {
......
...@@ -14,8 +14,6 @@ function exit_if_fail { ...@@ -14,8 +14,6 @@ function exit_if_fail {
go get -u github.com/alecthomas/gometalinter go get -u github.com/alecthomas/gometalinter
go get -u github.com/jgautheron/goconst/cmd/goconst go get -u github.com/jgautheron/goconst/cmd/goconst
go get -u honnef.co/go/tools/cmd/staticcheck go get -u honnef.co/go/tools/cmd/staticcheck
go get -u github.com/mgechev/revive
go get -u github.com/securego/gosec/cmd/gosec/...
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
# use gometalinter when lints are not available in golangci or # use gometalinter when lints are not available in golangci or
...@@ -36,10 +34,5 @@ exit_if_fail golangci-lint run --deadline 10m --disable-all \ ...@@ -36,10 +34,5 @@ exit_if_fail golangci-lint run --deadline 10m --disable-all \
exit_if_fail go vet ./pkg/... exit_if_fail go vet ./pkg/...
exit_if_fail revive -formatter stylish -config ./scripts/revive.toml exit_if_fail make revive
exit_if_fail make gosec
# TODO recheck the rules and leave only necessary exclusions
exit_if_fail gosec -quiet \
-exclude=G104,G107,G201,G202,G204,G301,G304,G401,G402,G501 \
-conf=./scripts/gosec.json \
./pkg/...
module github.com/grafana/grafana/scripts/go
go 1.12
require (
github.com/mgechev/revive v0.0.0-20190505013521-22b849f28677 // indirect
github.com/securego/gosec v0.0.0-20190510081509-ee80733faf72 // indirect
)
github.com/BurntSushi/toml v0.3.0 h1:e1/Ivsx3Z0FVTV0NSOv/aVgbUWyQuzj7DDnFblkRvsY=
github.com/BurntSushi/toml v0.3.0/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/structtag v1.0.0 h1:pTHj65+u3RKWYPSGaU290FpI/dXxTaHdVwVwbcPKmEc=
github.com/fatih/structtag v1.0.0/go.mod h1:IKitwq45uXL/yqi5mYghiD3w9H6eTOvI9vnk8tXMphA=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mgechev/dots v0.0.0-20180605013149-8e09d8ea2757 h1:KTwJ7Lo3KDKMknRYN5JEFRGIM4IkG59QjFFM2mxsMEU=
github.com/mgechev/dots v0.0.0-20180605013149-8e09d8ea2757/go.mod h1:KQ7+USdGKfpPjXk4Ga+5XxQM4Lm4e3gAogrreFAYpOg=
github.com/mgechev/revive v0.0.0-20190505013521-22b849f28677 h1:iOfPBHjVwDHHeKUerCrX3JRUU9YbRewSTzirEYE0x78=
github.com/mgechev/revive v0.0.0-20190505013521-22b849f28677/go.mod h1:pVHj2KvxEhotJ6Lmr7zb3YgNMX1QKt8cyp6fdPHOrzU=
github.com/mozilla/tls-observatory v0.0.0-20190404164649-a3c1b6cfecfd/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk=
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d h1:AREM5mwr4u1ORQBMvzfzBgpsctsbQikCVpvC+tX285E=
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU=
github.com/olekukonko/tablewriter v0.0.0-20180912035003-be2c049b30cc h1:rQ1O4ZLYR2xXHXgBCCfIIGnuZ0lidMQw2S5n1oOv+Wg=
github.com/olekukonko/tablewriter v0.0.0-20180912035003-be2c049b30cc/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/securego/gosec v0.0.0-20190510081509-ee80733faf72 h1:403cuEGt3niQPAau/if+Fp34KjBzMKGejdBCu486W3s=
github.com/securego/gosec v0.0.0-20190510081509-ee80733faf72/go.mod h1:shk+oGa7JTGg9taMxXk2skTwpt9KQAbryuwFIHCm/fw=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190420063019-afa5a82059c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20180911133044-677d2ff680c1 h1:dzEuQYa6+a3gROnSlgly5ERUm4SZKJt+dh+4iSbO+bI=
golang.org/x/tools v0.0.0-20180911133044-677d2ff680c1/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b h1:NVD8gBK33xpdqCaZVVtd6OFJp+3dxkXuz7+U7KaVN6s=
golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment