chore: replace interface with any
This commit is contained in:
committed by
Ralf Haferkamp
parent
8f26149743
commit
288e67cc39
@@ -7,10 +7,10 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/jellydator/ttlcache/v3"
|
||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
tenantpb "github.com/cs3org/go-cs3apis/cs3/identity/tenant/v1beta1"
|
||||
rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
"github.com/jellydator/ttlcache/v3"
|
||||
"github.com/opencloud-eu/opencloud/services/proxy/pkg/router"
|
||||
"github.com/opencloud-eu/opencloud/services/proxy/pkg/user/backend"
|
||||
"github.com/opencloud-eu/opencloud/services/proxy/pkg/userroles"
|
||||
@@ -91,7 +91,7 @@ type accountResolver struct {
|
||||
eventsPublisher events.Publisher
|
||||
}
|
||||
|
||||
func readStringClaim(path string, claims map[string]interface{}) (string, error) {
|
||||
func readStringClaim(path string, claims map[string]any) (string, error) {
|
||||
// happy path
|
||||
value, _ := claims[path].(string)
|
||||
if value != "" {
|
||||
@@ -104,10 +104,10 @@ func readStringClaim(path string, claims map[string]interface{}) (string, error)
|
||||
lastSegment := len(segments) - 1
|
||||
for i := range segments {
|
||||
if i < lastSegment {
|
||||
if castedClaims, ok := subclaims[segments[i]].(map[string]interface{}); ok {
|
||||
if castedClaims, ok := subclaims[segments[i]].(map[string]any); ok {
|
||||
subclaims = castedClaims
|
||||
} else if castedClaims, ok := subclaims[segments[i]].(map[interface{}]interface{}); ok {
|
||||
subclaims = make(map[string]interface{}, len(castedClaims))
|
||||
} else if castedClaims, ok := subclaims[segments[i]].(map[any]any); ok {
|
||||
subclaims = make(map[string]any, len(castedClaims))
|
||||
for k, v := range castedClaims {
|
||||
if s, ok := k.(string); ok {
|
||||
subclaims[s] = v
|
||||
@@ -281,7 +281,7 @@ func (m accountResolver) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
m.next.ServeHTTP(w, req)
|
||||
}
|
||||
|
||||
func (m accountResolver) verifyTenantClaim(ctx context.Context, userTenantID string, claims map[string]interface{}) error {
|
||||
func (m accountResolver) verifyTenantClaim(ctx context.Context, userTenantID string, claims map[string]any) error {
|
||||
claimTenantID, err := readStringClaim(m.tenantOIDCClaim, claims)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not read tenant claim: %w", err)
|
||||
|
||||
@@ -28,13 +28,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
testIdP = "https://idx.example.com"
|
||||
testTenantA = "tenant-a"
|
||||
testTenantB = "tenant-b"
|
||||
testJWTSecret = "change-me"
|
||||
testSvcAccountID = "svc-account-id"
|
||||
testSvcAccountSecret = "svc-account-secret"
|
||||
testSvcAccountToken = "svc-account-token"
|
||||
testIdP = "https://idx.example.com"
|
||||
testTenantA = "tenant-a"
|
||||
testTenantB = "tenant-b"
|
||||
testJWTSecret = "change-me"
|
||||
testSvcAccountID = "svc-account-id"
|
||||
testSvcAccountSecret = "svc-account-secret"
|
||||
testSvcAccountToken = "svc-account-token"
|
||||
)
|
||||
|
||||
func TestTokenIsAddedWithMailClaim(t *testing.T) {
|
||||
@@ -43,7 +43,7 @@ func TestTokenIsAddedWithMailClaim(t *testing.T) {
|
||||
Mail: "foo@example.com",
|
||||
}, nil, oidc.Email, "mail", false)
|
||||
|
||||
req, rw := mockRequest(map[string]interface{}{
|
||||
req, rw := mockRequest(map[string]any{
|
||||
oidc.Iss: testIdP,
|
||||
oidc.Email: "foo@example.com",
|
||||
})
|
||||
@@ -61,7 +61,7 @@ func TestTokenIsAddedWithUsernameClaim(t *testing.T) {
|
||||
Mail: "foo@example.com",
|
||||
}, nil, oidc.PreferredUsername, "username", false)
|
||||
|
||||
req, rw := mockRequest(map[string]interface{}{
|
||||
req, rw := mockRequest(map[string]any{
|
||||
oidc.Iss: testIdP,
|
||||
oidc.PreferredUsername: "foo",
|
||||
})
|
||||
@@ -81,9 +81,9 @@ func TestTokenIsAddedWithDotUsernamePathClaim(t *testing.T) {
|
||||
}, nil, "li.un", "username", false)
|
||||
|
||||
// This is how lico adds the username to the access token
|
||||
req, rw := mockRequest(map[string]interface{}{
|
||||
req, rw := mockRequest(map[string]any{
|
||||
oidc.Iss: testIdP,
|
||||
"li": map[string]interface{}{
|
||||
"li": map[string]any{
|
||||
"un": "foo",
|
||||
},
|
||||
})
|
||||
@@ -122,7 +122,7 @@ func TestTokenIsAddedWithDottedUsernameClaim(t *testing.T) {
|
||||
Mail: "foo@example.com",
|
||||
}, nil, tc.oidcClaim, "username", false)
|
||||
|
||||
req, rw := mockRequest(map[string]interface{}{
|
||||
req, rw := mockRequest(map[string]any{
|
||||
oidc.Iss: testIdP,
|
||||
"li.un": "foo",
|
||||
})
|
||||
@@ -149,7 +149,7 @@ func TestNSkipOnNoClaims(t *testing.T) {
|
||||
|
||||
func TestUnauthorizedOnUserNotFound(t *testing.T) {
|
||||
sut := newMockAccountResolver(nil, backend.ErrAccountNotFound, oidc.PreferredUsername, "username", false)
|
||||
req, rw := mockRequest(map[string]interface{}{
|
||||
req, rw := mockRequest(map[string]any{
|
||||
oidc.Iss: testIdP,
|
||||
oidc.PreferredUsername: "foo",
|
||||
})
|
||||
@@ -163,7 +163,7 @@ func TestUnauthorizedOnUserNotFound(t *testing.T) {
|
||||
|
||||
func TestUnauthorizedOnUserDisabled(t *testing.T) {
|
||||
sut := newMockAccountResolver(nil, backend.ErrAccountDisabled, oidc.PreferredUsername, "username", false)
|
||||
req, rw := mockRequest(map[string]interface{}{
|
||||
req, rw := mockRequest(map[string]any{
|
||||
oidc.Iss: testIdP,
|
||||
oidc.PreferredUsername: "foo",
|
||||
})
|
||||
@@ -177,7 +177,7 @@ func TestUnauthorizedOnUserDisabled(t *testing.T) {
|
||||
|
||||
func TestInternalServerErrorOnMissingMailAndUsername(t *testing.T) {
|
||||
sut := newMockAccountResolver(nil, backend.ErrAccountNotFound, oidc.Email, "mail", false)
|
||||
req, rw := mockRequest(map[string]interface{}{
|
||||
req, rw := mockRequest(map[string]any{
|
||||
oidc.Iss: testIdP,
|
||||
})
|
||||
|
||||
@@ -262,7 +262,7 @@ func TestTenantClaimValidation(t *testing.T) {
|
||||
Username: "foo",
|
||||
}
|
||||
|
||||
tokenManager, _ := jwt.New(map[string]interface{}{"secret": testJWTSecret, "expires": int64(60)})
|
||||
tokenManager, _ := jwt.New(map[string]any{"secret": testJWTSecret, "expires": int64(60)})
|
||||
s, _ := scope.AddOwnerScope(nil)
|
||||
token, _ := tokenManager.MintToken(context.Background(), user, s)
|
||||
|
||||
@@ -281,7 +281,7 @@ func TestTenantClaimValidation(t *testing.T) {
|
||||
MultiTenantEnabled(true),
|
||||
)(mockHandler{})
|
||||
|
||||
req, rw := mockRequest(map[string]interface{}{
|
||||
req, rw := mockRequest(map[string]any{
|
||||
oidc.Iss: testIdP,
|
||||
oidc.PreferredUsername: "foo",
|
||||
"tenant_id": tc.requestTenant,
|
||||
@@ -300,7 +300,7 @@ func TestTenantClaimValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
func newMockAccountResolver(userBackendResult *userv1beta1.User, userBackendErr error, oidcclaim, cs3claim string, multiTenant bool) http.Handler {
|
||||
tokenManager, _ := jwt.New(map[string]interface{}{
|
||||
tokenManager, _ := jwt.New(map[string]any{
|
||||
"secret": testJWTSecret,
|
||||
"expires": int64(60),
|
||||
})
|
||||
@@ -330,7 +330,7 @@ func newMockAccountResolver(userBackendResult *userv1beta1.User, userBackendErr
|
||||
)(mockHandler{})
|
||||
}
|
||||
|
||||
func mockRequest(claims map[string]interface{}) (*http.Request, *httptest.ResponseRecorder) {
|
||||
func mockRequest(claims map[string]any) (*http.Request, *httptest.ResponseRecorder) {
|
||||
if claims == nil {
|
||||
return httptest.NewRequest("GET", "http://example.com/foo", nil), httptest.NewRecorder()
|
||||
}
|
||||
@@ -362,7 +362,7 @@ func TestTenantIDMapping(t *testing.T) {
|
||||
Username: "foo",
|
||||
}
|
||||
|
||||
tokenManager, _ := jwt.New(map[string]interface{}{"secret": testJWTSecret, "expires": int64(60)})
|
||||
tokenManager, _ := jwt.New(map[string]any{"secret": testJWTSecret, "expires": int64(60)})
|
||||
s, _ := scope.AddOwnerScope(nil)
|
||||
token, _ := tokenManager.MintToken(context.Background(), user, s)
|
||||
|
||||
@@ -449,7 +449,7 @@ func TestTenantIDMapping(t *testing.T) {
|
||||
Value: externalTenantID,
|
||||
}).Return(tc.tenantResponse, nil)
|
||||
|
||||
req, rw := mockRequest(map[string]interface{}{
|
||||
req, rw := mockRequest(map[string]any{
|
||||
oidc.Iss: testIdP,
|
||||
oidc.PreferredUsername: "foo",
|
||||
"tenant_id": externalTenantID,
|
||||
|
||||
@@ -126,7 +126,7 @@ var _ = Describe("Authenticating requests", Label("Authentication"), func() {
|
||||
EnableBasicAuth(true),
|
||||
)
|
||||
testHandler := handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
Expect(oidc.FromContext(r.Context())).To(Equal(map[string]interface{}{
|
||||
Expect(oidc.FromContext(r.Context())).To(Equal(map[string]any{
|
||||
"sid": "a-session-id",
|
||||
"exp": int64(1147483647),
|
||||
}))
|
||||
@@ -144,7 +144,7 @@ var _ = Describe("Authenticating requests", Label("Authentication"), func() {
|
||||
EnableBasicAuth(true),
|
||||
)
|
||||
testHandler := handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
Expect(oidc.FromContext(r.Context())).To(Equal(map[string]interface{}{
|
||||
Expect(oidc.FromContext(r.Context())).To(Equal(map[string]any{
|
||||
"email": "testuser@example.com",
|
||||
"openclouduuid": "OpaqueId",
|
||||
"iss": "IdpId",
|
||||
|
||||
@@ -41,7 +41,7 @@ func (m BasicAuthenticator) Authenticate(r *http.Request) (*http.Request, bool)
|
||||
}
|
||||
|
||||
// fake oidc claims
|
||||
claims := map[string]interface{}{
|
||||
claims := map[string]any{
|
||||
oidc.Iss: user.Id.Idp,
|
||||
oidc.PreferredUsername: user.Username,
|
||||
oidc.Email: user.Mail,
|
||||
|
||||
@@ -54,8 +54,8 @@ type OIDCAuthenticator struct {
|
||||
TimeFunc func() time.Time
|
||||
}
|
||||
|
||||
func (m *OIDCAuthenticator) getClaims(token string, req *http.Request) (map[string]interface{}, bool, error) {
|
||||
var claims map[string]interface{}
|
||||
func (m *OIDCAuthenticator) getClaims(token string, req *http.Request) (map[string]any, bool, error) {
|
||||
var claims map[string]any
|
||||
|
||||
// use a 64 bytes long hash to have 256-bit collision resistance.
|
||||
hash := make([]byte, 64)
|
||||
@@ -159,7 +159,7 @@ func (m OIDCAuthenticator) extractExpiration(aClaims oidc.RegClaimsWithSID) time
|
||||
return defaultExpiration
|
||||
}
|
||||
|
||||
func verifyExpiresAt(claims map[string]interface{}, cmp time.Time) bool {
|
||||
func verifyExpiresAt(claims map[string]any, cmp time.Time) bool {
|
||||
var expiry time.Time
|
||||
switch v := claims["exp"].(type) {
|
||||
case nil:
|
||||
|
||||
@@ -35,7 +35,7 @@ type (
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
// The structure of this object is service-specific
|
||||
Innererror map[string]interface{} `json:"innererror,omitempty"`
|
||||
Innererror map[string]any `json:"innererror,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
@@ -154,7 +154,7 @@ func RenderError(w http.ResponseWriter, r *http.Request, evaluateReq *pService.E
|
||||
filename = path.Base(evaluateReq.Environment.GetRequest().GetPath())
|
||||
}
|
||||
|
||||
innererror := map[string]interface{}{
|
||||
innererror := map[string]any{
|
||||
"date": time.Now().UTC().Format(time.RFC3339),
|
||||
}
|
||||
|
||||
|
||||
@@ -28,12 +28,12 @@ func loadCSPConfig(presetYamlContent, customYamlContent []byte) (*config.CSP, er
|
||||
gofig.WithOptions(gofig.ParseEnv)
|
||||
gofig.AddDriver(yaml.Driver)
|
||||
|
||||
presetMap := map[string]interface{}{}
|
||||
presetMap := map[string]any{}
|
||||
err := yamlv3.Unmarshal(presetYamlContent, &presetMap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
customMap := map[string]interface{}{}
|
||||
customMap := map[string]any{}
|
||||
err = yamlv3.Unmarshal(customYamlContent, &customMap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -63,9 +63,9 @@ func loadCSPConfig(presetYamlContent, customYamlContent []byte) (*config.CSP, er
|
||||
// - nested maps are merged recursively
|
||||
// - slices are concatenated, preserving order and avoiding duplicates
|
||||
// - scalar or type-mismatched values from map2 overwrite map1
|
||||
func deepMerge(map1, map2 map[string]interface{}) map[string]interface{} {
|
||||
func deepMerge(map1, map2 map[string]any) map[string]any {
|
||||
if map1 == nil {
|
||||
out := make(map[string]interface{}, len(map2))
|
||||
out := make(map[string]any, len(map2))
|
||||
for k, v := range map2 {
|
||||
out[k] = v
|
||||
}
|
||||
@@ -75,17 +75,17 @@ func deepMerge(map1, map2 map[string]interface{}) map[string]interface{} {
|
||||
for k, v2 := range map2 {
|
||||
if v1, ok := map1[k]; ok {
|
||||
// both maps -> recurse
|
||||
if m1, ok1 := v1.(map[string]interface{}); ok1 {
|
||||
if m2, ok2 := v2.(map[string]interface{}); ok2 {
|
||||
if m1, ok1 := v1.(map[string]any); ok1 {
|
||||
if m2, ok2 := v2.(map[string]any); ok2 {
|
||||
map1[k] = deepMerge(m1, m2)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// both slices -> merge unique
|
||||
if s1, ok1 := v1.([]interface{}); ok1 {
|
||||
if s2, ok2 := v2.([]interface{}); ok2 {
|
||||
merged := append([]interface{}{}, s1...)
|
||||
if s1, ok1 := v1.([]any); ok1 {
|
||||
if s2, ok2 := v2.([]any); ok2 {
|
||||
merged := append([]any{}, s1...)
|
||||
for _, item := range s2 {
|
||||
if !sliceContains(merged, item) {
|
||||
merged = append(merged, item)
|
||||
@@ -112,7 +112,7 @@ func deepMerge(map1, map2 map[string]interface{}) map[string]interface{} {
|
||||
return map1
|
||||
}
|
||||
|
||||
func sliceContains(slice []interface{}, val interface{}) bool {
|
||||
func sliceContains(slice []any, val any) bool {
|
||||
for _, v := range slice {
|
||||
if reflect.DeepEqual(v, val) {
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user