ansible / django-ansible-base

Apache License 2.0
18 stars 45 forks source link

Introduce caching utility for lazy managed role references #422

Closed AlanCoding closed 5 months ago

AlanCoding commented 5 months ago

This is a baby-step in the direction I want to go for defining managed RoleDefinitions (or at least some of them in DAB), but for now, this removes the error seen in test logs:

INFO     ansible_base.authentication.utils.claims:claims.py:368 Reconciling user claims
ERROR    ansible_base.authentication.utils.claims:claims.py:275 Failed to reconcile user claims: RoleDefinition matching query does not exist.
Traceback (most recent call last):
  File "/home/alancoding/repos/awx/testing/django-ansible-base/ansible_base/authentication/utils/claims.py", line 273, in update_user_claims
    reconcile_user_class.reconcile_user_claims(user, authenticator_user)
  File "/home/alancoding/repos/awx/testing/django-ansible-base/ansible_base/authentication/utils/claims.py", line 371, in reconcile_user_claims
    org_member_rd = RoleDefinition.objects.get(name=cls.ORGANIZATION_MEMBER_ROLE_NAME)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alancoding/venvs/awx/lib64/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alancoding/venvs/awx/lib64/python3.12/site-packages/django/db/models/query.py", line 637, in get
    raise self.model.DoesNotExist(
ansible_base.rbac.models.RoleDefinition.DoesNotExist: RoleDefinition matching query does not exist.

I really don't want to require that each RoleDefinition exists to be able to use basic authentication. If you get a claim for a role definition that doesn't exist, yeah, that'll be a problem. But if there are no claims to a RoleDefinition that doesn't exist, I really don't want to do anything about that. The tests via test_app won't have these role definitions loaded, and I don't want to change that.

sonarcloud[bot] commented 5 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud