Commit d505d83e by Torkel Ödegaard Committed by GitHub

Merge pull request #13679 from mjtrangoni/fix-megacheck-issues

Fix megacheck issues
parents 946ca547 91447dcb
...@@ -185,7 +185,7 @@ func (a *ldapAuther) GetGrafanaUserFor(ctx *m.ReqContext, ldapUser *LdapUserInfo ...@@ -185,7 +185,7 @@ func (a *ldapAuther) GetGrafanaUserFor(ctx *m.ReqContext, ldapUser *LdapUserInfo
if ldapUser.isMemberOf(group.GroupDN) { if ldapUser.isMemberOf(group.GroupDN) {
extUser.OrgRoles[group.OrgId] = group.OrgRole extUser.OrgRoles[group.OrgId] = group.OrgRole
if extUser.IsGrafanaAdmin == nil || *extUser.IsGrafanaAdmin == false { if extUser.IsGrafanaAdmin == nil || !*extUser.IsGrafanaAdmin {
extUser.IsGrafanaAdmin = group.IsGrafanaAdmin extUser.IsGrafanaAdmin = group.IsGrafanaAdmin
} }
} }
......
...@@ -43,12 +43,13 @@ func GetContextHandler() macaron.Handler { ...@@ -43,12 +43,13 @@ func GetContextHandler() macaron.Handler {
// then init session and look for userId in session // then init session and look for userId in session
// then look for api key in session (special case for render calls via api) // then look for api key in session (special case for render calls via api)
// then test if anonymous access is enabled // then test if anonymous access is enabled
if initContextWithRenderAuth(ctx) || switch {
initContextWithApiKey(ctx) || case initContextWithRenderAuth(ctx):
initContextWithBasicAuth(ctx, orgId) || case initContextWithApiKey(ctx):
initContextWithAuthProxy(ctx, orgId) || case initContextWithBasicAuth(ctx, orgId):
initContextWithUserSessionCookie(ctx, orgId) || case initContextWithAuthProxy(ctx, orgId):
initContextWithAnonymousUser(ctx) { case initContextWithUserSessionCookie(ctx, orgId):
case initContextWithAnonymousUser(ctx):
} }
ctx.Logger = log.New("context", "userId", ctx.UserId, "orgId", ctx.OrgId, "uname", ctx.Login) ctx.Logger = log.New("context", "userId", ctx.UserId, "orgId", ctx.OrgId, "uname", ctx.Login)
......
...@@ -121,7 +121,6 @@ func (pm *PluginManager) Run(ctx context.Context) error { ...@@ -121,7 +121,6 @@ func (pm *PluginManager) Run(ctx context.Context) error {
pm.checkForUpdates() pm.checkForUpdates()
case <-ctx.Done(): case <-ctx.Done():
run = false run = false
break
} }
} }
......
...@@ -34,12 +34,9 @@ func NewRuleReader() *DefaultRuleReader { ...@@ -34,12 +34,9 @@ func NewRuleReader() *DefaultRuleReader {
func (arr *DefaultRuleReader) initReader() { func (arr *DefaultRuleReader) initReader() {
heartbeat := time.NewTicker(time.Second * 10) heartbeat := time.NewTicker(time.Second * 10)
for { for range heartbeat.C {
select {
case <-heartbeat.C:
arr.heartbeat() arr.heartbeat()
} }
}
} }
func (arr *DefaultRuleReader) Fetch() []*Rule { func (arr *DefaultRuleReader) Fetch() []*Rule {
......
...@@ -164,14 +164,12 @@ func formatTimeRange(input string) string { ...@@ -164,14 +164,12 @@ func formatTimeRange(input string) string {
func fixIntervalFormat(target string) string { func fixIntervalFormat(target string) string {
rMinute := regexp.MustCompile(`'(\d+)m'`) rMinute := regexp.MustCompile(`'(\d+)m'`)
rMin := regexp.MustCompile("m")
target = rMinute.ReplaceAllStringFunc(target, func(m string) string { target = rMinute.ReplaceAllStringFunc(target, func(m string) string {
return rMin.ReplaceAllString(m, "min") return strings.Replace(m, "m", "min", -1)
}) })
rMonth := regexp.MustCompile(`'(\d+)M'`) rMonth := regexp.MustCompile(`'(\d+)M'`)
rMon := regexp.MustCompile("M")
target = rMonth.ReplaceAllStringFunc(target, func(M string) string { target = rMonth.ReplaceAllStringFunc(target, func(M string) string {
return rMon.ReplaceAllString(M, "mon") return strings.Replace(M, "M", "mon", -1)
}) })
return target return target
} }
...@@ -186,8 +186,7 @@ func reverse(s string) string { ...@@ -186,8 +186,7 @@ func reverse(s string) string {
} }
func interpolateFilterWildcards(value string) string { func interpolateFilterWildcards(value string) string {
re := regexp.MustCompile("[*]") matches := strings.Count(value, "*")
matches := len(re.FindAllStringIndex(value, -1))
if matches == 2 && strings.HasSuffix(value, "*") && strings.HasPrefix(value, "*") { if matches == 2 && strings.HasSuffix(value, "*") && strings.HasPrefix(value, "*") {
value = strings.Replace(value, "*", "", -1) value = strings.Replace(value, "*", "", -1)
value = fmt.Sprintf(`has_substring("%s")`, value) value = fmt.Sprintf(`has_substring("%s")`, value)
......
...@@ -22,13 +22,13 @@ var versionRe = regexp.MustCompile(`grafana-(.*)(\.|_)(arm64|armhfp|aarch64|armv ...@@ -22,13 +22,13 @@ var versionRe = regexp.MustCompile(`grafana-(.*)(\.|_)(arm64|armhfp|aarch64|armv
var debVersionRe = regexp.MustCompile(`grafana_(.*)_(arm64|armv7|armhf|amd64)\.deb`) var debVersionRe = regexp.MustCompile(`grafana_(.*)_(arm64|armv7|armhf|amd64)\.deb`)
var builds = []build{} var builds = []build{}
var architectureMapping = map[string]string{ var architectureMapping = map[string]string{
"armv7":"armv7", "armv7": "armv7",
"armhfp":"armv7", "armhfp": "armv7",
"armhf":"armv7", "armhf": "armv7",
"arm64":"arm64", "arm64": "arm64",
"aarch64":"arm64", "aarch64": "arm64",
"amd64":"amd64", "amd64": "amd64",
"x86_64":"amd64", "x86_64": "amd64",
} }
func main() { func main() {
...@@ -78,7 +78,7 @@ func mapPackage(path string, name string, shaBytes []byte) (build, error) { ...@@ -78,7 +78,7 @@ func mapPackage(path string, name string, shaBytes []byte) (build, error) {
if len(result) > 0 { if len(result) > 0 {
version = string(result[1]) version = string(result[1])
log.Printf("Version detected: %v", version) log.Printf("Version detected: %v", version)
} else if (len(debResult) > 0) { } else if len(debResult) > 0 {
version = string(debResult[1]) version = string(debResult[1])
} else { } else {
return build{}, fmt.Errorf("Unable to figure out version from '%v'", name) return build{}, fmt.Errorf("Unable to figure out version from '%v'", name)
...@@ -124,6 +124,9 @@ func mapPackage(path string, name string, shaBytes []byte) (build, error) { ...@@ -124,6 +124,9 @@ func mapPackage(path string, name string, shaBytes []byte) (build, error) {
} }
func packageWalker(path string, f os.FileInfo, err error) error { func packageWalker(path string, f os.FileInfo, err error) error {
if err != nil {
log.Printf("error: %v", err)
}
if f.Name() == "dist" || strings.Contains(f.Name(), "sha256") || strings.Contains(f.Name(), "latest") { if f.Name() == "dist" || strings.Contains(f.Name(), "sha256") || strings.Contains(f.Name(), "latest") {
return nil return nil
} }
...@@ -134,7 +137,6 @@ func packageWalker(path string, f os.FileInfo, err error) error { ...@@ -134,7 +137,6 @@ func packageWalker(path string, f os.FileInfo, err error) error {
} }
build, err := mapPackage(path, f.Name(), shaBytes) build, err := mapPackage(path, f.Name(), shaBytes)
if err != nil { if err != nil {
log.Printf("Could not map metadata from package: %v", err) log.Printf("Could not map metadata from package: %v", err)
return nil return nil
......
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