Skip to content

Commit eb18ffe

Browse files
committed
make manager a seperate file to load it only if necessary
1 parent 1a15b1b commit eb18ffe

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

superset/stackable/patches/4.0.2/001-opa-integration.patch

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,26 @@
1-
diff --git a/superset/security/manager.py b/superset/security/manager.py
2-
index e5a32e97a..6971cf59a 100644
3-
--- a/superset/security/manager.py
4-
+++ b/superset/security/manager.py
5-
@@ -21,7 +21,7 @@ import logging
6-
import re
7-
import time
8-
from collections import defaultdict
9-
-from typing import Any, Callable, cast, NamedTuple, Optional, TYPE_CHECKING, Union
10-
+from typing import Any, Callable, cast, List, NamedTuple, Optional, Tuple, TYPE_CHECKING, Union
11-
12-
from flask import current_app, Flask, g, Request
13-
from flask_appbuilder import Model
14-
@@ -45,7 +45,9 @@ from flask_appbuilder.security.views import (
15-
from flask_appbuilder.widgets import ListWidget
16-
from flask_babel import lazy_gettext as _
17-
from flask_login import AnonymousUserMixin, LoginManager
1+
diff --git a/superset/security/OpaSupersetSecurityManager.py b/superset/security/OpaSupersetSecurityManager.py
2+
new file mode 100644
3+
index 0000000000..56fe61c917
4+
--- /dev/null
5+
+++ b/superset/security/OpaSupersetSecurityManager.py
6+
@@ -0,0 +1,71 @@
7+
+from typing import Any, Callable, cast, List, Optional, Tuple
188
+from http.client import HTTPException
19-
from jwt.api_jwt import _jwt_global_obj
209
+from opa_client.opa import OpaClient
21-
from sqlalchemy import and_, inspect, or_
22-
from sqlalchemy.engine.base import Connection
23-
from sqlalchemy.orm import eagerload
24-
@@ -2465,3 +2467,64 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
25-
return current_app.config["AUTH_ROLE_ADMIN"] in [
26-
role.name for role in self.get_user_roles()
27-
]
10+
+from superset.security import SupersetSecurityManager
11+
+from flask import current_app, g
2812
+
13+
+from flask_appbuilder.security.sqla.models import (
14+
+ Role,
15+
+ User,
16+
+)
2917
+
18+
+import logging
3019
+class OpaSupersetSecurityManager(SupersetSecurityManager):
3120
+ def get_user_roles(self, user: Optional[User] = None) -> List[Role]:
3221
+ if not user:
3322
+ user = g.user
34-
+
23+
+
3524
+ default_role = self.resolve_role(current_app.config.get("AUTH_USER_REGISTRATION_ROLE"))
3625
+
3726
+ opa_role_names = self.get_opa_user_roles(user.username)
@@ -47,7 +36,7 @@ index e5a32e97a..6971cf59a 100644
4736
+ self.update_user(user)
4837
+
4938
+ return user.roles
50-
+
39+
+
5140
+
5241
+ def get_opa_user_roles(self, username: str) -> set[str]:
5342
+ """
@@ -78,7 +67,7 @@ index e5a32e97a..6971cf59a 100644
7867
+ opa_endpoint = current_app.config.get('STACKABLE_OPA_ENDPOINT')
7968
+ [protocol, host, port] = opa_endpoint.split(":")
8069
+ return host.lstrip('/'), int(port.rstrip('/')), protocol == 'https'
81-
+
70+
+
8271
+
8372
+ def resolve_role(self, role_name: str) -> Role:
8473
+ role = self.find_role(role_name)

0 commit comments

Comments
 (0)