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