Chore: use any rather than interface{} (#74066)

This commit is contained in:
Ryan McKinley
2023-08-30 18:46:47 +03:00
committed by GitHub
parent 3e272d2bda
commit 025b2f3011
525 changed files with 2528 additions and 2528 deletions
+2 -2
View File
@@ -90,8 +90,8 @@ type Service struct {
features *featuremgmt.FeatureManager
}
func (s *Service) GetUsageStats(_ context.Context) map[string]interface{} {
return map[string]interface{}{
func (s *Service) GetUsageStats(_ context.Context) map[string]any {
return map[string]any{
"stats.oss.accesscontrol.enabled.count": 1,
}
}
+2 -2
View File
@@ -19,8 +19,8 @@ type FakeService struct {
ExpectedUsersPermissions map[int64][]accesscontrol.Permission
}
func (f FakeService) GetUsageStats(ctx context.Context) map[string]interface{} {
return map[string]interface{}{}
func (f FakeService) GetUsageStats(ctx context.Context) map[string]any {
return map[string]any{}
}
func (f FakeService) GetUserPermissions(ctx context.Context, user identity.Requester, options accesscontrol.Options) ([]accesscontrol.Permission, error) {
+1 -1
View File
@@ -82,7 +82,7 @@ func TestAPI_getUserPermissions(t *testing.T) {
{Action: datasources.ActionRead, Scope: datasources.ScopeProvider.GetResourceScope("aabbccdd")},
},
expectedOutput: util.DynMap{
datasources.ActionRead: []interface{}{
datasources.ActionRead: []any{
datasources.ScopeAll,
datasources.ScopeProvider.GetResourceScope("aabbccdd"),
}},
@@ -95,7 +95,7 @@ func (s *AccessControlStore) SearchUsersPermissions(ctx context.Context, orgID i
WHERE (org_id = ? OR org_id = ?)
`
params := []interface{}{accesscontrol.RoleGrafanaAdmin, accesscontrol.GlobalOrgID, orgID}
params := []any{accesscontrol.RoleGrafanaAdmin, accesscontrol.GlobalOrgID, orgID}
if options.ActionPrefix != "" {
q += ` AND action LIKE ?`
@@ -145,7 +145,7 @@ func (s *AccessControlStore) GetUsersBasicRoles(ctx context.Context, userFilter
LEFT JOIN org_user AS ou ON u.id = ou.user_id
WHERE (u.is_admin OR ou.org_id = ?)
`
params := []interface{}{orgID}
params := []any{orgID}
if len(userFilter) > 0 {
q += "AND u.id IN (?" + strings.Repeat(",?", len(userFilter)-1) + ")"
for _, u := range userFilter {
@@ -173,10 +173,10 @@ func (s *AccessControlStore) GetUsersBasicRoles(ctx context.Context, userFilter
func (s *AccessControlStore) DeleteUserPermissions(ctx context.Context, orgID, userID int64) error {
err := s.sql.WithDbSession(ctx, func(sess *db.Session) error {
roleDeleteQuery := "DELETE FROM user_role WHERE user_id = ?"
roleDeleteParams := []interface{}{roleDeleteQuery, userID}
roleDeleteParams := []any{roleDeleteQuery, userID}
if orgID != accesscontrol.GlobalOrgID {
roleDeleteQuery += " AND org_id = ?"
roleDeleteParams = []interface{}{roleDeleteQuery, userID, orgID}
roleDeleteParams = []any{roleDeleteQuery, userID, orgID}
}
// Delete user role assignments
@@ -193,10 +193,10 @@ func (s *AccessControlStore) DeleteUserPermissions(ctx context.Context, orgID, u
}
roleQuery := "SELECT id FROM role WHERE name = ?"
roleParams := []interface{}{accesscontrol.ManagedUserRoleName(userID)}
roleParams := []any{accesscontrol.ManagedUserRoleName(userID)}
if orgID != accesscontrol.GlobalOrgID {
roleQuery += " AND org_id = ?"
roleParams = []interface{}{accesscontrol.ManagedUserRoleName(userID), orgID}
roleParams = []any{accesscontrol.ManagedUserRoleName(userID), orgID}
}
var roleIDs []int64
@@ -209,7 +209,7 @@ func (s *AccessControlStore) DeleteUserPermissions(ctx context.Context, orgID, u
}
permissionDeleteQuery := "DELETE FROM permission WHERE role_id IN(? " + strings.Repeat(",?", len(roleIDs)-1) + ")"
permissionDeleteParams := make([]interface{}, 0, len(roleIDs)+1)
permissionDeleteParams := make([]any, 0, len(roleIDs)+1)
permissionDeleteParams = append(permissionDeleteParams, permissionDeleteQuery)
for _, id := range roleIDs {
permissionDeleteParams = append(permissionDeleteParams, id)
@@ -221,7 +221,7 @@ func (s *AccessControlStore) DeleteUserPermissions(ctx context.Context, orgID, u
}
managedRoleDeleteQuery := "DELETE FROM role WHERE id IN(? " + strings.Repeat(",?", len(roleIDs)-1) + ")"
managedRoleDeleteParams := []interface{}{managedRoleDeleteQuery}
managedRoleDeleteParams := []any{managedRoleDeleteQuery}
for _, id := range roleIDs {
managedRoleDeleteParams = append(managedRoleDeleteParams, id)
}
+10 -10
View File
@@ -27,7 +27,7 @@ var (
type SQLFilter struct {
Where string
Args []interface{}
Args []any
}
// Filter creates a where clause to restrict the view of a query based on a users permissions
@@ -43,7 +43,7 @@ func Filter(user identity.Requester, sqlID, prefix string, actions ...string) (S
}
wildcards := 0
result := make(map[interface{}]int)
result := make(map[any]int)
for _, a := range actions {
ids, hasWildcard := ParseScopes(prefix, user.GetPermissions()[a])
if hasWildcard {
@@ -63,7 +63,7 @@ func Filter(user identity.Requester, sqlID, prefix string, actions ...string) (S
return allowAllQuery, nil
}
var ids []interface{}
var ids []any
for id, count := range result {
// if an id exist for every action include it in the filter
if count+wildcards == len(actions) {
@@ -86,8 +86,8 @@ func Filter(user identity.Requester, sqlID, prefix string, actions ...string) (S
return SQLFilter{query.String(), ids}, nil
}
func ParseScopes(prefix string, scopes []string) (ids map[interface{}]struct{}, hasWildcard bool) {
ids = make(map[interface{}]struct{})
func ParseScopes(prefix string, scopes []string) (ids map[any]struct{}, hasWildcard bool) {
ids = make(map[any]struct{})
parser := parseStringAttribute
if strings.HasSuffix(prefix, ":id:") {
@@ -110,11 +110,11 @@ func ParseScopes(prefix string, scopes []string) (ids map[interface{}]struct{},
return ids, false
}
func parseIntAttribute(scope string) (interface{}, error) {
func parseIntAttribute(scope string) (any, error) {
return strconv.ParseInt(scope[strings.LastIndex(scope, ":")+1:], 10, 64)
}
func parseStringAttribute(scope string) (interface{}, error) {
func parseStringAttribute(scope string) (any, error) {
return scope[strings.LastIndex(scope, ":")+1:], nil
}
@@ -127,8 +127,8 @@ func SetAcceptListForTest(list map[string]struct{}) func() {
}
}
func UserRolesFilter(orgID, userID int64, teamIDs []int64, roles []string) (string, []interface{}) {
var params []interface{}
func UserRolesFilter(orgID, userID int64, teamIDs []int64, roles []string) (string, []any) {
var params []any
builder := strings.Builder{}
// This is an additional security. We should never have permissions granted to userID 0.
@@ -140,7 +140,7 @@ func UserRolesFilter(orgID, userID int64, teamIDs []int64, roles []string) (stri
WHERE ur.user_id = ?
AND (ur.org_id = ? OR ur.org_id = ?)
`)
params = []interface{}{userID, orgID, GlobalOrgID}
params = []any{userID, orgID, GlobalOrgID}
}
if len(teamIDs) > 0 {
+2 -2
View File
@@ -129,9 +129,9 @@ func unauthorized(c *contextmodel.ReqContext, err error) {
func tokenRevoked(c *contextmodel.ReqContext, err *usertoken.TokenRevokedError) {
if c.IsApiRequest() {
c.JSON(http.StatusUnauthorized, map[string]interface{}{
c.JSON(http.StatusUnauthorized, map[string]any{
"message": "Token revoked",
"error": map[string]interface{}{
"error": map[string]any{
"id": "ERR_TOKEN_REVOKED",
"maxConcurrentSessions": err.MaxConcurrentSessions,
},
@@ -39,11 +39,11 @@ func MigrateScopeSplit(db db.DB, log log.Logger) error {
// IDs to remove
delQuery := "DELETE FROM permission WHERE id IN ("
delArgs := make([]interface{}, 0, n)
delArgs := make([]any, 0, n)
// Query to insert the updated permissions
insertQuery := "INSERT INTO permission (id, role_id, action, scope, kind, attribute, identifier, created, updated) VALUES "
insertArgs := make([]interface{}, 0, 9*n)
insertArgs := make([]any, 0, 9*n)
// Prepare batch of updated permissions
for i := start; i < end; i++ {
@@ -355,7 +355,7 @@ func (s *store) getResourcePermissions(sess *db.Session, orgID int64, query GetR
scope := accesscontrol.Scope(query.Resource, query.ResourceAttribute, query.ResourceID)
args := []interface{}{
args := []any{
orgID,
orgID,
accesscontrol.Scope(query.Resource, "*"),
@@ -668,7 +668,7 @@ func deletePermissions(sess *db.Session, ids []int64) error {
}
rawSQL := "DELETE FROM permission WHERE id IN(?" + strings.Repeat(",?", len(ids)-1) + ")"
args := make([]interface{}, 0, len(ids)+1)
args := make([]any, 0, len(ids)+1)
args = append(args, rawSQL)
for _, id := range ids {
args = append(args, id)
+2 -2
View File
@@ -182,7 +182,7 @@ func (c *QueryCondition) executeQuery(context *alerting.EvalContext, timeRange l
queries = append(queries, &queryDto{
RefID: q.RefID,
Model: q.Model,
Datasource: simplejson.NewFromAny(map[string]interface{}{
Datasource: simplejson.NewFromAny(map[string]any{
"id": q.DataSource.ID,
"name": q.DataSource.Name,
}),
@@ -230,7 +230,7 @@ func (c *QueryCondition) executeQuery(context *alerting.EvalContext, timeRange l
result = append(result, v.Series...)
}
queryResultData := map[string]interface{}{}
queryResultData := map[string]any{}
if context.IsTestRun {
queryResultData["series"] = result
+1 -1
View File
@@ -35,7 +35,7 @@ func (j *Job) SetRunning(b bool) {
// ResultLogEntry represents log data for the alert evaluation.
type ResultLogEntry struct {
Message string
Data interface{}
Data any
}
// EvalMatch represents the series violating the threshold.
+1 -1
View File
@@ -130,7 +130,7 @@ func (a *Alert) GetTagsFromSettings() []*tag.Tag {
if a.Settings != nil {
if data, ok := a.Settings.CheckGet("alertRuleTags"); ok {
for tagNameString, tagValue := range data.MustMap() {
// MustMap() already guarantees the return of a `map[string]interface{}`.
// MustMap() already guarantees the return of a `map[string]any`.
// Therefore we only need to verify that tagValue is a String.
tagValueString := simplejson.NewFromAny(tagValue).MustString()
tags = append(tags, &tag.Tag{Key: tagNameString, Value: tagValueString})
+1 -1
View File
@@ -187,7 +187,7 @@ func notificationServiceScenario(t *testing.T, name string, evalCtx *EvalContext
{
ID: 1,
Type: "test",
Settings: simplejson.NewFromAny(map[string]interface{}{
Settings: simplejson.NewFromAny(map[string]any{
"uploadImage": uploadImage,
}),
},
@@ -158,7 +158,7 @@ func (am *AlertmanagerNotifier) Notify(evalContext *alerting.EvalContext) error
}
// Send one alert per matching series.
alerts := make([]interface{}, 0)
alerts := make([]any, 0)
for _, match := range evalContext.EvalMatches {
alert := am.createAlert(evalContext, match, ruleURL)
alerts = append(alerts, alert)
+3 -3
View File
@@ -122,14 +122,14 @@ func (dd *DingDingNotifier) genBody(evalContext *alerting.EvalContext, messageUR
message += fmt.Sprintf("\n%2d. %s: %s", i+1, match.Metric, match.Value)
}
var bodyMsg map[string]interface{}
var bodyMsg map[string]any
if dd.MsgType == "actionCard" {
// Embed the pic into the markdown directly because actionCard doesn't have a picUrl field
if dd.NeedsImage() && picURL != "" {
message = "![](" + picURL + ")\n\n" + message
}
bodyMsg = map[string]interface{}{
bodyMsg = map[string]any{
"msgtype": "actionCard",
"actionCard": map[string]string{
"text": message,
@@ -149,7 +149,7 @@ func (dd *DingDingNotifier) genBody(evalContext *alerting.EvalContext, messageUR
link["picUrl"] = picURL
}
bodyMsg = map[string]interface{}{
bodyMsg = map[string]any{
"msgtype": "link",
"link": link,
}
+7 -7
View File
@@ -110,10 +110,10 @@ func (dn *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
bodyJSON.Set("avatar_url", dn.AvatarURL)
}
fields := make([]map[string]interface{}, 0)
fields := make([]map[string]any, 0)
for _, evt := range evalContext.EvalMatches {
fields = append(fields, map[string]interface{}{
fields = append(fields, map[string]any{
// Discord uniquely does not send the alert if the metric field is empty,
// which it can be in some cases
"name": notEmpty(evt.Metric),
@@ -122,7 +122,7 @@ func (dn *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
})
}
footer := map[string]interface{}{
footer := map[string]any{
"text": "Grafana v" + setting.BuildVersion,
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
}
@@ -139,17 +139,17 @@ func (dn *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
embed.Set("fields", fields)
embed.Set("footer", footer)
var image map[string]interface{}
var image map[string]any
var embeddedImage = false
if dn.NeedsImage() {
if evalContext.ImagePublicURL != "" {
image = map[string]interface{}{
image = map[string]any{
"url": evalContext.ImagePublicURL,
}
embed.Set("image", image)
} else {
image = map[string]interface{}{
image = map[string]any{
"url": "attachment://graph.png",
}
embed.Set("image", image)
@@ -157,7 +157,7 @@ func (dn *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
}
}
bodyJSON.Set("embeds", []interface{}{embed})
bodyJSON.Set("embeds", []any{embed})
json, _ := bodyJSON.MarshalJSON()
+1 -1
View File
@@ -84,7 +84,7 @@ func (en *EmailNotifier) Notify(evalContext *alerting.EvalContext) error {
cmd := &notifications.SendEmailCommandSync{
SendEmailCommand: notifications.SendEmailCommand{
Subject: evalContext.GetNotificationTitle(),
Data: map[string]interface{}{
Data: map[string]any{
"Title": evalContext.GetNotificationTitle(),
"State": evalContext.Rule.State,
"Name": evalContext.Rule.Name,
+9 -9
View File
@@ -91,15 +91,15 @@ func (hc *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
return err
}
attributes := make([]map[string]interface{}, 0)
attributes := make([]map[string]any, 0)
for index, evt := range evalContext.EvalMatches {
metricName := evt.Metric
if len(metricName) > 50 {
metricName = metricName[:50]
}
attributes = append(attributes, map[string]interface{}{
attributes = append(attributes, map[string]any{
"label": metricName,
"value": map[string]interface{}{
"value": map[string]any{
"label": strconv.FormatFloat(evt.Value.Float64, 'f', -1, 64),
},
})
@@ -109,9 +109,9 @@ func (hc *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
}
if evalContext.Error != nil {
attributes = append(attributes, map[string]interface{}{
attributes = append(attributes, map[string]any{
"label": "Error message",
"value": map[string]interface{}{
"value": map[string]any{
"label": evalContext.Error.Error(),
},
})
@@ -140,20 +140,20 @@ func (hc *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
}
// Add a card with link to the dashboard
card := map[string]interface{}{
card := map[string]any{
"style": "application",
"url": ruleURL,
"id": "1",
"title": evalContext.GetNotificationTitle(),
"description": message,
"icon": map[string]interface{}{
"icon": map[string]any{
"url": "https://grafana.com/static/assets/img/fav32.png",
},
"date": evalContext.EndTime.Unix(),
"attributes": attributes,
}
if hc.NeedsImage() && evalContext.ImagePublicURL != "" {
card["thumbnail"] = map[string]interface{}{
card["thumbnail"] = map[string]any{
"url": evalContext.ImagePublicURL,
"url@2x": evalContext.ImagePublicURL,
"width": 1193,
@@ -161,7 +161,7 @@ func (hc *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
}
}
body := map[string]interface{}{
body := map[string]any{
"message": message,
"notify": "true",
"message_format": "html",
+2 -2
View File
@@ -79,7 +79,7 @@ func (kn *KafkaNotifier) Notify(evalContext *alerting.EvalContext) error {
kn.log.Info("Notifying Kafka", "alert_state", state)
recordJSON := simplejson.New()
records := make([]interface{}, 1)
records := make([]any, 1)
bodyJSON := simplejson.New()
// get alert state in the kafka output issue #11401
@@ -97,7 +97,7 @@ func (kn *KafkaNotifier) Notify(evalContext *alerting.EvalContext) error {
bodyJSON.Set("client_url", ruleURL)
if kn.NeedsImage() && evalContext.ImagePublicURL != "" {
contexts := make([]interface{}, 1)
contexts := make([]any, 1)
imageJSON := simplejson.New()
imageJSON.Set("type", "image")
imageJSON.Set("src", evalContext.ImagePublicURL)
@@ -111,20 +111,20 @@ func TestOpsGenieNotifier(t *testing.T) {
evalContext.IsTestRun = true
tags := make([]string, 0)
details := make(map[string]interface{})
details := make(map[string]any)
alertErr := opsgenieNotifier.createAlert(evalContext)
bodyJSON, err := simplejson.NewJson([]byte(notificationService.Webhook.Body))
if err == nil {
tags = bodyJSON.Get("tags").MustStringArray([]string{})
details = bodyJSON.Get("details").MustMap(map[string]interface{}{})
details = bodyJSON.Get("details").MustMap(map[string]any{})
}
require.Nil(t, notifierErr)
require.Nil(t, alertErr)
require.Equal(t, tags, []string{"keyOnly", "aKey:aValue"})
require.Equal(t, details, map[string]interface{}{"url": ""})
require.Equal(t, details, map[string]any{"url": ""})
})
t.Run("alert payload should include tag pairs only as a map in the details key when sendAsTags=details", func(t *testing.T) {
@@ -160,20 +160,20 @@ func TestOpsGenieNotifier(t *testing.T) {
evalContext.IsTestRun = true
tags := make([]string, 0)
details := make(map[string]interface{})
details := make(map[string]any)
alertErr := opsgenieNotifier.createAlert(evalContext)
bodyJSON, err := simplejson.NewJson([]byte(notificationService.Webhook.Body))
if err == nil {
tags = bodyJSON.Get("tags").MustStringArray([]string{})
details = bodyJSON.Get("details").MustMap(map[string]interface{}{})
details = bodyJSON.Get("details").MustMap(map[string]any{})
}
require.Nil(t, notifierErr)
require.Nil(t, alertErr)
require.Equal(t, tags, []string{})
require.Equal(t, details, map[string]interface{}{"keyOnly": "", "aKey": "aValue", "url": ""})
require.Equal(t, details, map[string]any{"keyOnly": "", "aKey": "aValue", "url": ""})
})
t.Run("alert payload should include tag pairs as both a map in the details key and an array in the tags key when sendAsTags=both", func(t *testing.T) {
@@ -209,20 +209,20 @@ func TestOpsGenieNotifier(t *testing.T) {
evalContext.IsTestRun = true
tags := make([]string, 0)
details := make(map[string]interface{})
details := make(map[string]any)
alertErr := opsgenieNotifier.createAlert(evalContext)
bodyJSON, err := simplejson.NewJson([]byte(notificationService.Webhook.Body))
if err == nil {
tags = bodyJSON.Get("tags").MustStringArray([]string{})
details = bodyJSON.Get("details").MustMap(map[string]interface{}{})
details = bodyJSON.Get("details").MustMap(map[string]any{})
}
require.Nil(t, notifierErr)
require.Nil(t, alertErr)
require.Equal(t, tags, []string{"keyOnly", "aKey:aValue"})
require.Equal(t, details, map[string]interface{}{"keyOnly": "", "aKey": "aValue", "url": ""})
require.Equal(t, details, map[string]any{"keyOnly": "", "aKey": "aValue", "url": ""})
})
})
}
@@ -151,20 +151,20 @@ func TestPagerdutyNotifier(t *testing.T) {
payload, err := simplejson.NewJson(payloadJSON)
require.Nil(t, err)
diff := cmp.Diff(map[string]interface{}{
diff := cmp.Diff(map[string]any{
"client": "Grafana",
"client_url": "",
"dedup_key": "alertId-0",
"event_action": "trigger",
"links": []interface{}{
map[string]interface{}{
"links": []any{
map[string]any{
"href": "",
},
},
"payload": map[string]interface{}{
"payload": map[string]any{
"component": "Grafana",
"source": "<<PRESENCE>>",
"custom_details": map[string]interface{}{
"custom_details": map[string]any{
"state": "alerting",
},
"severity": "critical",
@@ -207,20 +207,20 @@ func TestPagerdutyNotifier(t *testing.T) {
payload, err := simplejson.NewJson(payloadJSON)
require.Nil(t, err)
diff := cmp.Diff(map[string]interface{}{
diff := cmp.Diff(map[string]any{
"client": "Grafana",
"client_url": "",
"dedup_key": "alertId-0",
"event_action": "trigger",
"links": []interface{}{
map[string]interface{}{
"links": []any{
map[string]any{
"href": "",
},
},
"payload": map[string]interface{}{
"payload": map[string]any{
"component": "Grafana",
"source": "<<PRESENCE>>",
"custom_details": map[string]interface{}{
"custom_details": map[string]any{
"state": "alerting",
},
"severity": "critical",
@@ -274,22 +274,22 @@ func TestPagerdutyNotifier(t *testing.T) {
payload, err := simplejson.NewJson(payloadJSON)
require.NoError(t, err)
diff := cmp.Diff(map[string]interface{}{
diff := cmp.Diff(map[string]any{
"client": "Grafana",
"client_url": "",
"dedup_key": "alertId-0",
"event_action": "trigger",
"links": []interface{}{
map[string]interface{}{
"links": []any{
map[string]any{
"href": "",
},
},
"payload": map[string]interface{}{
"payload": map[string]any{
"component": "Grafana",
"source": "<<PRESENCE>>",
"custom_details": map[string]interface{}{
"custom_details": map[string]any{
"message": "someMessage",
"queries": map[string]interface{}{
"queries": map[string]any{
"someMetric": nil,
},
"state": "alerting",
@@ -345,20 +345,20 @@ func TestPagerdutyNotifier(t *testing.T) {
payload, err := simplejson.NewJson(payloadJSON)
require.NoError(t, err)
diff := cmp.Diff(map[string]interface{}{
diff := cmp.Diff(map[string]any{
"client": "Grafana",
"client_url": "",
"dedup_key": "key-" + strings.Repeat("x", 250),
"event_action": "trigger",
"links": []interface{}{
map[string]interface{}{
"links": []any{
map[string]any{
"href": "",
},
},
"payload": map[string]interface{}{
"payload": map[string]any{
"source": "<<PRESENCE>>",
"component": "aComponent",
"custom_details": map[string]interface{}{
"custom_details": map[string]any{
"group": "aGroup",
"class": "aClass",
"component": "aComponent",
@@ -373,8 +373,8 @@ func TestPagerdutyNotifier(t *testing.T) {
"class": "aClass",
"group": "aGroup",
},
"images": []interface{}{
map[string]interface{}{
"images": []any{
map[string]any{
"src": "http://somewhere.com/omg_dont_panic.png",
},
},
@@ -424,20 +424,20 @@ func TestPagerdutyNotifier(t *testing.T) {
payload, err := simplejson.NewJson(payloadJSON)
require.NoError(t, err)
diff := cmp.Diff(map[string]interface{}{
diff := cmp.Diff(map[string]any{
"client": "Grafana",
"client_url": "",
"dedup_key": "alertId-0",
"event_action": "trigger",
"links": []interface{}{
map[string]interface{}{
"links": []any{
map[string]any{
"href": "",
},
},
"payload": map[string]interface{}{
"payload": map[string]any{
"source": "<<PRESENCE>>",
"component": "aComponent",
"custom_details": map[string]interface{}{
"custom_details": map[string]any{
"group": "aGroup",
"class": "aClass",
"component": "aComponent",
@@ -451,8 +451,8 @@ func TestPagerdutyNotifier(t *testing.T) {
"class": "aClass",
"group": "aGroup",
},
"images": []interface{}{
map[string]interface{}{
"images": []any{
map[string]any{
"src": "http://somewhere.com/omg_dont_panic.png",
},
},
@@ -503,20 +503,20 @@ func TestPagerdutyNotifier(t *testing.T) {
payload, err := simplejson.NewJson(payloadJSON)
require.NoError(t, err)
diff := cmp.Diff(map[string]interface{}{
diff := cmp.Diff(map[string]any{
"client": "Grafana",
"client_url": "",
"dedup_key": "alertId-0",
"event_action": "trigger",
"links": []interface{}{
map[string]interface{}{
"links": []any{
map[string]any{
"href": "",
},
},
"payload": map[string]interface{}{
"payload": map[string]any{
"source": "<<PRESENCE>>",
"component": "aComponent",
"custom_details": map[string]interface{}{
"custom_details": map[string]any{
"group": "aGroup",
"class": "aClass",
"component": "aComponent",
@@ -530,8 +530,8 @@ func TestPagerdutyNotifier(t *testing.T) {
"class": "aClass",
"group": "aGroup",
},
"images": []interface{}{
map[string]interface{}{
"images": []any{
map[string]any{
"src": "http://somewhere.com/omg_dont_panic.png",
},
},
+10 -10
View File
@@ -61,10 +61,10 @@ func (tn *TeamsNotifier) Notify(evalContext *alerting.EvalContext) error {
return err
}
fields := make([]map[string]interface{}, 0)
fields := make([]map[string]any, 0)
fieldLimitCount := 4
for index, evt := range evalContext.EvalMatches {
fields = append(fields, map[string]interface{}{
fields = append(fields, map[string]any{
"name": evt.Metric,
"value": evt.Value,
})
@@ -74,7 +74,7 @@ func (tn *TeamsNotifier) Notify(evalContext *alerting.EvalContext) error {
}
if evalContext.Error != nil {
fields = append(fields, map[string]interface{}{
fields = append(fields, map[string]any{
"name": "Error message",
"value": evalContext.Error.Error(),
})
@@ -85,14 +85,14 @@ func (tn *TeamsNotifier) Notify(evalContext *alerting.EvalContext) error {
message = evalContext.Rule.Message
}
images := make([]map[string]interface{}, 0)
images := make([]map[string]any, 0)
if tn.NeedsImage() && evalContext.ImagePublicURL != "" {
images = append(images, map[string]interface{}{
images = append(images, map[string]any{
"image": evalContext.ImagePublicURL,
})
}
body := map[string]interface{}{
body := map[string]any{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
// summary MUST not be empty or the webhook request fails
@@ -100,7 +100,7 @@ func (tn *TeamsNotifier) Notify(evalContext *alerting.EvalContext) error {
"summary": evalContext.GetNotificationTitle(),
"title": evalContext.GetNotificationTitle(),
"themeColor": evalContext.GetStateModel().Color,
"sections": []map[string]interface{}{
"sections": []map[string]any{
{
"title": "Details",
"facts": fields,
@@ -108,12 +108,12 @@ func (tn *TeamsNotifier) Notify(evalContext *alerting.EvalContext) error {
"text": message,
},
},
"potentialAction": []map[string]interface{}{
"potentialAction": []map[string]any{
{
"@context": "http://schema.org",
"@type": "OpenUri",
"name": "View Rule",
"targets": []map[string]interface{}{
"targets": []map[string]any{
{
"os": "default", "uri": ruleURL,
},
@@ -123,7 +123,7 @@ func (tn *TeamsNotifier) Notify(evalContext *alerting.EvalContext) error {
"@context": "http://schema.org",
"@type": "OpenUri",
"name": "View Graph",
"targets": []map[string]interface{}{
"targets": []map[string]any{
{
"os": "default", "uri": evalContext.ImagePublicURL,
},
+1 -1
View File
@@ -113,7 +113,7 @@ func (vn *VictoropsNotifier) buildEventPayload(evalContext *alerting.EvalContext
messageType = alertStateRecovery
}
fields := make(map[string]interface{})
fields := make(map[string]any)
fieldLimitCount := 4
for index, evt := range evalContext.EvalMatches {
fields[evt.Metric] = evt.Value
@@ -100,12 +100,12 @@ func TestVictoropsNotifier(t *testing.T) {
payload, err := victoropsNotifier.buildEventPayload(evalContext)
require.Nil(t, err)
diff := cmp.Diff(map[string]interface{}{
diff := cmp.Diff(map[string]any{
"alert_url": "",
"entity_display_name": "[Alerting] someRule",
"entity_id": "someRule",
"message_type": "WARNING",
"metrics": map[string]interface{}{},
"metrics": map[string]any{},
"monitoring_tool": "Grafana v",
"state_message": "someMessage",
"state_start_time": int64(-1),
@@ -148,12 +148,12 @@ func TestVictoropsNotifier(t *testing.T) {
payload, err := victoropsNotifier.buildEventPayload(evalContext)
require.Nil(t, err)
diff := cmp.Diff(map[string]interface{}{
diff := cmp.Diff(map[string]any{
"alert_url": "",
"entity_display_name": "[OK] someRule",
"entity_id": "someRule",
"message_type": "RECOVERY",
"metrics": map[string]interface{}{},
"metrics": map[string]any{},
"monitoring_tool": "Grafana v",
"state_message": "someMessage",
"state_start_time": int64(-1),
+2 -2
View File
@@ -352,7 +352,7 @@ func (ss *sqlStore) PauseAlert(ctx context.Context, cmd *alertmodels.PauseAlertC
}
var buffer bytes.Buffer
params := make([]interface{}, 0)
params := make([]any, 0)
buffer.WriteString(`UPDATE alert SET state = ?, new_state_date = ?`)
if cmd.Paused {
@@ -368,7 +368,7 @@ func (ss *sqlStore) PauseAlert(ctx context.Context, cmd *alertmodels.PauseAlertC
params = append(params, v)
}
sqlOrArgs := append([]interface{}{buffer.String()}, params...)
sqlOrArgs := append([]any{buffer.String()}, params...)
res, err := sess.Exec(sqlOrArgs...)
if err != nil {
+4 -4
View File
@@ -131,7 +131,7 @@ func (ss *sqlStore) GetAlertNotificationsWithUidToSend(ctx context.Context, quer
res = make([]*models.AlertNotification, 0)
err = ss.db.WithDbSession(ctx, func(sess *db.Session) error {
var sql bytes.Buffer
params := make([]interface{}, 0)
params := make([]any, 0)
sql.WriteString(`SELECT
alert_notification.id,
@@ -171,7 +171,7 @@ func (ss *sqlStore) GetAlertNotificationsWithUidToSend(ctx context.Context, quer
func getAlertNotificationUidInternal(ctx context.Context, query *models.GetAlertNotificationUidQuery, sess *db.Session) (res string, err error) {
var sql bytes.Buffer
params := make([]interface{}, 0)
params := make([]any, 0)
sql.WriteString(`SELECT
alert_notification.uid
@@ -199,7 +199,7 @@ func getAlertNotificationUidInternal(ctx context.Context, query *models.GetAlert
func getAlertNotificationInternal(ctx context.Context, query *models.GetAlertNotificationsQuery, sess *db.Session) (res *models.AlertNotification, err error) {
var sql bytes.Buffer
params := make([]interface{}, 0)
params := make([]any, 0)
sql.WriteString(`SELECT
alert_notification.id,
@@ -246,7 +246,7 @@ func getAlertNotificationInternal(ctx context.Context, query *models.GetAlertNot
func getAlertNotificationWithUidInternal(ctx context.Context, query *models.GetAlertNotificationsWithUidQuery, sess *db.Session) (res *models.AlertNotification, err error) {
var sql bytes.Buffer
params := make([]interface{}, 0)
params := make([]any, 0)
sql.WriteString(`SELECT
alert_notification.id,
+2 -2
View File
@@ -435,13 +435,13 @@ func (ss *sqlStore) pauseAllAlerts(t *testing.T, pauseState bool) error {
}
func insertTestDashboard(t *testing.T, store db.DB, title string, orgId int64,
folderId int64, isFolder bool, tags ...interface{}) *dashboards.Dashboard {
folderId int64, isFolder bool, tags ...any) *dashboards.Dashboard {
t.Helper()
cmd := dashboards.SaveDashboardCommand{
OrgID: orgId,
FolderID: folderId,
IsFolder: isFolder,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": title,
"tags": tags,
@@ -73,7 +73,7 @@ func TestIntegrationAnnotations(t *testing.T) {
testDashboard1 := dashboards.SaveDashboardCommand{
UserID: 1,
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": "Dashboard 1",
}),
}
@@ -84,7 +84,7 @@ func TestIntegrationAnnotations(t *testing.T) {
testDashboard2 := dashboards.SaveDashboardCommand{
UserID: 1,
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": "Dashboard 2",
}),
}
@@ -99,7 +99,7 @@ func TestIntegrationAnnotations(t *testing.T) {
Type: "alert",
Epoch: 10,
Tags: []string{"outage", "error", "type:outage", "server:server-1"},
Data: simplejson.NewFromAny(map[string]interface{}{"data1": "I am a cool data", "data2": "I am another cool data"}),
Data: simplejson.NewFromAny(map[string]any{"data1": "I am a cool data", "data2": "I am another cool data"}),
}
err = repo.Add(context.Background(), annotation)
require.NoError(t, err)
@@ -338,7 +338,7 @@ func TestIntegrationAnnotations(t *testing.T) {
assert.Equal(t, "something new", items[0].Text)
data, err := items[0].Data.Map()
assert.NoError(t, err)
assert.Equal(t, data, map[string]interface{}{"data1": "I am a cool data", "data2": "I am another cool data"})
assert.Equal(t, data, map[string]any{"data1": "I am a cool data", "data2": "I am another cool data"})
})
t.Run("Can update annotation with new tags", func(t *testing.T) {
@@ -411,7 +411,7 @@ func TestIntegrationAnnotations(t *testing.T) {
require.NoError(t, err)
annotationId := items[0].ID
data := simplejson.NewFromAny(map[string]interface{}{"data": "I am a data", "data2": "I am also a data"})
data := simplejson.NewFromAny(map[string]any{"data": "I am a data", "data2": "I am also a data"})
err = repo.Update(context.Background(), &annotations.Item{
ID: annotationId,
OrgID: 1,
@@ -543,7 +543,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
UserID: 1,
OrgID: 1,
IsFolder: false,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": "Dashboard 1",
}),
}
@@ -554,7 +554,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
testDashboard2 := dashboards.SaveDashboardCommand{
UserID: 1,
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": "Dashboard 2",
}),
}
@@ -738,7 +738,7 @@ func TestIntegrationAnnotationListingWithInheritedRBAC(t *testing.T) {
UserID: usr.UserID,
OrgID: orgID,
IsFolder: false,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": fmt.Sprintf("Dashboard under %s", f.UID),
}),
FolderID: f.ID,
@@ -910,7 +910,7 @@ func benchmarkFindTags(b *testing.B, numAnnotations int) {
Text: "hello",
Type: "alert",
Epoch: 10,
Data: simplejson.NewFromAny(map[string]interface{}{"data1": "I am a cool data", "data2": "I am another cool data"}),
Data: simplejson.NewFromAny(map[string]any{"data1": "I am a cool data", "data2": "I am another cool data"}),
})
newTags = append(newTags, tag.Tag{
Id: int64(i),
@@ -948,7 +948,7 @@ func benchmarkFindTags(b *testing.B, numAnnotations int) {
Type: "alert",
Epoch: 10,
Tags: []string{"outage", "error", "type:outage", "server:server-1"},
Data: simplejson.NewFromAny(map[string]interface{}{"data1": "I am a cool data", "data2": "I am another cool data"}),
Data: simplejson.NewFromAny(map[string]any{"data1": "I am a cool data", "data2": "I am another cool data"}),
}
err = repo.Add(context.Background(), &annotationWithTheTag)
require.NoError(b, err)
+2 -2
View File
@@ -65,7 +65,7 @@ func ProvideAnonymousDeviceService(remoteCache remotecache.CacheStorage, usageSt
return a
}
func (a *AnonDeviceService) usageStatFn(ctx context.Context) (map[string]interface{}, error) {
func (a *AnonDeviceService) usageStatFn(ctx context.Context) (map[string]any, error) {
anonDeviceCount, err := a.remoteCache.Count(ctx, string(anonymous.AnonDevice))
if err != nil {
return nil, nil
@@ -86,7 +86,7 @@ func (a *AnonDeviceService) usageStatFn(ctx context.Context) (map[string]interfa
return nil, nil
}
return map[string]interface{}{
return map[string]any{
"stats.anonymous.session.count": anonDeviceCount, // keep session for legacy data
"stats.users.device.count": authedDeviceCount,
"stats.anonymous.device.ui.count": anonUIDeviceCount,
+1 -1
View File
@@ -22,7 +22,7 @@ type sqlxStore struct {
func (ss *sqlxStore) GetAPIKeys(ctx context.Context, query *apikey.GetApiKeysQuery) ([]*apikey.APIKey, error) {
var where []string
var args []interface{}
var args []any
if query.IncludeExpired {
where = append(where, "org_id=?")
+3 -3
View File
@@ -215,7 +215,7 @@ func (s *UserAuthTokenService) RotateToken(ctx context.Context, cmd auth.RotateC
return nil, auth.ErrInvalidSessionToken
}
res, err, _ := s.singleflight.Do(cmd.UnHashedToken, func() (interface{}, error) {
res, err, _ := s.singleflight.Do(cmd.UnHashedToken, func() (any, error) {
token, err := s.LookupToken(ctx, cmd.UnHashedToken)
if err != nil {
return nil, err
@@ -312,7 +312,7 @@ func (s *UserAuthTokenService) TryRotateToken(ctx context.Context, token *auth.U
newToken *auth.UserToken
}
rotResult, err, _ := s.singleflight.Do(fmt.Sprint(model.Id), func() (interface{}, error) {
rotResult, err, _ := s.singleflight.Do(fmt.Sprint(model.Id), func() (any, error) {
var needsRotation bool
rotatedAt := time.Unix(model.RotatedAt, 0)
if model.AuthTokenSeen {
@@ -462,7 +462,7 @@ func (s *UserAuthTokenService) BatchRevokeAllUserTokens(ctx context.Context, use
user_id_params := strings.Repeat(",?", len(userIds)-1)
sql := "DELETE from user_auth_token WHERE user_id IN (?" + user_id_params + ")"
params := []interface{}{sql}
params := []any{sql}
for _, v := range userIds {
params = append(params, v)
}
+1 -1
View File
@@ -53,7 +53,7 @@ type AuthService struct {
keySet keySet
log log.Logger
expect map[string]interface{}
expect map[string]any
expectRegistered jwt.Expected
}
+5 -5
View File
@@ -262,19 +262,19 @@ func TestClaimValidation(t *testing.T) {
scenario(t, "validates non-registered (custom) claims for equality", func(t *testing.T, sc scenarioContext) {
var err error
_, err = sc.authJWTSvc.Verify(sc.ctx, sign(t, key, map[string]interface{}{"my-str": "foo", "my-number": 123}, nil))
_, err = sc.authJWTSvc.Verify(sc.ctx, sign(t, key, map[string]any{"my-str": "foo", "my-number": 123}, nil))
require.NoError(t, err)
_, err = sc.authJWTSvc.Verify(sc.ctx, sign(t, key, map[string]interface{}{"my-str": "bar", "my-number": 123}, nil))
_, err = sc.authJWTSvc.Verify(sc.ctx, sign(t, key, map[string]any{"my-str": "bar", "my-number": 123}, nil))
require.Error(t, err)
_, err = sc.authJWTSvc.Verify(sc.ctx, sign(t, key, map[string]interface{}{"my-str": "foo", "my-number": 100}, nil))
_, err = sc.authJWTSvc.Verify(sc.ctx, sign(t, key, map[string]any{"my-str": "foo", "my-number": 100}, nil))
require.Error(t, err)
_, err = sc.authJWTSvc.Verify(sc.ctx, sign(t, key, map[string]interface{}{"my-str": "foo"}, nil))
_, err = sc.authJWTSvc.Verify(sc.ctx, sign(t, key, map[string]any{"my-str": "foo"}, nil))
require.Error(t, err)
_, err = sc.authJWTSvc.Verify(sc.ctx, sign(t, key, map[string]interface{}{"my-number": 123}, nil))
_, err = sc.authJWTSvc.Verify(sc.ctx, sign(t, key, map[string]any{"my-number": 123}, nil))
require.Error(t, err)
}, configurePKIXPublicKeyFile, func(t *testing.T, cfg *setting.Cfg) {
cfg.JWTAuthExpectClaims = `{"my-str": "foo", "my-number": 123}`
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"context"
)
type JWTClaims map[string]interface{}
type JWTClaims map[string]any
type JWTService interface {
Verify(ctx context.Context, strToken string) (JWTClaims, error)
+1 -1
View File
@@ -97,7 +97,7 @@ func (s *AuthService) initKeySet() error {
return ErrFailedToParsePemFile
}
var key interface{}
var key any
switch block.Type {
case "PUBLIC KEY":
if key, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil {
+2 -2
View File
@@ -10,7 +10,7 @@ import (
type noneSigner struct{}
func sign(t *testing.T, key interface{}, claims interface{}, opts *jose.SignerOptions) string {
func sign(t *testing.T, key any, claims any, opts *jose.SignerOptions) string {
t.Helper()
if opts == nil {
@@ -35,7 +35,7 @@ func (s noneSigner) SignPayload(payload []byte, alg jose.SignatureAlgorithm) ([]
return nil, nil
}
func signNone(t *testing.T, claims interface{}) string {
func signNone(t *testing.T, claims any) string {
t.Helper()
sig, err := jose.NewSigner(jose.SigningKey{Algorithm: "none", Key: noneSigner{}}, (&jose.SignerOptions{}).WithType("JWT"))
+2 -2
View File
@@ -32,7 +32,7 @@ func (s *AuthService) initClaimExpectations() error {
delete(s.expect, key)
case "aud":
switch value := value.(type) {
case []interface{}:
case []any:
for _, val := range value {
if v, ok := val.(string); ok {
s.expectRegistered.Audience = append(s.expectRegistered.Audience, v)
@@ -70,7 +70,7 @@ func (s *AuthService) validateClaims(claims JWTClaims) error {
}
case "aud":
switch value := value.(type) {
case []interface{}:
case []any:
for _, val := range value {
if v, ok := val.(string); ok {
registeredClaims.Audience = append(registeredClaims.Audience, v)
+2 -2
View File
@@ -133,7 +133,7 @@ type ProxyClient interface {
// Clients that implements this interface can specify a usage stat collection hook
type UsageStatClient interface {
Client
UsageStatFn(ctx context.Context) (map[string]interface{}, error)
UsageStatFn(ctx context.Context) (map[string]any, error)
}
type Request struct {
@@ -341,7 +341,7 @@ type RedirectValidator func(url string) error
// HandleLoginResponse is a utility function to perform common operations after a successful login and returns response.NormalResponse
func HandleLoginResponse(r *http.Request, w http.ResponseWriter, cfg *setting.Cfg, identity *Identity, validator RedirectValidator) *response.NormalResponse {
result := map[string]interface{}{"message": "Logged in"}
result := map[string]any{"message": "Logged in"}
result["redirectUrl"] = handleLogin(r, w, cfg, identity, validator)
return response.JSON(http.StatusOK, result)
}
+2 -2
View File
@@ -6,8 +6,8 @@ import (
"github.com/grafana/grafana/pkg/services/authn"
)
func (s *Service) getUsageStats(ctx context.Context) (map[string]interface{}, error) {
m := map[string]interface{}{}
func (s *Service) getUsageStats(ctx context.Context) (map[string]any, error) {
m := map[string]any{}
// Add stats about auth configuration
authTypes := map[string]bool{}
@@ -12,7 +12,7 @@ import (
func TestService_getUsageStats(t *testing.T) {
svc := setupTests(t, func(svc *Service) {
svc.RegisterClient(
&authntest.FakeClient{ExpectedErr: nil, ExpectedName: "test", ExpectedPriority: 1, ExpectedStats: map[string]interface{}{"stats.test.enabled.count": 1}})
&authntest.FakeClient{ExpectedErr: nil, ExpectedName: "test", ExpectedPriority: 1, ExpectedStats: map[string]any{"stats.test.enabled.count": 1}})
svc.RegisterClient(
&authntest.FakeClient{ExpectedErr: errCantAuthenticateReq, ExpectedName: "failing", ExpectedPriority: 1, ExpectedStats: nil})
})
@@ -28,7 +28,7 @@ func TestService_getUsageStats(t *testing.T) {
got, err := svc.getUsageStats(context.Background())
require.NoError(t, err)
want := map[string]interface{}{"stats.auth_enabled.anonymous.count": 0,
want := map[string]any{"stats.auth_enabled.anonymous.count": 0,
"stats.auth_enabled.auth_proxy.count": 1,
"stats.auth_enabled.basic_auth.count": 1,
"stats.auth_enabled.grafana_password.count": 1,
+2 -2
View File
@@ -80,7 +80,7 @@ type FakeClient struct {
ExpectedTest bool
ExpectedPriority uint
ExpectedIdentity *authn.Identity
ExpectedStats map[string]interface{}
ExpectedStats map[string]any
}
func (f *FakeClient) Name() string {
@@ -99,7 +99,7 @@ func (f *FakeClient) Priority() uint {
return f.ExpectedPriority
}
func (f *FakeClient) UsageStatFn(ctx context.Context) (map[string]interface{}, error) {
func (f *FakeClient) UsageStatFn(ctx context.Context) (map[string]any, error) {
return f.ExpectedStats, f.ExpectedErr
}
+2 -2
View File
@@ -83,8 +83,8 @@ func (a *Anonymous) Priority() uint {
return 100
}
func (a *Anonymous) UsageStatFn(ctx context.Context) (map[string]interface{}, error) {
m := map[string]interface{}{}
func (a *Anonymous) UsageStatFn(ctx context.Context) (map[string]any, error) {
m := map[string]any{}
// Add stats about anonymous auth
m["stats.anonymous.customized_role.count"] = 0
+2 -2
View File
@@ -534,9 +534,9 @@ type testEnv struct {
s *ExtendedJWT
}
func generateToken(payload ExtendedJWTClaims, signingKey interface{}, alg jose.SignatureAlgorithm) string {
func generateToken(payload ExtendedJWTClaims, signingKey any, alg jose.SignatureAlgorithm) string {
signer, _ := jose.NewSigner(jose.SigningKey{Algorithm: alg, Key: signingKey}, &jose.SignerOptions{
ExtraHeaders: map[jose.HeaderKey]interface{}{
ExtraHeaders: map[jose.HeaderKey]any{
jose.HeaderType: "at+jwt",
}})
+3 -3
View File
@@ -170,7 +170,7 @@ func (s *JWT) Priority() uint {
const roleGrafanaAdmin = "GrafanaAdmin"
func (s *JWT) extractRoleAndAdmin(claims map[string]interface{}) (org.RoleType, bool) {
func (s *JWT) extractRoleAndAdmin(claims map[string]any) (org.RoleType, bool) {
if s.cfg.JWTAuthRoleAttributePath == "" {
return "", false
}
@@ -186,7 +186,7 @@ func (s *JWT) extractRoleAndAdmin(claims map[string]interface{}) (org.RoleType,
return org.RoleType(role), false
}
func searchClaimsForStringAttr(attributePath string, claims map[string]interface{}) (string, error) {
func searchClaimsForStringAttr(attributePath string, claims map[string]any) (string, error) {
val, err := searchClaimsForAttr(attributePath, claims)
if err != nil {
return "", err
@@ -200,7 +200,7 @@ func searchClaimsForStringAttr(attributePath string, claims map[string]interface
return "", nil
}
func searchClaimsForAttr(attributePath string, claims map[string]interface{}) (interface{}, error) {
func searchClaimsForAttr(attributePath string, claims map[string]any) (any, error) {
if attributePath == "" {
return "", errors.New("no attribute path specified")
}
+1 -1
View File
@@ -114,7 +114,7 @@ func TestJWTClaimConfig(t *testing.T) {
// #nosec G101 -- This is a dummy/test token
token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.XbPfbIHMI6arZ3Y922BhjWgQzWXcXNrz0ogtVhfEd2o"
type Dictionary map[string]interface{}
type Dictionary map[string]any
type testCase struct {
desc string
+2 -2
View File
@@ -4,10 +4,10 @@ import "context"
type Key struct{}
func Set(ctx context.Context, data interface{}) context.Context {
func Set(ctx context.Context, data any) context.Context {
return context.WithValue(ctx, Key{}, data)
}
func Get(ctx context.Context) interface{} {
func Get(ctx context.Context) any {
return ctx.Value(Key{})
}
+7 -7
View File
@@ -74,7 +74,7 @@ type CorrelationConfig struct {
// Target data query
// required:true
// example: {"prop1":"value1","prop2":"value"}
Target map[string]interface{} `json:"target" binding:"Required"`
Target map[string]any `json:"target" binding:"Required"`
// Source data transformations
// required:false
// example: [{"type":"logfmt"}]
@@ -85,13 +85,13 @@ func (c CorrelationConfig) MarshalJSON() ([]byte, error) {
target := c.Target
transformations := c.Transformations
if target == nil {
target = map[string]interface{}{}
target = map[string]any{}
}
return json.Marshal(struct {
Type CorrelationConfigType `json:"type"`
Field string `json:"field"`
Target map[string]interface{} `json:"target"`
Transformations Transformations `json:"transformations,omitempty"`
Type CorrelationConfigType `json:"type"`
Field string `json:"field"`
Target map[string]any `json:"target"`
Transformations Transformations `json:"transformations,omitempty"`
}{
Type: ConfigTypeQuery,
Field: c.Field,
@@ -204,7 +204,7 @@ type CorrelationConfigUpdateDTO struct {
Type *CorrelationConfigType `json:"type"`
// Target data query
// example: {"prop1":"value1","prop2":"value"}
Target *map[string]interface{} `json:"target"`
Target *map[string]any `json:"target"`
// Source data transformations
// example: [{"type": "logfmt"},{"type":"regex","expression":"(Superman|Batman)", "variable":"name"}]
Transformations []Transformation `json:"transformations"`
+3 -3
View File
@@ -13,7 +13,7 @@ func TestCorrelationModels(t *testing.T) {
targetUid := "targetUid"
config := &CorrelationConfig{
Field: "field",
Target: map[string]interface{}{},
Target: map[string]any{},
Type: ConfigTypeQuery,
}
cmd := &CreateCorrelationCommand{
@@ -29,7 +29,7 @@ func TestCorrelationModels(t *testing.T) {
t.Run("Fails if target UID is not set and config type = query", func(t *testing.T) {
config := &CorrelationConfig{
Field: "field",
Target: map[string]interface{}{},
Target: map[string]any{},
Type: ConfigTypeQuery,
}
cmd := &CreateCorrelationCommand{
@@ -44,7 +44,7 @@ func TestCorrelationModels(t *testing.T) {
t.Run("Fails if config type is unknown", func(t *testing.T) {
config := &CorrelationConfig{
Field: "field",
Target: map[string]interface{}{},
Target: map[string]any{},
Type: "unknown config type",
}
cmd := &CreateCorrelationCommand{
@@ -69,7 +69,7 @@ func (s *ImportDashboardService) ImportDashboard(ctx context.Context, req *dashb
libraryElements := generatedDash.Get("__elements")
libElementsArr, err := libraryElements.Array()
if err == nil {
elementMap := map[string]interface{}{}
elementMap := map[string]any{}
for _, el := range libElementsArr {
libElement := simplejson.NewFromAny(el)
elementMap[libElement.Get("uid").MustString()] = el
@@ -47,7 +47,7 @@ func TestImportDashboardService(t *testing.T) {
importLibraryPanelsForDashboard := false
connectLibraryPanelsForDashboardCalled := false
libraryPanelService := &libraryPanelServiceMock{
importLibraryPanelsForDashboardFunc: func(ctx context.Context, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []interface{}, folderID int64) error {
importLibraryPanelsForDashboardFunc: func(ctx context.Context, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []any, folderID int64) error {
importLibraryPanelsForDashboard = true
return nil
},
@@ -212,7 +212,7 @@ func (s *dashboardServiceMock) ImportDashboard(ctx context.Context, dto *dashboa
type libraryPanelServiceMock struct {
librarypanels.Service
connectLibraryPanelsForDashboardFunc func(c context.Context, signedInUser *user.SignedInUser, dash *dashboards.Dashboard) error
importLibraryPanelsForDashboardFunc func(c context.Context, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []interface{}, folderID int64) error
importLibraryPanelsForDashboardFunc func(c context.Context, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []any, folderID int64) error
}
func (s *libraryPanelServiceMock) ConnectLibraryPanelsForDashboard(ctx context.Context, signedInUser *user.SignedInUser, dash *dashboards.Dashboard) error {
@@ -223,7 +223,7 @@ func (s *libraryPanelServiceMock) ConnectLibraryPanelsForDashboard(ctx context.C
return nil
}
func (s *libraryPanelServiceMock) ImportLibraryPanelsForDashboard(ctx context.Context, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []interface{}, folderID int64) error {
func (s *libraryPanelServiceMock) ImportLibraryPanelsForDashboard(ctx context.Context, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []any, folderID int64) error {
if s.importLibraryPanelsForDashboardFunc != nil {
return s.importLibraryPanelsForDashboardFunc(ctx, signedInUser, libraryPanels, panels, folderID)
}
@@ -72,7 +72,7 @@ func (e *DashTemplateEvaluator) Eval() (*simplejson.Json, error) {
return simplejson.NewFromAny(e.evalObject(e.template)), nil
}
func (e *DashTemplateEvaluator) evalValue(source *simplejson.Json) interface{} {
func (e *DashTemplateEvaluator) evalValue(source *simplejson.Json) any {
sourceValue := source.Interface()
switch v := sourceValue.(type) {
@@ -89,10 +89,10 @@ func (e *DashTemplateEvaluator) evalValue(source *simplejson.Json) interface{} {
return v
case json.Number:
return v
case map[string]interface{}:
case map[string]any:
return e.evalObject(source)
case []interface{}:
array := make([]interface{}, 0)
case []any:
array := make([]any, 0)
for _, item := range v {
array = append(array, e.evalValue(simplejson.NewFromAny(item)))
}
@@ -102,8 +102,8 @@ func (e *DashTemplateEvaluator) evalValue(source *simplejson.Json) interface{} {
return nil
}
func (e *DashTemplateEvaluator) evalObject(source *simplejson.Json) interface{} {
result := make(map[string]interface{})
func (e *DashTemplateEvaluator) evalObject(source *simplejson.Json) any {
result := make(map[string]any)
for key, value := range source.MustMap() {
if key == "__inputs" {
+2 -2
View File
@@ -233,7 +233,7 @@ func (d *dashboardStore) DeleteOrphanedProvisionedDashboards(ctx context.Context
return d.store.WithDbSession(ctx, func(sess *db.Session) error {
var result []*dashboards.DashboardProvisioning
convertedReaderNames := make([]interface{}, len(cmd.ReaderNames))
convertedReaderNames := make([]any, len(cmd.ReaderNames))
for index, readerName := range cmd.ReaderNames {
convertedReaderNames[index] = readerName
}
@@ -965,7 +965,7 @@ func (d *dashboardStore) FindDashboards(ctx context.Context, query *dashboards.F
return nil, err
}
filters := []interface{}{
filters := []any{
permissions.NewAccessControlDashboardPermissionFilter(query.SignedInUser, query.Permission, query.Type, d.features, recursiveQueriesAreSupported),
}
@@ -323,7 +323,7 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
UserID: admin.UserID,
OrgID: admin.OrgID,
IsFolder: false,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": dashInRootTitle,
}),
}
@@ -334,7 +334,7 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
UserID: admin.UserID,
OrgID: admin.OrgID,
IsFolder: false,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": dashInParentTitle,
}),
FolderID: nestedFolders[0].ID,
@@ -347,7 +347,7 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
UserID: admin.UserID,
OrgID: admin.OrgID,
IsFolder: false,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": dashInSubfolderTitle,
}),
FolderID: nestedFolders[1].ID,
@@ -27,7 +27,7 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
OrgID: 1,
FolderID: 0,
IsFolder: true,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": "test dashboard",
}),
@@ -40,7 +40,7 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
OrgID: 1,
IsFolder: false,
FolderID: dash.ID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": "test dashboard",
}),
@@ -66,7 +66,7 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
OrgID: 1,
IsFolder: false,
FolderID: dash.ID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": "another_dashboard",
}),
+3 -3
View File
@@ -64,9 +64,9 @@ func (d *Dashboard) SetVersion(version int) {
d.Data.Set("version", version)
}
func (d *Dashboard) ToResource() kinds.GrafanaResource[simplejson.Json, interface{}] {
func (d *Dashboard) ToResource() kinds.GrafanaResource[simplejson.Json, any] {
parent := dashboard.NewK8sResource(d.UID, nil)
res := kinds.GrafanaResource[simplejson.Json, interface{}]{
res := kinds.GrafanaResource[simplejson.Json, any]{
Kind: parent.Kind,
APIVersion: parent.APIVersion,
Metadata: kinds.GrafanaResourceMetadata{
@@ -488,5 +488,5 @@ type FindPersistedDashboardsQuery struct {
Permission PermissionType
Sort model.SortOption
Filters []interface{}
Filters []any
}
@@ -42,7 +42,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": float64(123412321),
"title": "Expect error",
}),
@@ -61,7 +61,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
true, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: otherOrgId,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": sc.savedDashInFolder.ID,
"title": "Expect error",
}),
@@ -77,7 +77,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
const otherOrgId int64 = 2
cmd := dashboards.SaveDashboardCommand{
OrgID: otherOrgId,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"uid": sc.savedDashInFolder.UID,
"title": "Dash with existing uid in other org",
}),
@@ -103,7 +103,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
sqlStore := db.InitTestDB(t)
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": "Dash",
}),
UserID: 10000,
@@ -125,7 +125,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": "Dash",
}),
FolderID: sc.otherSavedFolder.ID,
@@ -148,7 +148,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": sc.savedDashInFolder.Title,
}),
FolderID: sc.savedFolder.ID,
@@ -171,7 +171,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"uid": sc.savedDashInFolder.UID,
"title": "New dash",
}),
@@ -195,7 +195,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": sc.savedDashInGeneralFolder.ID,
"title": "Dash",
}),
@@ -219,7 +219,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": sc.savedDashInFolder.ID,
"title": "Dash",
}),
@@ -243,7 +243,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": sc.savedDashInGeneralFolder.ID,
"title": "Dash",
}),
@@ -267,7 +267,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": sc.savedDashInFolder.ID,
"title": "Dash",
}),
@@ -291,7 +291,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"uid": sc.savedDashInGeneralFolder.UID,
"title": "Dash",
}),
@@ -315,7 +315,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"uid": sc.savedDashInFolder.UID,
"title": "Dash",
}),
@@ -346,7 +346,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": sc.savedDashInFolder.Title,
}),
@@ -369,7 +369,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": sc.savedDashInGeneralFolder.Title,
}),
@@ -393,7 +393,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": sc.savedDashInFolder.Title,
}),
@@ -418,7 +418,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": "Dash without id and uid",
}),
Overwrite: shouldOverwrite,
@@ -440,7 +440,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": 0,
"title": "Dash with zero id",
}),
@@ -461,7 +461,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": "Expect error",
}),
FolderID: 123412321,
@@ -476,7 +476,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": sc.savedDashInGeneralFolder.ID,
"title": "test dash 23",
}),
@@ -492,7 +492,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": sc.savedDashInGeneralFolder.ID,
"title": "Updated title",
"version": sc.savedDashInGeneralFolder.Version,
@@ -516,7 +516,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"uid": sc.savedDashInFolder.UID,
"title": "test dash 23",
}),
@@ -532,7 +532,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"uid": sc.savedDashInFolder.UID,
"title": "Updated title",
"version": sc.savedDashInFolder.Version,
@@ -555,7 +555,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": sc.savedDashInFolder.Title,
}),
@@ -571,7 +571,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
canSave, func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": sc.savedDashInGeneralFolder.Title,
}),
@@ -587,7 +587,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": sc.savedFolder.Title,
}),
@@ -607,7 +607,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": sc.savedDashInGeneralFolder.ID,
"title": "Updated title",
}),
@@ -629,7 +629,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"uid": sc.savedDashInFolder.UID,
"title": "Updated title",
}),
@@ -651,7 +651,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": sc.savedDashInFolder.ID,
"uid": "new-uid",
"title": sc.savedDashInFolder.Title,
@@ -675,7 +675,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": sc.savedDashInFolder.ID,
"uid": sc.savedDashInGeneralFolder.UID,
"title": sc.savedDashInFolder.Title,
@@ -691,7 +691,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": sc.savedDashInFolder.Title,
}),
@@ -715,7 +715,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: testOrgID,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": sc.savedDashInGeneralFolder.Title,
}),
@@ -739,7 +739,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": sc.savedFolder.ID,
"title": "new title",
}),
@@ -755,7 +755,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": sc.savedDashInFolder.ID,
"title": "new folder title",
}),
@@ -771,7 +771,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"uid": sc.savedFolder.UID,
"title": "new title",
}),
@@ -787,7 +787,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"uid": sc.savedDashInFolder.UID,
"title": "new folder title",
}),
@@ -803,7 +803,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": sc.savedFolder.Title,
}),
IsFolder: false,
@@ -818,7 +818,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
func(t *testing.T, sc *permissionScenarioContext) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": sc.savedDashInGeneralFolder.Title,
}),
IsFolder: true,
@@ -973,7 +973,7 @@ func saveTestDashboard(t *testing.T, title string, orgID, folderID int64, sqlSto
OrgID: orgID,
FolderID: folderID,
IsFolder: false,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": title,
}),
@@ -1017,7 +1017,7 @@ func saveTestFolder(t *testing.T, title string, orgID int64, sqlStore db.DB) *da
OrgID: orgID,
FolderID: 0,
IsFolder: true,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": title,
}),
@@ -31,7 +31,7 @@ func TestIntegrationDashboardSnapshotDBAccess(t *testing.T) {
setting.SecretKey = origSecret
})
secretsService := fakes.NewFakeSecretsService()
dashboard := simplejson.NewFromAny(map[string]interface{}{"hello": "mupp"})
dashboard := simplejson.NewFromAny(map[string]any{"hello": "mupp"})
t.Run("Given saved snapshot", func(t *testing.T) {
rawDashboard, err := dashboard.Encode()
@@ -115,7 +115,7 @@ func TestIntegrationDashboardSnapshotDBAccess(t *testing.T) {
cmd := dashboardsnapshots.CreateDashboardSnapshotCommand{
Key: "strangesnapshotwithuserid0",
DeleteKey: "adeletekey",
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"hello": "mupp",
}),
UserID: 0,
@@ -195,7 +195,7 @@ func createTestSnapshot(t *testing.T, dashStore *DashboardSnapshotStore, key str
cmd := dashboardsnapshots.CreateDashboardSnapshotCommand{
Key: key,
DeleteKey: "delete" + key,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"hello": "mupp",
}),
UserID: 1000,
@@ -49,7 +49,7 @@ func TestDeleteExpiredVersions(t *testing.T) {
t.Run("Clean up old dashboard versions successfully", func(t *testing.T) {
dashboardVersionStore.ExptectedDeletedVersions = 4
dashboardVersionStore.ExpectedVersions = []interface{}{1, 2, 3, 4}
dashboardVersionStore.ExpectedVersions = []any{1, 2, 3, 4}
err := dashboardVersionService.DeleteExpired(context.Background(), &dashver.DeleteExpiredVersionsCommand{DeletedRows: 4})
require.Nil(t, err)
})
@@ -147,7 +147,7 @@ func TestListDashboardVersions(t *testing.T) {
type FakeDashboardVersionStore struct {
ExpectedDashboardVersion *dashver.DashboardVersion
ExptectedDeletedVersions int64
ExpectedVersions []interface{}
ExpectedVersions []any
ExpectedListVersions []*dashver.DashboardVersion
ExpectedError error
}
@@ -160,11 +160,11 @@ func (f *FakeDashboardVersionStore) Get(ctx context.Context, query *dashver.GetD
return f.ExpectedDashboardVersion, f.ExpectedError
}
func (f *FakeDashboardVersionStore) GetBatch(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand, perBatch int, versionsToKeep int) ([]interface{}, error) {
func (f *FakeDashboardVersionStore) GetBatch(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand, perBatch int, versionsToKeep int) ([]any, error) {
return f.ExpectedVersions, f.ExpectedError
}
func (f *FakeDashboardVersionStore) DeleteBatch(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand, versionIdsToDelete []interface{}) (int64, error) {
func (f *FakeDashboardVersionStore) DeleteBatch(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand, versionIdsToDelete []any) (int64, error) {
return f.ExptectedDeletedVersions, f.ExpectedError
}
@@ -28,8 +28,8 @@ func (ss *sqlxStore) Get(ctx context.Context, query *dashver.GetDashboardVersion
return &version, err
}
func (ss *sqlxStore) GetBatch(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand, perBatch int, versionsToKeep int) ([]interface{}, error) {
var versionIds []interface{}
func (ss *sqlxStore) GetBatch(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand, perBatch int, versionsToKeep int) ([]any, error) {
var versionIds []any
versionIdsToDeleteQuery := `SELECT id
FROM dashboard_version, (
SELECT dashboard_id, count(version) as count, min(version) as min
@@ -45,7 +45,7 @@ func (ss *sqlxStore) GetBatch(ctx context.Context, cmd *dashver.DeleteExpiredVer
// This service is used by cleanup which need to belong to the same transaction
// Here we need to make sure that the transaction is shared between services
func (ss *sqlxStore) DeleteBatch(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand, versionIdsToDelete []interface{}) (int64, error) {
func (ss *sqlxStore) DeleteBatch(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand, versionIdsToDelete []any) (int64, error) {
var deleted int64
err := ss.sess.WithTransaction(ctx, func(tx *session.SessionTx) error {
deleteExpiredSQL := `DELETE FROM dashboard_version WHERE id IN (?` + strings.Repeat(",?", len(versionIdsToDelete)-1) + `)`
@@ -8,7 +8,7 @@ import (
type store interface {
Get(context.Context, *dashver.GetDashboardVersionQuery) (*dashver.DashboardVersion, error)
GetBatch(context.Context, *dashver.DeleteExpiredVersionsCommand, int, int) ([]interface{}, error)
DeleteBatch(context.Context, *dashver.DeleteExpiredVersionsCommand, []interface{}) (int64, error)
GetBatch(context.Context, *dashver.DeleteExpiredVersionsCommand, int, int) ([]any, error)
DeleteBatch(context.Context, *dashver.DeleteExpiredVersionsCommand, []any) (int64, error)
List(context.Context, *dashver.ListDashboardVersionsQuery) ([]*dashver.DashboardVersion, error)
}
@@ -68,7 +68,7 @@ func testIntegrationGetDashboardVersion(t *testing.T, fn getStore) {
for i := 0; i < versionsToWrite-1; i++ {
insertTestDashboard(t, ss, "test dash 53", 1, int64(i), false, "diff-all")
}
versionIDsToDelete := []interface{}{1, 2, 3, 4}
versionIDsToDelete := []any{1, 2, 3, 4}
res, err := dashVerStore.DeleteBatch(
context.Background(),
&dashver.DeleteExpiredVersionsCommand{DeletedRows: 4},
@@ -101,7 +101,7 @@ func testIntegrationGetDashboardVersion(t *testing.T, fn getStore) {
})
t.Run("Get all versions for an updated dashboard", func(t *testing.T) {
updateTestDashboard(t, ss, savedDash, map[string]interface{}{
updateTestDashboard(t, ss, savedDash, map[string]any{
"tags": "different-tag",
})
query := dashver.ListDashboardVersionsQuery{DashboardID: savedDash.ID, OrgID: 1, Limit: 1000}
@@ -134,13 +134,13 @@ var (
)
func insertTestDashboard(t *testing.T, sqlStore db.DB, title string, orgId int64,
folderId int64, isFolder bool, tags ...interface{}) *dashboards.Dashboard {
folderId int64, isFolder bool, tags ...any) *dashboards.Dashboard {
t.Helper()
cmd := dashboards.SaveDashboardCommand{
OrgID: orgId,
FolderID: folderId,
IsFolder: isFolder,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": title,
"tags": tags,
@@ -189,7 +189,7 @@ func insertTestDashboard(t *testing.T, sqlStore db.DB, title string, orgId int64
return dash
}
func updateTestDashboard(t *testing.T, sqlStore db.DB, dashboard *dashboards.Dashboard, data map[string]interface{}) {
func updateTestDashboard(t *testing.T, sqlStore db.DB, dashboard *dashboards.Dashboard, data map[string]any) {
t.Helper()
data["id"] = dashboard.ID
@@ -36,8 +36,8 @@ func (ss *sqlStore) Get(ctx context.Context, query *dashver.GetDashboardVersionQ
return &version, nil
}
func (ss *sqlStore) GetBatch(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand, perBatch int, versionsToKeep int) ([]interface{}, error) {
var versionIds []interface{}
func (ss *sqlStore) GetBatch(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand, perBatch int, versionsToKeep int) ([]any, error) {
var versionIds []any
err := ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
versionIdsToDeleteQuery := `SELECT id
FROM dashboard_version, (
@@ -55,11 +55,11 @@ func (ss *sqlStore) GetBatch(ctx context.Context, cmd *dashver.DeleteExpiredVers
return versionIds, err
}
func (ss *sqlStore) DeleteBatch(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand, versionIdsToDelete []interface{}) (int64, error) {
func (ss *sqlStore) DeleteBatch(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand, versionIdsToDelete []any) (int64, error) {
var deleted int64
err := ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
deleteExpiredSQL := `DELETE FROM dashboard_version WHERE id IN (?` + strings.Repeat(",?", len(versionIdsToDelete)-1) + `)`
sqlOrArgs := append([]interface{}{deleteExpiredSQL}, versionIdsToDelete...)
sqlOrArgs := append([]any{deleteExpiredSQL}, versionIdsToDelete...)
expiredResponse, err := sess.Exec(sqlOrArgs...)
if err != nil {
return err
+4 -4
View File
@@ -13,26 +13,26 @@ import (
func TestAllowedCookies(t *testing.T) {
testCases := []struct {
desc string
given map[string]interface{}
given map[string]any
want []string
}{
{
desc: "Usual json data with keepCookies",
given: map[string]interface{}{
given: map[string]any{
"keepCookies": []string{"cookie2"},
},
want: []string{"cookie2"},
},
{
desc: "Usual json data without kepCookies",
given: map[string]interface{}{
given: map[string]any{
"something": "somethingelse",
},
want: []string(nil),
},
{
desc: "Usual json data that has multiple values in keepCookies",
given: map[string]interface{}{
given: map[string]any{
"keepCookies": []string{"cookie1", "cookie2", "special[]"},
},
want: []string{"cookie1", "cookie2", "special[]"},
@@ -450,7 +450,7 @@ func (s *Service) httpClientOptions(ctx context.Context, ds *datasources.DataSou
if ds.JsonData != nil {
opts.CustomOptions = ds.JsonData.MustMap()
// allow the plugin sdk to get the json data in JSONDataFromHTTPClientOptions
deepJsonDataCopy := make(map[string]interface{}, len(opts.CustomOptions))
deepJsonDataCopy := make(map[string]any, len(opts.CustomOptions))
for k, v := range opts.CustomOptions {
deepJsonDataCopy[k] = v
}
@@ -719,7 +719,7 @@ func TestService_GetHttpTransport(t *testing.T) {
t.Run("Should set custom headers if configured in JsonData", func(t *testing.T) {
provider := httpclient.NewProvider()
sjson := simplejson.NewFromAny(map[string]interface{}{
sjson := simplejson.NewFromAny(map[string]any{
"httpHeaderName1": "Authorization",
})
@@ -788,7 +788,7 @@ func TestService_GetHttpTransport(t *testing.T) {
t.Run("Should use request timeout if configured in JsonData", func(t *testing.T) {
provider := httpclient.NewProvider()
sjson := simplejson.NewFromAny(map[string]interface{}{
sjson := simplejson.NewFromAny(map[string]any{
"timeout": 19,
})
@@ -939,10 +939,10 @@ func TestService_getTimeout(t *testing.T) {
expectedTimeout time.Duration
}{
{jsonData: simplejson.New(), expectedTimeout: time.Minute},
{jsonData: simplejson.NewFromAny(map[string]interface{}{"timeout": nil}), expectedTimeout: time.Minute},
{jsonData: simplejson.NewFromAny(map[string]interface{}{"timeout": 0}), expectedTimeout: time.Minute},
{jsonData: simplejson.NewFromAny(map[string]interface{}{"timeout": 1}), expectedTimeout: time.Second},
{jsonData: simplejson.NewFromAny(map[string]interface{}{"timeout": "2"}), expectedTimeout: 2 * time.Second},
{jsonData: simplejson.NewFromAny(map[string]any{"timeout": nil}), expectedTimeout: time.Minute},
{jsonData: simplejson.NewFromAny(map[string]any{"timeout": 0}), expectedTimeout: time.Minute},
{jsonData: simplejson.NewFromAny(map[string]any{"timeout": 1}), expectedTimeout: time.Second},
{jsonData: simplejson.NewFromAny(map[string]any{"timeout": "2"}), expectedTimeout: 2 * time.Second},
}
sqlStore := db.InitTestDB(t)
@@ -1043,7 +1043,7 @@ func TestDataSource_CustomHeaders(t *testing.T) {
}{
{
name: "valid custom headers",
jsonData: simplejson.NewFromAny(map[string]interface{}{
jsonData: simplejson.NewFromAny(map[string]any{
"httpHeaderName1": "X-Test-Header1",
}),
secureJsonData: map[string][]byte{
@@ -1055,7 +1055,7 @@ func TestDataSource_CustomHeaders(t *testing.T) {
},
{
name: "missing header value",
jsonData: simplejson.NewFromAny(map[string]interface{}{
jsonData: simplejson.NewFromAny(map[string]any{
"httpHeaderName1": "X-Test-Header1",
}),
secureJsonData: map[string][]byte{},
@@ -1063,7 +1063,7 @@ func TestDataSource_CustomHeaders(t *testing.T) {
},
{
name: "non customer header value",
jsonData: simplejson.NewFromAny(map[string]interface{}{
jsonData: simplejson.NewFromAny(map[string]any{
"someotherheader": "X-Test-Header1",
}),
secureJsonData: map[string][]byte{},
+2 -2
View File
@@ -82,11 +82,11 @@ func (s *Service) checkEncryptionAlgorithm(algorithm string) error {
}
func (s *Service) registerUsageMetrics() {
s.usageMetrics.RegisterMetricsFunc(func(context.Context) (map[string]interface{}, error) {
s.usageMetrics.RegisterMetricsFunc(func(context.Context) (map[string]any, error) {
algorithm := s.cfg.SectionWithEnvOverrides(securitySection).Key(encryptionAlgorithmKey).
MustString(defaultEncryptionAlgorithm)
return map[string]interface{}{
return map[string]any{
fmt.Sprintf("stats.encryption.%s.count", algorithm): 1,
}, nil
})
+3 -3
View File
@@ -19,7 +19,7 @@ type FeatureManager struct {
flags map[string]*FeatureFlag
enabled map[string]bool // only the "on" values
config string // path to config file
vars map[string]interface{}
vars map[string]any
log log.Logger
}
@@ -161,8 +161,8 @@ func (fm *FeatureManager) LookupFlag(name string) (FeatureFlag, bool) {
// WithFeatures is used to define feature toggles for testing.
// The arguments are a list of strings that are optionally followed by a boolean value for example:
// WithFeatures([]interface{}{"my_feature", "other_feature"}) or WithFeatures([]interface{}{"my_feature", true})
func WithFeatures(spec ...interface{}) *FeatureManager {
// WithFeatures([]any{"my_feature", "other_feature"}) or WithFeatures([]any{"my_feature", true})
func WithFeatures(spec ...any) *FeatureManager {
count := len(spec)
features := make(map[string]*FeatureFlag, count)
enabled := make(map[string]bool, count)
+1 -1
View File
@@ -8,7 +8,7 @@ import (
type configBody struct {
// define variables that can be used in expressions
Vars map[string]interface{} `yaml:"vars"`
Vars map[string]any `yaml:"vars"`
// Define and override feature flag properties
Flags []FeatureFlag `yaml:"flags"`
+1 -1
View File
@@ -13,7 +13,7 @@ func TestReadingFeatureSettings(t *testing.T) {
config, err := readConfigFile("testdata/features.yaml")
require.NoError(t, err, "No error when reading feature configs")
assert.Equal(t, map[string]interface{}{
assert.Equal(t, map[string]any{
"level": "free",
"stack": "something",
"valA": "value from features.yaml",
+2 -2
View File
@@ -7,9 +7,9 @@ import (
"github.com/grafana/grafana/pkg/services/featuremgmt/strcase"
)
func (fm *FeatureManager) GetUsageStats(ctx context.Context) map[string]interface{} {
func (fm *FeatureManager) GetUsageStats(ctx context.Context) map[string]any {
enabled := fm.GetEnabled(ctx)
stats := make(map[string]interface{}, len(enabled))
stats := make(map[string]any, len(enabled))
for featureName := range enabled {
stats[asMetricName(featureName)] = 1
}
+1 -1
View File
@@ -16,7 +16,7 @@ func TestFeatureUsageStats(t *testing.T) {
"feature.with.a.dot",
)
require.Equal(t, map[string]interface{}{
require.Equal(t, map[string]any{
"stats.features.trim_defaults.count": 1,
"stats.features.database_metrics.count": 1,
"stats.features.live_config.count": 1,
@@ -91,7 +91,7 @@ func (d *DashboardFolderStoreImpl) GetFolders(ctx context.Context, orgID int64,
var folders []*folder.Folder
if err := d.store.WithDbSession(ctx, func(sess *db.Session) error {
b := strings.Builder{}
args := make([]interface{}, 0, len(uids)+1)
args := make([]any, 0, len(uids)+1)
b.WriteString("SELECT * FROM dashboard WHERE org_id=? ")
args = append(args, orgID)
@@ -96,13 +96,13 @@ func TestIntegrationDashboardFolderStore(t *testing.T) {
})
}
func insertTestDashboard(t *testing.T, dashboardStore dashboards.Store, title string, orgId int64, folderId int64, tags ...interface{}) *dashboards.Dashboard {
func insertTestDashboard(t *testing.T, dashboardStore dashboards.Store, title string, orgId int64, folderId int64, tags ...any) *dashboards.Dashboard {
t.Helper()
cmd := dashboards.SaveDashboardCommand{
OrgID: orgId,
FolderID: folderId,
IsFolder: false,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": title,
"tags": tags,
@@ -116,13 +116,13 @@ func insertTestDashboard(t *testing.T, dashboardStore dashboards.Store, title st
return dash
}
func insertTestFolder(t *testing.T, dashboardStore dashboards.Store, title string, orgId int64, folderId int64, tags ...interface{}) *dashboards.Dashboard {
func insertTestFolder(t *testing.T, dashboardStore dashboards.Store, title string, orgId int64, folderId int64, tags ...any) *dashboards.Dashboard {
t.Helper()
cmd := dashboards.SaveDashboardCommand{
OrgID: orgId,
FolderID: folderId,
IsFolder: true,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"id": nil,
"title": title,
"tags": tags,
+6 -6
View File
@@ -42,10 +42,10 @@ func (ss *sqlStore) Create(ctx context.Context, cmd folder.CreateFolderCommand)
var lastInsertedID int64
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
var sql string
var args []interface{}
var args []any
if cmd.ParentUID == "" {
sql = "INSERT INTO folder(org_id, uid, title, description, created, updated) VALUES(?, ?, ?, ?, ?, ?)"
args = []interface{}{cmd.OrgID, cmd.UID, cmd.Title, cmd.Description, time.Now(), time.Now()}
args = []any{cmd.OrgID, cmd.UID, cmd.Title, cmd.Description, time.Now(), time.Now()}
} else {
if cmd.ParentUID != folder.GeneralFolderUID {
if _, err := ss.Get(ctx, folder.GetFolderQuery{
@@ -56,7 +56,7 @@ func (ss *sqlStore) Create(ctx context.Context, cmd folder.CreateFolderCommand)
}
}
sql = "INSERT INTO folder(org_id, uid, parent_uid, title, description, created, updated) VALUES(?, ?, ?, ?, ?, ?, ?)"
args = []interface{}{cmd.OrgID, cmd.UID, cmd.ParentUID, cmd.Title, cmd.Description, time.Now(), time.Now()}
args = []any{cmd.OrgID, cmd.UID, cmd.ParentUID, cmd.Title, cmd.Description, time.Now(), time.Now()}
}
var err error
@@ -99,7 +99,7 @@ func (ss *sqlStore) Update(ctx context.Context, cmd folder.UpdateFolderCommand)
sql := strings.Builder{}
sql.WriteString("UPDATE folder SET ")
columnsToUpdate := []string{"updated = ?"}
args := []interface{}{updated}
args := []any{updated}
if cmd.NewDescription != nil {
columnsToUpdate = append(columnsToUpdate, "description = ?")
args = append(args, *cmd.NewDescription)
@@ -133,7 +133,7 @@ func (ss *sqlStore) Update(ctx context.Context, cmd folder.UpdateFolderCommand)
sql.WriteString(" WHERE uid = ? AND org_id = ?")
args = append(args, cmd.UID, cmd.OrgID)
args = append([]interface{}{sql.String()}, args...)
args = append([]any{sql.String()}, args...)
res, err := sess.Exec(args...)
if err != nil {
@@ -242,7 +242,7 @@ func (ss *sqlStore) GetChildren(ctx context.Context, q folder.GetChildrenQuery)
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
sql := strings.Builder{}
args := make([]interface{}, 0, 2)
args := make([]any, 0, 2)
if q.UID == "" {
sql.WriteString("SELECT * FROM folder WHERE parent_uid IS NULL AND org_id=? ORDER BY title ASC")
args = append(args, q.OrgID)
+3 -3
View File
@@ -22,7 +22,7 @@ func (l *logAdapter) WithName(name string) logr.LogSink {
return l
}
func (l *logAdapter) WithValues(keysAndValues ...interface{}) logr.LogSink {
func (l *logAdapter) WithValues(keysAndValues ...any) logr.LogSink {
l.log = l.log.New(keysAndValues...)
return l
}
@@ -35,7 +35,7 @@ func (l *logAdapter) Enabled(level int) bool {
return level <= 5
}
func (l *logAdapter) Info(level int, msg string, keysAndValues ...interface{}) {
func (l *logAdapter) Info(level int, msg string, keysAndValues ...any) {
msg = strings.TrimSpace(msg)
if level < 1 {
l.log.Info(msg, keysAndValues...)
@@ -44,7 +44,7 @@ func (l *logAdapter) Info(level int, msg string, keysAndValues ...interface{}) {
l.log.Debug(msg, keysAndValues...)
}
func (l *logAdapter) Error(err error, msg string, keysAndValues ...interface{}) {
func (l *logAdapter) Error(err error, msg string, keysAndValues ...any) {
msg = strings.TrimSpace(msg)
l.log.Error(msg, keysAndValues...)
}
@@ -13,10 +13,10 @@ const tracingPrefix = "gRPC Server "
func TracingUnaryInterceptor(tracer tracing.Tracer) grpc.UnaryServerInterceptor {
return func(
ctx context.Context,
req interface{},
req any,
info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler,
) (resp interface{}, err error) {
) (resp any, err error) {
ctx, span := tracer.Start(ctx, tracingPrefix+info.FullMethod)
defer span.End()
resp, err = handler(ctx, req)
@@ -25,7 +25,7 @@ func TracingUnaryInterceptor(tracer tracing.Tracer) grpc.UnaryServerInterceptor
}
func TracingStreamInterceptor(tracer tracing.Tracer) grpc.StreamServerInterceptor {
return func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
return func(srv any, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
ctx, span := tracer.Start(stream.Context(), tracingPrefix+info.FullMethod)
defer span.End()
tracingStream := &tracingServerStream{
+1 -1
View File
@@ -70,7 +70,7 @@ func readConfig(configFile string) (*ldap.Config, error) {
return result, nil
}
func assertNotEmptyCfg(val interface{}, propName string) error {
func assertNotEmptyCfg(val any, propName string) error {
switch v := val.(type) {
case string:
if v == "" {
+1 -1
View File
@@ -175,7 +175,7 @@ func readConfig(configFile string) (*Config, error) {
return result, nil
}
func assertNotEmptyCfg(val interface{}, propName string) error {
func assertNotEmptyCfg(val any, propName string) error {
switch v := val.(type) {
case string:
if v == "" {
+1 -1
View File
@@ -54,7 +54,7 @@ LEFT JOIN ` + user + ` AS u2 ON le.updated_by = u2.id
}
func syncFieldsWithModel(libraryElement *model.LibraryElement) error {
var modelLibraryElement map[string]interface{}
var modelLibraryElement map[string]any
if err := json.Unmarshal(libraryElement.Model, &modelLibraryElement); err != nil {
return err
}
@@ -78,13 +78,13 @@ func (l *LibraryElementService) DeleteLibraryElementsInFolder(c context.Context,
}
func (l *LibraryElementService) addUidToLibraryPanel(model []byte, newUid string) (json.RawMessage, error) {
var modelMap map[string]interface{}
var modelMap map[string]any
err := json.Unmarshal(model, &modelMap)
if err != nil {
return nil, err
}
if libraryPanel, ok := modelMap["libraryPanel"].(map[string]interface{}); ok {
if libraryPanel, ok := modelMap["libraryPanel"].(map[string]any); ok {
if uid, ok := libraryPanel["uid"]; ok && uid == "" {
libraryPanel["uid"] = newUid
}
@@ -32,7 +32,7 @@ func TestCreateLibraryElement(t *testing.T) {
Kind: int64(model.PanelElement),
Type: "text",
Description: "A description",
Model: map[string]interface{}{
Model: map[string]any{
"datasource": "${DS_GDEV-TESTDATA}",
"description": "A description",
"id": float64(1),
@@ -81,7 +81,7 @@ func TestCreateLibraryElement(t *testing.T) {
Kind: int64(model.PanelElement),
Type: "text",
Description: "A description",
Model: map[string]interface{}{
Model: map[string]any{
"datasource": "${DS_GDEV-TESTDATA}",
"description": "A description",
"id": float64(1),
@@ -156,7 +156,7 @@ func TestCreateLibraryElement(t *testing.T) {
Kind: int64(model.PanelElement),
Type: "text",
Description: "A description",
Model: map[string]interface{}{
Model: map[string]any{
"datasource": "${DS_GDEV-TESTDATA}",
"description": "A description",
"id": float64(1),
@@ -43,26 +43,26 @@ func TestDeleteLibraryElement(t *testing.T) {
scenarioWithPanel(t, "When an admin tries to delete a library panel that is connected, it should fail",
func(t *testing.T, sc scenarioContext) {
dashJSON := map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
dashJSON := map[string]any{
"panels": []any{
map[string]any{
"id": int64(1),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
map[string]any{
"id": int64(2),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 6,
"y": 0,
},
"libraryPanel": map[string]interface{}{
"libraryPanel": map[string]any{
"uid": sc.initialResult.Result.UID,
"name": sc.initialResult.Result.Name,
},
@@ -40,7 +40,7 @@ func TestGetLibraryElement(t *testing.T) {
Kind: int64(model.PanelElement),
Type: "text",
Description: "A description",
Model: map[string]interface{}{
Model: map[string]any{
"datasource": "${DS_GDEV-TESTDATA}",
"description": "A description",
"id": float64(1),
@@ -92,26 +92,26 @@ func TestGetLibraryElement(t *testing.T) {
scenarioWithPanel(t, "When an admin tries to get a connected library panel, it should succeed and return correct connected dashboards",
func(t *testing.T, sc scenarioContext) {
dashJSON := map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
dashJSON := map[string]any{
"panels": []any{
map[string]any{
"id": int64(1),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
map[string]any{
"id": int64(2),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 6,
"y": 0,
},
"libraryPanel": map[string]interface{}{
"libraryPanel": map[string]any{
"uid": sc.initialResult.Result.UID,
"name": sc.initialResult.Result.Name,
},
@@ -137,7 +137,7 @@ func TestGetLibraryElement(t *testing.T) {
Kind: int64(model.PanelElement),
Type: "text",
Description: "A description",
Model: map[string]interface{}{
Model: map[string]any{
"datasource": "${DS_GDEV-TESTDATA}",
"description": "A description",
"id": float64(1),
@@ -55,7 +55,7 @@ func TestPatchLibraryElement(t *testing.T) {
Kind: int64(model.PanelElement),
Type: "graph",
Description: "An updated description",
Model: map[string]interface{}{
Model: map[string]any{
"datasource": "${DS_GDEV-TESTDATA}",
"description": "An updated description",
"id": float64(1),
@@ -219,7 +219,7 @@ func TestPatchLibraryElement(t *testing.T) {
var result = validateAndUnMarshalResponse(t, resp)
sc.initialResult.Result.Type = "graph"
sc.initialResult.Result.Description = "New description"
sc.initialResult.Result.Model = map[string]interface{}{
sc.initialResult.Result.Model = map[string]any{
"title": "New Model Title",
"name": "New Model Name",
"type": "graph",
@@ -248,7 +248,7 @@ func TestPatchLibraryElement(t *testing.T) {
var result = validateAndUnMarshalResponse(t, resp)
sc.initialResult.Result.Type = "text"
sc.initialResult.Result.Description = "New description"
sc.initialResult.Result.Model = map[string]interface{}{
sc.initialResult.Result.Model = map[string]any{
"type": "text",
"description": "New description",
}
@@ -275,7 +275,7 @@ func TestPatchLibraryElement(t *testing.T) {
var result = validateAndUnMarshalResponse(t, resp)
sc.initialResult.Result.Type = "graph"
sc.initialResult.Result.Description = "A description"
sc.initialResult.Result.Model = map[string]interface{}{
sc.initialResult.Result.Model = map[string]any{
"type": "graph",
"description": "A description",
}
@@ -386,7 +386,7 @@ func TestPatchLibraryElement(t *testing.T) {
sc.initialResult.Result.Type = "text"
sc.initialResult.Result.Kind = int64(model.PanelElement)
sc.initialResult.Result.Description = "A description"
sc.initialResult.Result.Model = map[string]interface{}{
sc.initialResult.Result.Model = map[string]any{
"datasource": "${DS_GDEV-TESTDATA}",
"id": float64(1),
"title": "Text - Library Panel",
@@ -52,26 +52,26 @@ const userInDbAvatar = "/avatar/402d08de060496d6b6874495fe20f5ad"
func TestDeleteLibraryPanelsInFolder(t *testing.T) {
scenarioWithPanel(t, "When an admin tries to delete a folder that contains connected library elements, it should fail",
func(t *testing.T, sc scenarioContext) {
dashJSON := map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
dashJSON := map[string]any{
"panels": []any{
map[string]any{
"id": int64(1),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
map[string]any{
"id": int64(2),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 6,
"y": 0,
},
"libraryPanel": map[string]interface{}{
"libraryPanel": map[string]any{
"uid": sc.initialResult.Result.UID,
"name": sc.initialResult.Result.Name,
},
@@ -125,26 +125,26 @@ func TestDeleteLibraryPanelsInFolder(t *testing.T) {
func TestGetLibraryPanelConnections(t *testing.T) {
scenarioWithPanel(t, "When an admin tries to get connections of library panel, it should succeed and return correct result",
func(t *testing.T, sc scenarioContext) {
dashJSON := map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
dashJSON := map[string]any{
"panels": []any{
map[string]any{
"id": int64(1),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
map[string]any{
"id": int64(2),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 6,
"y": 0,
},
"libraryPanel": map[string]interface{}{
"libraryPanel": map[string]any{
"uid": sc.initialResult.Result.UID,
"name": sc.initialResult.Result.Name,
},
@@ -198,7 +198,7 @@ type libraryElement struct {
Kind int64 `json:"kind"`
Type string `json:"type"`
Description string `json:"description"`
Model map[string]interface{} `json:"model"`
Model map[string]any `json:"model"`
Version int64 `json:"version"`
Meta model.LibraryElementDTOMeta `json:"meta"`
}
@@ -488,7 +488,7 @@ func getCompareOptions() []cmp.Option {
}
}
func mockRequestBody(v interface{}) io.ReadCloser {
func mockRequestBody(v any) io.ReadCloser {
b, _ := json.Marshal(v)
return io.NopCloser(bytes.NewReader(b))
}
+6 -6
View File
@@ -12,12 +12,12 @@ import (
type Pair struct {
key string
value interface{}
value any
}
func selectLibraryElementByParam(params []Pair) (string, []interface{}) {
func selectLibraryElementByParam(params []Pair) (string, []any) {
conditions := make([]string, 0, len(params))
values := make([]interface{}, 0, len(params))
values := make([]any, 0, len(params))
for _, p := range params {
conditions = append(conditions, "le."+p.key+"=?")
values = append(values, p.value)
@@ -48,7 +48,7 @@ func writeKindSQL(query model.SearchLibraryElementsQuery, builder *db.SQLBuilder
func writeTypeFilterSQL(typeFilter []string, builder *db.SQLBuilder) {
if len(typeFilter) > 0 {
var sql bytes.Buffer
params := make([]interface{}, 0)
params := make([]any, 0)
sql.WriteString(` AND le.type IN (?` + strings.Repeat(",?", len(typeFilter)-1) + ")")
for _, filter := range typeFilter {
params = append(params, filter)
@@ -129,7 +129,7 @@ func parseFolderFilter(query model.SearchLibraryElementsQuery) FolderFilter {
func (f *FolderFilter) writeFolderFilterSQL(includeGeneral bool, builder *db.SQLBuilder) error {
var sql bytes.Buffer
params := make([]interface{}, 0)
params := make([]any, 0)
for _, filter := range f.folderIDs {
folderID, err := strconv.ParseInt(filter, 10, 64)
if err != nil {
@@ -145,7 +145,7 @@ func (f *FolderFilter) writeFolderFilterSQL(includeGeneral bool, builder *db.SQL
builder.Write(sql.String(), params...)
}
paramsUIDs := make([]interface{}, 0)
paramsUIDs := make([]any, 0)
for _, folderUID := range f.folderUIDs {
if !includeGeneral && isUIDGeneralFolder(folderUID) {
continue
+6 -6
View File
@@ -39,11 +39,11 @@ func ProvideService(cfg *setting.Cfg, sqlStore db.DB, routeRegister routing.Rout
// Service is a service for operating on library panels.
type Service interface {
ConnectLibraryPanelsForDashboard(c context.Context, signedInUser *user.SignedInUser, dash *dashboards.Dashboard) error
ImportLibraryPanelsForDashboard(c context.Context, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []interface{}, folderID int64) error
ImportLibraryPanelsForDashboard(c context.Context, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []any, folderID int64) error
}
type LibraryInfo struct {
Panels []*interface{}
Panels []*any
LibraryPanels *simplejson.Json
}
@@ -78,7 +78,7 @@ func isLibraryPanelOrRow(panel *simplejson.Json, panelType string) bool {
return panel.Interface() != nil || panelType == "row"
}
func connectLibraryPanelsRecursively(c context.Context, panels []interface{}, libraryPanels map[string]string) error {
func connectLibraryPanelsRecursively(c context.Context, panels []any, libraryPanels map[string]string) error {
for _, panel := range panels {
panelAsJSON := simplejson.NewFromAny(panel)
libraryPanel := panelAsJSON.Get("libraryPanel")
@@ -112,11 +112,11 @@ func connectLibraryPanelsRecursively(c context.Context, panels []interface{}, li
}
// ImportLibraryPanelsForDashboard loops through all panels in dashboard JSON and creates any missing library panels in the database.
func (lps *LibraryPanelService) ImportLibraryPanelsForDashboard(c context.Context, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []interface{}, folderID int64) error {
func (lps *LibraryPanelService) ImportLibraryPanelsForDashboard(c context.Context, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []any, folderID int64) error {
return importLibraryPanelsRecursively(c, lps.LibraryElementService, signedInUser, libraryPanels, panels, folderID)
}
func importLibraryPanelsRecursively(c context.Context, service libraryelements.Service, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []interface{}, folderID int64) error {
func importLibraryPanelsRecursively(c context.Context, service libraryelements.Service, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []any, folderID int64) error {
for _, panel := range panels {
panelAsJSON := simplejson.NewFromAny(panel)
libraryPanel := panelAsJSON.Get("libraryPanel")
@@ -152,7 +152,7 @@ func importLibraryPanelsRecursively(c context.Context, service libraryelements.S
}
elementModel := libraryPanels.Get(UID).Get("model")
elementModel.Set("libraryPanel", map[string]interface{}{
elementModel.Set("libraryPanel", map[string]any{
"uid": UID,
})
@@ -48,27 +48,27 @@ const userInDbAvatar = "/avatar/402d08de060496d6b6874495fe20f5ad"
func TestConnectLibraryPanelsForDashboard(t *testing.T) {
scenarioWithLibraryPanel(t, "When an admin tries to store a dashboard with a library panel, it should connect the two",
func(t *testing.T, sc scenarioContext) {
dashJSON := map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
dashJSON := map[string]any{
"panels": []any{
map[string]any{
"id": int64(1),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
map[string]any{
"id": int64(2),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 6,
"y": 0,
},
"datasource": "${DS_GDEV-TESTDATA}",
"libraryPanel": map[string]interface{}{
"libraryPanel": map[string]any{
"uid": sc.initialResult.Result.UID,
},
"title": "Text - Library Panel",
@@ -109,20 +109,20 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
}
outsidePanel, err := sc.elementService.CreateElement(sc.ctx, sc.user, cmd)
require.NoError(t, err)
dashJSON := map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
dashJSON := map[string]any{
"panels": []any{
map[string]any{
"id": int64(1),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
map[string]any{
"collapsed": true,
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
@@ -130,26 +130,26 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
},
"id": int64(2),
"type": "row",
"panels": []interface{}{
map[string]interface{}{
"panels": []any{
map[string]any{
"id": int64(3),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 7,
},
},
map[string]interface{}{
map[string]any{
"id": int64(4),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 6,
"y": 13,
},
"datasource": "${DS_GDEV-TESTDATA}",
"libraryPanel": map[string]interface{}{
"libraryPanel": map[string]any{
"uid": sc.initialResult.Result.UID,
},
"title": "Inside row",
@@ -157,16 +157,16 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
},
},
},
map[string]interface{}{
map[string]any{
"id": int64(5),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 19,
},
"datasource": "${DS_GDEV-TESTDATA}",
"libraryPanel": map[string]interface{}{
"libraryPanel": map[string]any{
"uid": outsidePanel.UID,
},
"title": "Outside row",
@@ -192,27 +192,27 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
scenarioWithLibraryPanel(t, "When an admin tries to store a dashboard with a library panel without uid, it should fail",
func(t *testing.T, sc scenarioContext) {
dashJSON := map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
dashJSON := map[string]any{
"panels": []any{
map[string]any{
"id": int64(1),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
map[string]any{
"id": int64(2),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 6,
"y": 0,
},
"datasource": "${DS_GDEV-TESTDATA}",
"libraryPanel": map[string]interface{}{
"libraryPanel": map[string]any{
"name": sc.initialResult.Result.Name,
},
"title": "Text - Library Panel",
@@ -247,27 +247,27 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
Kind: int64(model.PanelElement),
})
require.NoError(t, err)
dashJSON := map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
dashJSON := map[string]any{
"panels": []any{
map[string]any{
"id": int64(1),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
map[string]any{
"id": int64(4),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 6,
"y": 0,
},
"datasource": "${DS_GDEV-TESTDATA}",
"libraryPanel": map[string]interface{}{
"libraryPanel": map[string]any{
"uid": unused.UID,
},
"title": "Unused Libray Panel",
@@ -284,26 +284,26 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
err = sc.elementService.ConnectElementsToDashboard(sc.ctx, sc.user, []string{sc.initialResult.Result.UID}, dashInDB.ID)
require.NoError(t, err)
panelJSON := []interface{}{
map[string]interface{}{
panelJSON := []any{
map[string]any{
"id": int64(1),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
map[string]any{
"id": int64(2),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 6,
"y": 0,
},
"datasource": "${DS_GDEV-TESTDATA}",
"libraryPanel": map[string]interface{}{
"libraryPanel": map[string]any{
"uid": sc.initialResult.Result.UID,
},
"title": "Text - Library Panel",
@@ -343,9 +343,9 @@ func TestImportLibraryPanelsForDashboard(t *testing.T) {
func(t *testing.T, sc scenarioContext) {
var missingUID = "jL6MrxCMz"
var missingName = "Missing Library Panel"
var missingModel = map[string]interface{}{
var missingModel = map[string]any{
"id": int64(2),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": int64(6),
"w": int64(6),
"x": int64(0),
@@ -353,31 +353,31 @@ func TestImportLibraryPanelsForDashboard(t *testing.T) {
},
"description": "",
"datasource": "${DS_GDEV-TESTDATA}",
"libraryPanel": map[string]interface{}{
"libraryPanel": map[string]any{
"uid": missingUID,
"name": missingName,
},
"title": "Text - Library Panel",
"type": "text",
}
var libraryElements = map[string]interface{}{
missingUID: map[string]interface{}{
var libraryElements = map[string]any{
missingUID: map[string]any{
"model": missingModel,
},
}
panels := []interface{}{
map[string]interface{}{
panels := []any{
map[string]any{
"id": int64(1),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
"libraryPanel": map[string]interface{}{
map[string]any{
"libraryPanel": map[string]any{
"uid": missingUID,
"name": missingName,
},
@@ -407,18 +407,18 @@ func TestImportLibraryPanelsForDashboard(t *testing.T) {
var existingUID = sc.initialResult.Result.UID
var existingName = sc.initialResult.Result.Name
panels := []interface{}{
map[string]interface{}{
panels := []any{
map[string]any{
"id": int64(1),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
"libraryPanel": map[string]interface{}{
map[string]any{
"libraryPanel": map[string]any{
"uid": sc.initialResult.Result.UID,
"name": sc.initialResult.Result.Name,
},
@@ -450,16 +450,16 @@ func TestImportLibraryPanelsForDashboard(t *testing.T) {
func(t *testing.T, sc scenarioContext) {
var outsideUID = "jL6MrxCMz"
var outsideName = "Outside Library Panel"
var outsideModel = map[string]interface{}{
var outsideModel = map[string]any{
"id": int64(5),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 19,
},
"datasource": "${DS_GDEV-TESTDATA}",
"libraryPanel": map[string]interface{}{
"libraryPanel": map[string]any{
"uid": outsideUID,
"name": outsideName,
},
@@ -469,16 +469,16 @@ func TestImportLibraryPanelsForDashboard(t *testing.T) {
var insideUID = "iK7NsyDNz"
var insideName = "Inside Library Panel"
var insideModel = map[string]interface{}{
var insideModel = map[string]any{
"id": int64(4),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 6,
"y": 13,
},
"datasource": "${DS_GDEV-TESTDATA}",
"libraryPanel": map[string]interface{}{
"libraryPanel": map[string]any{
"uid": insideUID,
"name": insideName,
},
@@ -486,34 +486,34 @@ func TestImportLibraryPanelsForDashboard(t *testing.T) {
"type": "text",
}
var libraryElements = map[string]interface{}{
outsideUID: map[string]interface{}{
var libraryElements = map[string]any{
outsideUID: map[string]any{
"model": outsideModel,
},
insideUID: map[string]interface{}{
insideUID: map[string]any{
"model": insideModel,
},
}
panels := []interface{}{
map[string]interface{}{
panels := []any{
map[string]any{
"id": int64(1),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
"libraryPanel": map[string]interface{}{
map[string]any{
"libraryPanel": map[string]any{
"uid": outsideUID,
"name": outsideName,
},
},
map[string]interface{}{
map[string]any{
"collapsed": true,
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
@@ -521,18 +521,18 @@ func TestImportLibraryPanelsForDashboard(t *testing.T) {
},
"id": int64(2),
"type": "row",
"panels": []interface{}{
map[string]interface{}{
"panels": []any{
map[string]any{
"id": int64(3),
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"h": 6,
"w": 6,
"x": 0,
"y": 7,
},
},
map[string]interface{}{
"libraryPanel": map[string]interface{}{
map[string]any{
"libraryPanel": map[string]any{
"uid": insideUID,
"name": insideName,
},
@@ -574,7 +574,7 @@ type libraryPanel struct {
Name string
Type string
Description string
Model map[string]interface{}
Model map[string]any
Version int64
Meta model.LibraryElementDTOMeta
}
@@ -666,7 +666,7 @@ func toLibraryElement(t *testing.T, res model.LibraryElementDTO) libraryElement
}
}
func getExpected(t *testing.T, res model.LibraryElementDTO, UID string, name string, lEModel map[string]interface{}) libraryElement {
func getExpected(t *testing.T, res model.LibraryElementDTO, UID string, name string, lEModel map[string]any) libraryElement {
marshalled, err := json.Marshal(lEModel)
require.NoError(t, err)
var libModel libraryElementModel
@@ -777,7 +777,7 @@ func scenarioWithLibraryPanel(t *testing.T, desc string, fn func(t *testing.T, s
}
resp, err := sc.elementService.CreateElement(sc.ctx, sc.user, command)
require.NoError(t, err)
var model map[string]interface{}
var model map[string]any
err = json.Unmarshal(resp.Model, &model)
require.NoError(t, err)
+1 -1
View File
@@ -46,7 +46,7 @@ func (m *MockPluginContextGetter) GetPluginContext(arg0 context.Context, arg1 id
}
// GetPluginContext indicates an expected call of GetPluginContext.
func (mr *MockPluginContextGetterMockRecorder) GetPluginContext(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
func (mr *MockPluginContextGetterMockRecorder) GetPluginContext(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPluginContext", reflect.TypeOf((*MockPluginContextGetter)(nil).GetPluginContext), arg0, arg1, arg2, arg3, arg4)
}
@@ -29,8 +29,8 @@ func (out *LokiDataOutput) OutputData(_ context.Context, vars Vars, data []byte)
}
err := out.lokiWriter.write(LokiStream{
Stream: map[string]string{"channel": vars.Channel},
Values: []interface{}{
[]interface{}{time.Now().UnixNano(), string(data)},
Values: []any{
[]any{time.Now().UnixNano(), string(data)},
},
})
return nil, err
+10 -10
View File
@@ -17,15 +17,15 @@ import (
)
type Data struct {
Value1 float64 `json:"value1"`
Value2 float64 `json:"value2"`
Value3 *float64 `json:"value3"`
Value4 float64 `json:"value4"`
Annotation string `json:"annotation"`
Array []float64 `json:"array"`
Map map[string]interface{} `json:"map"`
Host string `json:"host"`
Status string `json:"status"`
Value1 float64 `json:"value1"`
Value2 float64 `json:"value2"`
Value3 *float64 `json:"value3"`
Value4 float64 `json:"value4"`
Annotation string `json:"annotation"`
Array []float64 `json:"array"`
Map map[string]any `json:"map"`
Host string `json:"host"`
Status string `json:"status"`
}
// TODO: temporary for development, remove.
@@ -41,7 +41,7 @@ func postTestData() {
Value4: float64(i % 10),
Annotation: "odd",
Array: []float64{float64(rand.Intn(10)), float64(rand.Intn(10))},
Map: map[string]interface{}{
Map: map[string]any{
"red": 1,
"yellow": 4,
"green": 7,
@@ -54,7 +54,7 @@ func (out *ChangeLogFrameOutput) OutputFrame(_ context.Context, vars Vars, frame
}
}
var previousValue interface{}
var previousValue any
if previousFrameFieldIndex >= 0 {
// Take last value for the field.
previousValue = previousFrame.Fields[previousFrameFieldIndex].At(previousFrame.Fields[previousFrameFieldIndex].Len() - 1)
@@ -38,7 +38,7 @@ type LokiStreamsEntry struct {
type LokiStream struct {
Stream map[string]string `json:"stream"`
Values []interface{} `json:"values"`
Values []any `json:"values"`
}
func (out *LokiFrameOutput) OutputFrame(_ context.Context, vars Vars, frame *data.Frame) ([]*ChannelFrame, error) {
@@ -52,8 +52,8 @@ func (out *LokiFrameOutput) OutputFrame(_ context.Context, vars Vars, frame *dat
}
err = out.lokiWriter.write(LokiStream{
Stream: map[string]string{"frame": frame.Name, "channel": vars.Channel},
Values: []interface{}{
[]interface{}{time.Now().UnixNano(), string(frameJSON)},
Values: []any{
[]any{time.Now().UnixNano(), string(frameJSON)},
},
})
return nil, err
@@ -45,7 +45,7 @@ func (m *MockFrameGetSetter) Get(arg0 int64, arg1 string) (*data.Frame, bool, er
}
// Get indicates an expected call of Get.
func (mr *MockFrameGetSetterMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call {
func (mr *MockFrameGetSetterMockRecorder) Get(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockFrameGetSetter)(nil).Get), arg0, arg1)
}
@@ -59,7 +59,7 @@ func (m *MockFrameGetSetter) Set(arg0 int64, arg1 string, arg2 *data.Frame) erro
}
// Set indicates an expected call of Set.
func (mr *MockFrameGetSetterMockRecorder) Set(arg0, arg1, arg2 interface{}) *gomock.Call {
func (mr *MockFrameGetSetterMockRecorder) Set(arg0, arg1, arg2 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockFrameGetSetter)(nil).Set), arg0, arg1, arg2)
}
+3 -3
View File
@@ -1,9 +1,9 @@
package pipeline
type EntityInfo struct {
Type string `json:"type"`
Description string `json:"description"`
Example interface{} `json:"example,omitempty"`
Type string `json:"type"`
Description string `json:"description"`
Example any `json:"example,omitempty"`
}
var SubscribersRegistry = []EntityInfo{
+1 -1
View File
@@ -65,7 +65,7 @@ const (
catchAll
)
type Handler interface{}
type Handler any
func New() *Node {
return new(Node)
+1 -1
View File
@@ -350,7 +350,7 @@ func TestUnescapeParameters(t *testing.T) {
checkPriorities(t, tree)
}
func catchPanic(testFunc func()) (recv interface{}) {
func catchPanic(testFunc func()) (recv any) {
defer func() {
recv = recover()
}()
+1 -1
View File
@@ -120,7 +120,7 @@ func sanitizeLabelName(name string) (string, bool) {
}
// sampleValue converts a field value into a value suitable for a simple sample value.
func sampleValue(value interface{}) (float64, bool) {
func sampleValue(value any) (float64, bool) {
switch v := value.(type) {
case float64:
return v, true
+4 -4
View File
@@ -45,7 +45,7 @@ func (m *MockChannelLocalPublisher) PublishLocal(arg0 string, arg1 []byte) error
}
// PublishLocal indicates an expected call of PublishLocal.
func (mr *MockChannelLocalPublisherMockRecorder) PublishLocal(arg0, arg1 interface{}) *gomock.Call {
func (mr *MockChannelLocalPublisherMockRecorder) PublishLocal(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PublishLocal", reflect.TypeOf((*MockChannelLocalPublisher)(nil).PublishLocal), arg0, arg1)
}
@@ -83,7 +83,7 @@ func (m *MockNumLocalSubscribersGetter) GetNumLocalSubscribers(arg0 string) (int
}
// GetNumLocalSubscribers indicates an expected call of GetNumLocalSubscribers.
func (mr *MockNumLocalSubscribersGetterMockRecorder) GetNumLocalSubscribers(arg0 interface{}) *gomock.Call {
func (mr *MockNumLocalSubscribersGetterMockRecorder) GetNumLocalSubscribers(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNumLocalSubscribers", reflect.TypeOf((*MockNumLocalSubscribersGetter)(nil).GetNumLocalSubscribers), arg0)
}
@@ -120,7 +120,7 @@ func (m *MockStreamRunner) RunStream(arg0 context.Context, arg1 *backend.RunStre
}
// RunStream indicates an expected call of RunStream.
func (mr *MockStreamRunnerMockRecorder) RunStream(arg0, arg1, arg2 interface{}) *gomock.Call {
func (mr *MockStreamRunnerMockRecorder) RunStream(arg0, arg1, arg2 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RunStream", reflect.TypeOf((*MockStreamRunner)(nil).RunStream), arg0, arg1, arg2)
}
@@ -158,7 +158,7 @@ func (m *MockPluginContextGetter) GetPluginContext(arg0 context.Context, arg1 id
}
// GetPluginContext indicates an expected call of GetPluginContext.
func (mr *MockPluginContextGetterMockRecorder) GetPluginContext(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
func (mr *MockPluginContextGetterMockRecorder) GetPluginContext(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPluginContext", reflect.TypeOf((*MockPluginContextGetter)(nil).GetPluginContext), arg0, arg1, arg2, arg3, arg4)
}
+2 -2
View File
@@ -42,7 +42,7 @@ type NodeManagedChannelsResponse struct {
func (c *Caller) handleSurvey(e centrifuge.SurveyEvent, cb centrifuge.SurveyCallback) {
var (
resp interface{}
resp any
err error
)
switch e.Op {
@@ -66,7 +66,7 @@ func (c *Caller) handleSurvey(e centrifuge.SurveyEvent, cb centrifuge.SurveyCall
})
}
func (c *Caller) handleManagedStreams(data []byte) (interface{}, error) {
func (c *Caller) handleManagedStreams(data []byte) (any, error) {
var req NodeManagedChannelsRequest
err := json.Unmarshal(data, &req)
if err != nil {
@@ -275,7 +275,7 @@ func (s *metricFrame) append(m influx.Metric) error {
// float64FieldTypeFor converts all numbers to float64.
// The precision can be lost during big int64 or uint64 conversion to float64.
func float64FieldTypeFor(t interface{}) data.FieldType {
func float64FieldTypeFor(t any) data.FieldType {
switch t.(type) {
case int8:
return data.FieldTypeFloat64
@@ -309,7 +309,7 @@ func float64FieldTypeFor(t interface{}) data.FieldType {
return data.FieldTypeUnknown
}
func (s *metricFrame) getFieldTypeAndValue(f *influx.Field) (data.FieldType, interface{}, error) {
func (s *metricFrame) getFieldTypeAndValue(f *influx.Field) (data.FieldType, any, error) {
var ft data.FieldType
if s.useFloatNumbers {
ft = float64FieldTypeFor(f.Value)
@@ -344,8 +344,8 @@ func (s *metricFrame) getFieldTypeAndValue(f *influx.Field) (data.FieldType, int
return ft, v, nil
}
func getConvertFunc(ft data.FieldType) (func(v interface{}) (interface{}, error), bool) {
var convert func(v interface{}) (interface{}, error)
func getConvertFunc(ft data.FieldType) (func(v any) (any, error), bool) {
var convert func(v any) (any, error)
switch ft {
case data.FieldTypeNullableString:
convert = converters.AnyToNullableString.Converter

Some files were not shown because too many files have changed in this diff Show More