# See the License for the specific language governing permissions and
# limitations under the License.
+rm -f nosetests.xml
tox # flake8 unittest
schema_edit = roles_edit_schema
multiproject = False
- def __init__(self, db, fs, msg, auth, ops):
+ def __init__(self, db, fs, msg, auth):
BaseTopic.__init__(self, db, fs, msg, auth)
# self.auth = auth
- self.operations = ops
+ self.operations = auth.role_permissions
# self.topic = "roles_operations" if isinstance(auth, AuthconnKeystone) else "roles"
@staticmethod
.format(config["message"]["driver"]))
if not self.backend:
if config["authentication"]["backend"] == "keystone":
- self.backend = AuthconnKeystone(self.config["authentication"], self.db)
+ self.backend = AuthconnKeystone(self.config["authentication"], self.db, self.role_permissions)
elif config["authentication"]["backend"] == "internal":
- self.backend = AuthconnInternal(self.config["authentication"], self.db)
+ self.backend = AuthconnInternal(self.config["authentication"], self.db, self.role_permissions)
self._internal_tokens_prune()
else:
raise AuthException("Unknown authentication backend: {}"
Each Auth backend connector plugin must be a subclass of
Authconn class.
"""
- def __init__(self, config, db):
+ def __init__(self, config, db, role_permissions):
"""
Constructor of the Authconn class.
-
- Note: each subclass
-
:param config: configuration dictionary containing all the
necessary configuration parameters.
+ :param db: internal database classs
+ :param role_permissions: read only role permission list
"""
self.config = config
+ self.role_permissions = role_permissions
def authenticate(self, credentials, token_info=None):
"""
token_time_window = 2 # seconds
token_delay = 1 # seconds to wait upon second request within time window
- def __init__(self, config, db):
- Authconn.__init__(self, config, db)
+ def __init__(self, config, db, role_permissions):
+ Authconn.__init__(self, config, db, role_permissions)
self.logger = logging.getLogger("nbi.authenticator.internal")
self.db = db
class AuthconnKeystone(Authconn):
- def __init__(self, config, db):
- Authconn.__init__(self, config, db)
+ def __init__(self, config, db, role_permissions):
+ Authconn.__init__(self, config, db, role_permissions)
self.logger = logging.getLogger("nbi.authenticator.keystone")
self.domains_id2name = {}
# limitations under the License.
import logging
-import yaml
+# import yaml
from osm_common import dbmongo, dbmemory, fslocal, fsmongo, msglocal, msgkafka, version as common_version
from osm_common.dbbase import DbException
from osm_common.fsbase import FsException
from osm_nbi.instance_topics import NsrTopic, VnfrTopic, NsLcmOpTopic, NsiTopic, NsiLcmOpTopic
from osm_nbi.pmjobs_topics import PmJobsTopic
from base64 import b64encode
-from os import urandom, path
+from os import urandom # , path
from threading import Lock
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
self.msg = None
self.authconn = None
self.config = None
- self.operations = None
+ # self.operations = None
self.logger = logging.getLogger("nbi.engine")
self.map_topic = {}
self.write_lock = None
config["message"]["driver"]))
if not self.authconn:
if config["authentication"]["backend"] == "keystone":
- self.authconn = AuthconnKeystone(config["authentication"], self.db)
+ self.authconn = AuthconnKeystone(config["authentication"], self.db,
+ self.authenticator.role_permissions)
else:
- self.authconn = AuthconnInternal(config["authentication"], self.db)
- if not self.operations:
- if "resources_to_operations" in config["rbac"]:
- resources_to_operations_file = config["rbac"]["resources_to_operations"]
- else:
- possible_paths = (
- __file__[:__file__.rfind("engine.py")] + "resources_to_operations.yml",
- "./resources_to_operations.yml"
- )
- for config_file in possible_paths:
- if path.isfile(config_file):
- resources_to_operations_file = config_file
- break
- if not resources_to_operations_file:
- raise EngineException("Invalid permission configuration: resources_to_operations file missing")
-
- with open(resources_to_operations_file, 'r') as f:
- resources_to_operations = yaml.load(f, Loader=yaml.Loader)
-
- self.operations = []
-
- for _, value in resources_to_operations["resources_to_operations"].items():
- if value not in self.operations:
- self.operations += [value]
+ self.authconn = AuthconnInternal(config["authentication"], self.db,
+ self.authenticator.role_permissions)
+ # if not self.operations:
+ # if "resources_to_operations" in config["rbac"]:
+ # resources_to_operations_file = config["rbac"]["resources_to_operations"]
+ # else:
+ # possible_paths = (
+ # __file__[:__file__.rfind("engine.py")] + "resources_to_operations.yml",
+ # "./resources_to_operations.yml"
+ # )
+ # for config_file in possible_paths:
+ # if path.isfile(config_file):
+ # resources_to_operations_file = config_file
+ # break
+ # if not resources_to_operations_file:
+ # raise EngineException("Invalid permission configuration:"
+ # "resources_to_operations file missing")
+ #
+ # with open(resources_to_operations_file, 'r') as f:
+ # resources_to_operations = yaml.load(f, Loader=yaml.Loader)
+ #
+ # self.operations = []
+ #
+ # for _, value in resources_to_operations["resources_to_operations"].items():
+ # if value not in self.operations:
+ # self.operations += [value]
self.write_lock = Lock()
# create one class per topic
for topic, topic_class in self.map_from_topic_to_class.items():
# if self.auth and topic_class in (UserTopicAuth, ProjectTopicAuth):
# self.map_topic[topic] = topic_class(self.db, self.fs, self.msg, self.auth)
- if self.authconn and topic_class == RoleTopicAuth:
- self.map_topic[topic] = topic_class(self.db, self.fs, self.msg, self.authconn,
- self.operations)
- else:
- self.map_topic[topic] = topic_class(self.db, self.fs, self.msg, self.authconn)
+ self.map_topic[topic] = topic_class(self.db, self.fs, self.msg, self.authconn)
self.map_topic["pm_jobs"] = PmJobsTopic(self.db, config["prometheus"].get("host"),
config["prometheus"].get("port"))
self.db = Mock(dbbase.DbBase())
self.fs = Mock(fsbase.FsBase())
self.msg = Mock(msgbase.MsgBase())
- self.auth = Mock(authconn.Authconn(None, None))
+ self.auth = Mock(authconn.Authconn(None, None, None))
self.topic = ProjectTopicAuth(self.db, self.fs, self.msg, self.auth)
self.fake_session = {"username": self.test_name, "project_id": (test_pid,), "method": None,
"admin": True, "force": False, "public": False, "allow_show_user_project_role": True}
self.db = Mock(dbbase.DbBase())
self.fs = Mock(fsbase.FsBase())
self.msg = Mock(msgbase.MsgBase())
- self.auth = Mock(authconn.Authconn(None, None))
- self.topic = RoleTopicAuth(self.db, self.fs, self.msg, self.auth, self.test_operations)
+ self.auth = Mock(authconn.Authconn(None, None, None))
+ self.auth.role_permissions = self.test_operations
+ self.topic = RoleTopicAuth(self.db, self.fs, self.msg, self.auth)
self.fake_session = {"username": test_name, "project_id": (test_pid,), "method": None,
"admin": True, "force": False, "public": False, "allow_show_user_project_role": True}
self.db = Mock(dbbase.DbBase())
self.fs = Mock(fsbase.FsBase())
self.msg = Mock(msgbase.MsgBase())
- self.auth = Mock(authconn.Authconn(None, None))
+ self.auth = Mock(authconn.Authconn(None, None, None))
self.topic = UserTopicAuth(self.db, self.fs, self.msg, self.auth)
self.fake_session = {"username": test_name, "project_id": (test_pid,), "method": None,
"admin": True, "force": False, "public": False, "allow_show_user_project_role": True}
self.db = Mock(dbbase.DbBase())
self.fs = Mock(fsbase.FsBase())
self.msg = Mock(msgbase.MsgBase())
- self.auth = Mock(authconn.Authconn(None, None))
+ self.auth = Mock(authconn.Authconn(None, None, None))
self.topic = CommonVimWimSdn(self.db, self.fs, self.msg, self.auth)
# Use WIM schemas for testing because they are the simplest
self.topic.topic = "wims"
self.db = Mock(dbbase.DbBase())
self.fs = Mock(fsbase.FsBase())
self.msg = Mock(msgbase.MsgBase())
- self.auth = Mock(authconn.Authconn(None, None))
+ self.auth = Mock(authconn.Authconn(None, None, None))
self.topic = VnfdTopic(self.db, self.fs, self.msg, self.auth)
def test_new_vnfd(self):
self.db = Mock(dbbase.DbBase())
self.fs = Mock(fsbase.FsBase())
self.msg = Mock(msgbase.MsgBase())
- self.auth = Mock(authconn.Authconn(None, None))
+ self.auth = Mock(authconn.Authconn(None, None, None))
self.topic = NsdTopic(self.db, self.fs, self.msg, self.auth)
def test_new_nsd(self):