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)