From 3328674585a70f4c2edf3ae6e030de7690eab91a Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 3 Oct 2023 09:03:57 -0400 Subject: [PATCH] Lint fixes and more social logging. No-Issue Signed-off-by: James Tanner --- galaxy_ng/app/api/v1/viewsets/sync.py | 1 - galaxy_ng/social/__init__.py | 75 ++++++++++++++----- .../tests/integration/api/test_community.py | 6 +- .../test_community_namespace_rbac.py | 1 + 4 files changed, 61 insertions(+), 22 deletions(-) diff --git a/galaxy_ng/app/api/v1/viewsets/sync.py b/galaxy_ng/app/api/v1/viewsets/sync.py index ca3962bb52..9488c92122 100644 --- a/galaxy_ng/app/api/v1/viewsets/sync.py +++ b/galaxy_ng/app/api/v1/viewsets/sync.py @@ -23,7 +23,6 @@ ) - class LegacyRolesSyncViewSet(viewsets.GenericViewSet, mixins.CreateModelMixin, LegacyTasksMixin): """Load roles from an upstream v1 source.""" diff --git a/galaxy_ng/social/__init__.py b/galaxy_ng/social/__init__.py index 548feb2f09..30798d5aee 100644 --- a/galaxy_ng/social/__init__.py +++ b/galaxy_ng/social/__init__.py @@ -63,21 +63,26 @@ def do_auth(self, access_token, *args, **kwargs): v3_namespace, v3_namespace_created = \ self.handle_v3_namespace(auth_response, email, login, gid) - print('-' * 100) - print(f'{login} v3 namespace: {v3_namespace}') - print('-' * 100) + logger.info( + f'v3 namespace {v3_namespace} created:{v3_namespace_created}' + + f' for github login {login}' + ) # create a legacynamespace and bind to the v3 namespace? if v3_namespace: legacy_namespace, legacy_namespace_created = \ self._ensure_legacynamespace(login, v3_namespace) + logger.info( + f'legacy namespace {legacy_namespace} created:{legacy_namespace_created}' + + f' for github login {login}' + ) return auth_response def handle_v3_namespace(self, session_user, session_email, session_login, github_id): - logger.debug( - f'HANDLING V3 NAMESPACE session_user:{session_user}' + logger.info( + f'handle_v3_namespace(1): session_user:{session_user}' + f' session_email:{session_email} session_login:{session_login}' ) @@ -86,19 +91,23 @@ def handle_v3_namespace(self, session_user, session_email, session_login, github # first make the namespace name ... namespace_name = self.transform_namespace_name(session_login) - logger.debug(f'TRANSFORMED NAME: {namespace_name}') - print(f'TRANSFORMED NAME: {namespace_name}') + logger.info( + f'handle_v3_namespace(2): session_login:{session_login}' + + f' transformed_name:{namespace_name}' + ) if not self.validate_namespace_name(namespace_name): - logger.debug(f'DID NOT VALIDATE NAMESPACE NAME: {namespace_name}') - print(f'DID NOT VALIDATE NAMESPACE NAME: {namespace_name}') + logger.info( + f'handle_v3_namespace(3): session_login:{session_login}' + + f' transformed_name:{namespace_name} validated:False') return False, False # does the namespace already exist? found_namespace = Namespace.objects.filter(name=namespace_name).first() - - logger.debug(f'FOUND NAMESPACE: {found_namespace}') - print(f'FOUND NAMESPACE: {found_namespace}') + logger.info( + f'handle_v3_namespace(4): session_login:{session_login}' + + f' transformed_name:{namespace_name} found:{found_namespace}' + ) # is it owned by this userid? if found_namespace: @@ -107,39 +116,65 @@ def handle_v3_namespace(self, session_user, session_email, session_login, github logger.debug(f'FOUND EXISTING OWNERS: {owners}') if session_user in owners: + logger.info( + f'handle_v3_namespace(5): session_login:{session_login}' + f' is owner of {found_namespace}' + ) return found_namespace, False + else: + logger.info( + f'handle_v3_namespace(6): session_login:{session_login}' + + f' is NOT owner of {found_namespace}' + ) # FIXME - make one from the transformed name? if not found_namespace: namespace, namespace_created = self._ensure_namespace(namespace_name, session_user) + logger.info( + f'handle_v3_namespace(7): session_login:{session_login}' + + f' created:{namespace_created} namespace:{namespace}' + ) return namespace, namespace_created # short circuit if the user does own at least one namespace ... owned_namespaces = rbac.get_owned_v3_namespaces(session_user) - logger.debug(f'FOUND USER OWNED NAMESPACES: {owned_namespaces}') - print(f'FOUND USER OWNED NAMESPACES: {owned_namespaces}') + logger.info( + f'handle_v3_namespace(8): session_login:{session_login} owns {owned_namespaces}' + ) + if owned_namespaces: # does one resemble the desired namespace name? owned_namespaces = sorted(owned_namespaces) for ns in owned_namespaces: if ns.name.startswith(namespace_name): - logger.debug(f'MATCHED NS OWNED BY {session_user}: {ns} {ns.name}') + logger.info( + f'handle_v3_namespace(9): session_login:{session_login} returning {ns}' + ) return ns, False + + logger.info( + f'handle_v3_namespace(10): session_login:{session_login}' + + f' no candidates among {owned_namespaces}' + ) return None, False # should always have a namespace ... if found_namespace: - logger.debug( - f'GENERATING A NEW NAMESPACE NAME SINCE USER DOES NOT OWN {found_namespace}' - ) namespace_name = self.generate_available_namespace_name(session_login, github_id) - logger.debug(f'FINAL NAMESPACE NAME {namespace_name}') + logger.info( + f'handle_v3_namespace(11): session_login:{session_login}' + + f' new namespace name {namespace_name}' + ) # create a v3 namespace? namespace, namespace_created = self._ensure_namespace(namespace_name, session_user) + logger.info( + f'handle_v3_namespace(12): session_login:{session_login}' + + f' namespace:{namespace} created:{namespace_created}' + ) owned = rbac.get_owned_v3_namespaces(session_user) - logger.debug(f'NS OWNED BY {session_user}: {owned}') + logger.info(f'handle_v3_namespace(13): session_login:{session_login} owns {owned}') return namespace, namespace_created diff --git a/galaxy_ng/tests/integration/api/test_community.py b/galaxy_ng/tests/integration/api/test_community.py index e9431e2392..c0f35c3aaa 100644 --- a/galaxy_ng/tests/integration/api/test_community.py +++ b/galaxy_ng/tests/integration/api/test_community.py @@ -166,7 +166,11 @@ def test_me_social_with_v1_synced_user(ansible_config): ) # v1 sync the user's roles and namespace ... - pargs = json.dumps({"github_user": username, "limit": 1, "baseurl": "https://old-galaxy.ansible.com"}).encode('utf-8') + pargs = json.dumps({ + "github_user": username, + "limit": 1, + "baseurl": "https://old-galaxy.ansible.com" + }).encode('utf-8') resp = admin_client('/api/v1/sync/', method='POST', args=pargs) wait_for_v1_task(resp=resp, api_client=admin_client) diff --git a/galaxy_ng/tests/integration/community/test_community_namespace_rbac.py b/galaxy_ng/tests/integration/community/test_community_namespace_rbac.py index 2000013a44..966b36020e 100644 --- a/galaxy_ng/tests/integration/community/test_community_namespace_rbac.py +++ b/galaxy_ng/tests/integration/community/test_community_namespace_rbac.py @@ -500,6 +500,7 @@ def test_rbac_utils_get_owned_v3_namespaces(ansible_config): def test_community_tools_urls(ansible_config): pass + @pytest.mark.deployment_community def test_social_auth_no_duplicated_namespaces(ansible_config):