From b8a3fc2ee98bc47cf2e91dedf1e7d9e55fc6f45a Mon Sep 17 00:00:00 2001 From: verdan Date: Tue, 18 Aug 2020 00:28:48 +0200 Subject: [PATCH] Refactoring Signed-off-by: verdan --- metadata_service/proxy/atlas_proxy.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/metadata_service/proxy/atlas_proxy.py b/metadata_service/proxy/atlas_proxy.py index c3032951..51f89392 100644 --- a/metadata_service/proxy/atlas_proxy.py +++ b/metadata_service/proxy/atlas_proxy.py @@ -58,7 +58,8 @@ class AtlasProxy(BaseProxy): ATTRS_KEY = 'attributes' REL_ATTRS_KEY = 'relationshipAttributes' ENTITY_URI_KEY = 'entityUri' - user_detail_method = app.config.get('USER_DETAIL_METHOD', lambda x: None) + # Variables 'x' in lambda function represents the 'self'. + user_detail_method = app.config.get('USER_DETAIL_METHOD') or (lambda x, y: None) _CACHE = CacheManager(**parse_cache_config_options({'cache.regions': 'atlas_proxy', 'cache.atlas_proxy.type': 'memory', 'cache.atlas_proxy.expire': _ATLAS_PROXY_CACHE_EXPIRY_SEC})) @@ -386,6 +387,7 @@ def _get_owners(self, data_owner, fallback_owner): for owner in active_owners: owner_qn = owner['displayText'] + # noinspection PyArgumentList owner_data = self.user_detail_method(owner_qn) or { 'email': owner_qn, 'user_id': owner_qn @@ -489,6 +491,10 @@ def add_owner(self, *, table_uri: str, owner: str) -> None: :param owner: Email address of the owner :return: None, as it simply adds the owner. """ + # noinspection PyArgumentList + if not self.user_detail_method(owner) or owner: + raise NotFoundException(f'User "{owner}" does not exist.') + user_dict = { "entity": { "typeName": "User", @@ -816,6 +822,7 @@ def _get_readers(self, qualified_name: str, top: Optional[int] = 15) -> List[Rea for read_entity in read_entities: reader_qn = read_entity.relationshipAttributes['user']['displayText'] + # noinspection PyArgumentList reader_details = self.user_detail_method(reader_qn) or { 'email': reader_qn, 'user_id': reader_qn