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
+4 -4
View File
@@ -58,7 +58,7 @@ type OAuth2ServiceImpl struct {
saService serviceaccounts.Service
userService user.Service
teamService team.Service
publicKey interface{}
publicKey any
}
func ProvideService(router routing.RouteRegister, db db.DB, cfg *setting.Cfg,
@@ -77,7 +77,7 @@ func ProvideService(router routing.RouteRegister, db db.DB, cfg *setting.Cfg,
privateKey := keySvc.GetServerPrivateKey()
var publicKey interface{}
var publicKey any
switch k := privateKey.(type) {
case *rsa.PrivateKey:
publicKey = &k.PublicKey
@@ -109,8 +109,8 @@ func ProvideService(router routing.RouteRegister, db db.DB, cfg *setting.Cfg,
return s, nil
}
func newProvider(config *fosite.Config, storage interface{}, key interface{}) fosite.OAuth2Provider {
keyGetter := func(context.Context) (interface{}, error) {
func newProvider(config *fosite.Config, storage any, key any) fosite.OAuth2Provider {
keyGetter := func(context.Context) (any, error) {
return key, nil
}
return compose.Compose(
+13 -13
View File
@@ -52,7 +52,7 @@ func TestOAuth2ServiceImpl_handleClientCredentials(t *testing.T) {
name string
scopes []string
client *oauthserver.ExternalService
expectedClaims map[string]interface{}
expectedClaims map[string]any
wantErr bool
}{
{
@@ -73,7 +73,7 @@ func TestOAuth2ServiceImpl_handleClientCredentials(t *testing.T) {
name: "profile claims",
client: client1,
scopes: []string{"profile"},
expectedClaims: map[string]interface{}{"name": "Test App", "login": "testapp"},
expectedClaims: map[string]any{"name": "Test App", "login": "testapp"},
},
{
name: "email claims should be empty",
@@ -89,7 +89,7 @@ func TestOAuth2ServiceImpl_handleClientCredentials(t *testing.T) {
name: "entitlements claims",
client: client1,
scopes: []string{"entitlements"},
expectedClaims: map[string]interface{}{"entitlements": map[string][]string{
expectedClaims: map[string]any{"entitlements": map[string][]string{
"dashboards:read": {"dashboards:*", "folders:*"},
"dashboards:write": {"dashboards:uid:1"},
}},
@@ -98,7 +98,7 @@ func TestOAuth2ServiceImpl_handleClientCredentials(t *testing.T) {
name: "scoped entitlements claims",
client: client1,
scopes: []string{"entitlements", "dashboards:write"},
expectedClaims: map[string]interface{}{"entitlements": map[string][]string{
expectedClaims: map[string]any{"entitlements": map[string][]string{
"dashboards:write": {"dashboards:uid:1"},
}},
},
@@ -187,7 +187,7 @@ func TestOAuth2ServiceImpl_handleJWTBearer(t *testing.T) {
scopes []string
client *oauthserver.ExternalService
subject string
expectedClaims map[string]interface{}
expectedClaims map[string]any
wantErr bool
}{
{
@@ -248,7 +248,7 @@ func TestOAuth2ServiceImpl_handleJWTBearer(t *testing.T) {
client: client1,
subject: "user:id:56",
scopes: []string{"profile"},
expectedClaims: map[string]interface{}{
expectedClaims: map[string]any{
"name": "User 56",
"login": "user56",
"updated_at": now.Unix(),
@@ -262,7 +262,7 @@ func TestOAuth2ServiceImpl_handleJWTBearer(t *testing.T) {
client: client1,
subject: "user:id:56",
scopes: []string{"email"},
expectedClaims: map[string]interface{}{
expectedClaims: map[string]any{
"email": "user56@example.org",
},
},
@@ -275,7 +275,7 @@ func TestOAuth2ServiceImpl_handleJWTBearer(t *testing.T) {
client: client1,
subject: "user:id:56",
scopes: []string{"groups"},
expectedClaims: map[string]interface{}{
expectedClaims: map[string]any{
"groups": []string{"Team 1", "Team 2"},
},
},
@@ -293,7 +293,7 @@ func TestOAuth2ServiceImpl_handleJWTBearer(t *testing.T) {
{Action: "datasources:read", Scope: "datasources:*"},
}),
subject: "user:id:56",
expectedClaims: map[string]interface{}{
expectedClaims: map[string]any{
"entitlements": map[string][]string{},
},
scopes: []string{"entitlements"},
@@ -315,7 +315,7 @@ func TestOAuth2ServiceImpl_handleJWTBearer(t *testing.T) {
{Action: "datasources:read", Scope: "datasources:*"},
}),
subject: "user:id:56",
expectedClaims: map[string]interface{}{
expectedClaims: map[string]any{
"entitlements": map[string][]string{
"datasources:read": {"datasources:uid:1"},
},
@@ -339,7 +339,7 @@ func TestOAuth2ServiceImpl_handleJWTBearer(t *testing.T) {
{Action: "users.permissions:read", Scope: "users:self"},
}),
subject: "user:id:56",
expectedClaims: map[string]interface{}{
expectedClaims: map[string]any{
"entitlements": map[string][]string{
"users:read": {"global.users:id:56"},
"users.permissions:read": {"users:id:56"},
@@ -361,7 +361,7 @@ func TestOAuth2ServiceImpl_handleJWTBearer(t *testing.T) {
{Action: "teams:read", Scope: "teams:self"},
}),
subject: "user:id:56",
expectedClaims: map[string]interface{}{
expectedClaims: map[string]any{
"entitlements": map[string][]string{"teams:read": {"teams:id:1", "teams:id:2"}},
},
scopes: []string{"entitlements"},
@@ -384,7 +384,7 @@ func TestOAuth2ServiceImpl_handleJWTBearer(t *testing.T) {
{Action: "datasources:read", Scope: "datasources:*"},
}),
subject: "user:id:56",
expectedClaims: map[string]interface{}{
expectedClaims: map[string]any{
"entitlements": map[string][]string{"users:read": {"global.users:id:*"}},
},
scopes: []string{"entitlements", "users:read"},
+3 -3
View File
@@ -27,7 +27,7 @@ func createImpersonatePermissions(sess *db.Session, client *oauthserver.External
return nil
}
insertPermQuery := make([]interface{}, 1, len(client.ImpersonatePermissions)*3+1)
insertPermQuery := make([]any, 1, len(client.ImpersonatePermissions)*3+1)
insertPermStmt := `INSERT INTO oauth_impersonate_permission (client_id, action, scope) VALUES `
for _, perm := range client.ImpersonatePermissions {
insertPermStmt += "(?, ?, ?),"
@@ -39,7 +39,7 @@ func createImpersonatePermissions(sess *db.Session, client *oauthserver.External
}
func registerExternalService(sess *db.Session, client *oauthserver.ExternalService) error {
insertQuery := []interface{}{
insertQuery := []any{
`INSERT INTO oauth_client (name, client_id, secret, grant_types, audiences, service_account_id, public_pem, redirect_uri) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
client.Name,
client.ClientID,
@@ -77,7 +77,7 @@ func recreateImpersonatePermissions(sess *db.Session, client *oauthserver.Extern
}
func updateExternalService(sess *db.Session, client *oauthserver.ExternalService, prevClientID string) error {
updateQuery := []interface{}{
updateQuery := []any{
`UPDATE oauth_client SET client_id = ?, secret = ?, grant_types = ?, audiences = ?, service_account_id = ?, public_pem = ?, redirect_uri = ? WHERE name = ?`,
client.ClientID,
client.Secret,
+1 -1
View File
@@ -18,7 +18,7 @@ func ParseUserIDFromSubject(subject string) (int64, error) {
}
// ParsePublicKeyPem parses the public key from the PEM encoded public key.
func ParsePublicKeyPem(publicPem []byte) (interface{}, error) {
func ParsePublicKeyPem(publicPem []byte) (any, error) {
block, _ := pem.Decode(publicPem)
if block == nil {
return nil, errors.New("could not decode PEM block")