1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +02:00

chore(code): replace interface{} with any EE-6513 (#11986)

This commit is contained in:
andres-portainer 2024-06-28 14:59:28 -03:00 committed by GitHub
parent 9c4935286f
commit f0d43f941f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
66 changed files with 231 additions and 231 deletions

View file

@ -61,7 +61,7 @@ func (*Service) Authenticate(code string, configuration *portainer.OAuthSettings
}
// mergeSecondIntoFirst merges the overlap map into the base overwriting any existing values.
func mergeSecondIntoFirst(base map[string]interface{}, overlap map[string]interface{}) map[string]interface{} {
func mergeSecondIntoFirst(base map[string]any, overlap map[string]any) map[string]any {
for k, v := range overlap {
base[k] = v
}
@ -87,8 +87,8 @@ func getOAuthToken(code string, configuration *portainer.OAuthSettings) (*oauth2
// getIdToken retrieves parsed id_token from the OAuth token response.
// This is necessary for OAuth providers like Azure
// that do not provide information about user groups on the user resource endpoint.
func getIdToken(token *oauth2.Token) (map[string]interface{}, error) {
tokenData := make(map[string]interface{})
func getIdToken(token *oauth2.Token) (map[string]any, error) {
tokenData := make(map[string]any)
idToken := token.Extra("id_token")
if idToken == nil {
@ -113,7 +113,7 @@ func getIdToken(token *oauth2.Token) (map[string]interface{}, error) {
return tokenData, nil
}
func getResource(token string, configuration *portainer.OAuthSettings) (map[string]interface{}, error) {
func getResource(token string, configuration *portainer.OAuthSettings) (map[string]any, error) {
req, err := http.NewRequest("GET", configuration.ResourceURI, nil)
if err != nil {
return nil, err
@ -151,7 +151,7 @@ func getResource(token string, configuration *portainer.OAuthSettings) (map[stri
return nil, err
}
datamap := make(map[string]interface{})
datamap := make(map[string]any)
for k, v := range values {
if len(v) == 0 {
datamap[k] = ""
@ -162,7 +162,7 @@ func getResource(token string, configuration *portainer.OAuthSettings) (map[stri
return datamap, nil
}
var datamap map[string]interface{}
var datamap map[string]any
if err = json.Unmarshal(body, &datamap); err != nil {
return nil, err
}

View file

@ -7,7 +7,7 @@ import (
portainer "github.com/portainer/portainer/api"
)
func getUsername(datamap map[string]interface{}, configuration *portainer.OAuthSettings) (string, error) {
func getUsername(datamap map[string]any, configuration *portainer.OAuthSettings) (string, error) {
username, ok := datamap[configuration.UserIdentifier].(string)
if ok && username != "" {
return username, nil

View file

@ -9,7 +9,7 @@ import (
func Test_getUsername(t *testing.T) {
t.Run("fails for non-matching user identifier", func(t *testing.T) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"name": "john"}
datamap := map[string]any{"name": "john"}
_, err := getUsername(datamap, oauthSettings)
if err == nil {
@ -19,7 +19,7 @@ func Test_getUsername(t *testing.T) {
t.Run("fails if username is empty string", func(t *testing.T) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"username": ""}
datamap := map[string]any{"username": ""}
_, err := getUsername(datamap, oauthSettings)
if err == nil {
@ -29,7 +29,7 @@ func Test_getUsername(t *testing.T) {
t.Run("fails if username is 0 int", func(t *testing.T) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"username": 0}
datamap := map[string]any{"username": 0}
_, err := getUsername(datamap, oauthSettings)
if err == nil {
@ -39,7 +39,7 @@ func Test_getUsername(t *testing.T) {
t.Run("fails if username is negative int", func(t *testing.T) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"username": -1}
datamap := map[string]any{"username": -1}
_, err := getUsername(datamap, oauthSettings)
if err == nil {
@ -49,7 +49,7 @@ func Test_getUsername(t *testing.T) {
t.Run("succeeds if username is matched and is not empty", func(t *testing.T) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"username": "john"}
datamap := map[string]any{"username": "john"}
_, err := getUsername(datamap, oauthSettings)
if err != nil {
@ -60,7 +60,7 @@ func Test_getUsername(t *testing.T) {
// looks like a bug!?
t.Run("fails if username is matched and is positive int", func(t *testing.T) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"username": 1}
datamap := map[string]any{"username": 1}
_, err := getUsername(datamap, oauthSettings)
if err == nil {
@ -70,7 +70,7 @@ func Test_getUsername(t *testing.T) {
t.Run("succeeds if username is matched and is non-zero (or negative) float", func(t *testing.T) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"username": 1.1}
datamap := map[string]any{"username": 1.1}
_, err := getUsername(datamap, oauthSettings)
if err != nil {

View file

@ -34,7 +34,7 @@ func Test_getOAuthToken(t *testing.T) {
func Test_getIdToken(t *testing.T) {
verifiedToken := `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2NTM1NDA3MjksImV4cCI6MTY4NTA3NjcyOSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJHaXZlbk5hbWUiOiJKb2huIiwiU3VybmFtZSI6IkRvZSIsIkdyb3VwcyI6WyJGaXJzdCIsIlNlY29uZCJdfQ.GeU8XCV4Y4p5Vm-i63Aj7UP5zpb_0Zxb7-DjM2_z-s8`
nonVerifiedToken := `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2NTM1NDA3MjksImV4cCI6MTY4NTA3NjcyOSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJHaXZlbk5hbWUiOiJKb2huIiwiU3VybmFtZSI6IkRvZSIsIkdyb3VwcyI6WyJGaXJzdCIsIlNlY29uZCJdfQ.`
claims := map[string]interface{}{
claims := map[string]any{
"iss": "Online JWT Builder",
"iat": float64(1653540729),
"exp": float64(1685076729),
@ -42,13 +42,13 @@ func Test_getIdToken(t *testing.T) {
"sub": "john.doe@example.com",
"GivenName": "John",
"Surname": "Doe",
"Groups": []interface{}{"First", "Second"},
"Groups": []any{"First", "Second"},
}
tests := []struct {
testName string
idToken string
expectedResult map[string]interface{}
expectedResult map[string]any
expectedError error
}{
{
@ -66,7 +66,7 @@ func Test_getIdToken(t *testing.T) {
{
testName: "should return empty map if token does not exist",
idToken: "",
expectedResult: make(map[string]interface{}),
expectedResult: make(map[string]any),
expectedError: nil,
},
}
@ -75,7 +75,7 @@ func Test_getIdToken(t *testing.T) {
t.Run(tc.testName, func(t *testing.T) {
token := &oauth2.Token{}
if tc.idToken != "" {
token = token.WithExtra(map[string]interface{}{"id_token": tc.idToken})
token = token.WithExtra(map[string]any{"id_token": tc.idToken})
}
result, err := getIdToken(token)

View file

@ -45,7 +45,7 @@ func OAuthRoutes(code string, config *portainer.OAuthSettings) http.Handler {
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]interface{}{
json.NewEncoder(w).Encode(map[string]any{
"token_type": "Bearer",
"expires_in": 86400,
"access_token": AccessToken,
@ -67,7 +67,7 @@ func OAuthRoutes(code string, config *portainer.OAuthSettings) http.Handler {
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]interface{}{
json.NewEncoder(w).Encode(map[string]any{
"username": "test-oauth-user",
"groups": "testing",
})