From f3582ee044bfd0f7c788d006e37612b69ad81beb Mon Sep 17 00:00:00 2001 From: ymao2 Date: Fri, 10 Nov 2023 14:36:36 +0000 Subject: [PATCH] Generate python package upgrade (#1223) * DPAT-0000 generate package upgrade * DPAT-0000 upgrade auth0 * DPAT-0000 try fix the failed tests * DPAT-0000 fix the error of missing param when getting auth0 token --- controlpanel/api/auth0.py | 26 ++++++++++--------- controlpanel/api/models/app.py | 2 +- .../commands/clear_up_auth0_resources.py | 2 +- .../management/commands/export_auth0_log.py | 2 +- controlpanel/frontend/views/app.py | 2 +- requirements.txt | 12 ++++----- tests/api/test_auth0.py | 4 +-- tests/api/views/test_customer.py | 2 +- tests/conftest.py | 2 +- 9 files changed, 28 insertions(+), 26 deletions(-) diff --git a/controlpanel/api/auth0.py b/controlpanel/api/auth0.py index 25c16bd1d..f744ed3ad 100644 --- a/controlpanel/api/auth0.py +++ b/controlpanel/api/auth0.py @@ -6,13 +6,13 @@ # Third-party import structlog import yaml -from auth0.v3 import authentication, exceptions -from auth0.v3.management import Auth0 -from auth0.v3.management.clients import Clients -from auth0.v3.management.connections import Connections -from auth0.v3.management.device_credentials import DeviceCredentials -from auth0.v3.management.rest import RestClient -from auth0.v3.management.users import Users +from auth0 import authentication, exceptions +from auth0.management import Auth0 +from auth0.management.clients import Clients +from auth0.management.connections import Connections +from auth0.management.device_credentials import DeviceCredentials +from auth0.rest import RestClient +from auth0.management.users import Users from django.conf import settings from jinja2 import Environment from rest_framework.exceptions import APIException @@ -27,7 +27,7 @@ # This is the maximum they'll allow for group/members API PER_PAGE_FOR_GROUP_MEMBERS = 25 -# The default value for timeout in auth0.v3.management is 5 seconds which will +# The default value for timeout in auth0.management is 5 seconds which will # get ReadTimeOut error quite easily on Auth0 dev tenant when Control panel # initialises the connection with it. In order to avoid this, a longer timeout # is defined below as the default value for this app. This value will be passed @@ -104,11 +104,13 @@ def _init_authorization_extension_apis(self): ) def _access_token(self, audience): - get_token = authentication.GetToken(self.domain) + get_token = authentication.GetToken( + self.domain, + client_id=self.client_id, + client_secret=self.client_secret + ) try: - token = get_token.client_credentials( - self.client_id, self.client_secret, audience - ) + token = get_token.client_credentials(audience) except exceptions.Auth0Error as error: error_detail = ( f"Access token error: {self.client_id}, {self.domain}, {error}" diff --git a/controlpanel/api/models/app.py b/controlpanel/api/models/app.py index e94041b28..099860d0a 100644 --- a/controlpanel/api/models/app.py +++ b/controlpanel/api/models/app.py @@ -3,7 +3,7 @@ import uuid # Third-party -from auth0.v3.exceptions import Auth0Error +from auth0.exceptions import Auth0Error from django.conf import settings from django.db import models from django_extensions.db.fields import AutoSlugField diff --git a/controlpanel/cli/management/commands/clear_up_auth0_resources.py b/controlpanel/cli/management/commands/clear_up_auth0_resources.py index 469a410d0..663d94fd7 100644 --- a/controlpanel/cli/management/commands/clear_up_auth0_resources.py +++ b/controlpanel/cli/management/commands/clear_up_auth0_resources.py @@ -3,7 +3,7 @@ from datetime import datetime # Third-party -from auth0.v3.exceptions import Auth0Error +from auth0.exceptions import Auth0Error from django.core.management.base import BaseCommand, CommandError from django.conf import settings diff --git a/controlpanel/cli/management/commands/export_auth0_log.py b/controlpanel/cli/management/commands/export_auth0_log.py index e459947bb..ca4e8c8ee 100644 --- a/controlpanel/cli/management/commands/export_auth0_log.py +++ b/controlpanel/cli/management/commands/export_auth0_log.py @@ -6,7 +6,7 @@ from time import time from controlpanel.api import auth0 -from auth0.v3.management.logs import Logs +from auth0.management.logs import Logs class Command(BaseCommand): diff --git a/controlpanel/frontend/views/app.py b/controlpanel/frontend/views/app.py index d4edceadc..821a0138d 100644 --- a/controlpanel/frontend/views/app.py +++ b/controlpanel/frontend/views/app.py @@ -17,7 +17,7 @@ from django.views.generic.edit import CreateView, DeleteView, FormMixin, UpdateView from django.views.generic.list import ListView from rules.contrib.views import PermissionRequiredMixin -from auth0.v3.management.rest import Auth0Error +from auth0.rest import Auth0Error # First-party/Local from controlpanel.api import auth0, cluster diff --git a/requirements.txt b/requirements.txt index ffbfe9ecf..fb09285da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,17 +1,17 @@ asgiref==3.6.0 -auth0-python==3.13.0 +auth0-python==4.5.0 beautifulsoup4==4.12.2 boto3==1.26.143 celery[sqs]==5.3.1 channels==4.0.0 channels-redis==4.0.0 daphne==4.0.0 -Django==4.2.1 +Django==4.2.7 django-crequest==2018.5.11 -django-extensions==3.2.1 +django-extensions==3.2.3 django-filter==22.1 django-prometheus==2.1.0 -django-redis==5.3.0 +django-redis==5.4.0 django-simple-history==3.3.0 django-structlog==2.2.0 djangorestframework==3.14.0 @@ -33,6 +33,6 @@ python-jose==3.3.0 pyyaml==6.0 rules==3.3 sentry-sdk==1.14.0 -slackclient==2.8.1 -urllib3==1.26.16 +slackclient==2.9.4 +urllib3==1.26.18 uvicorn[standard]==0.20.0 diff --git a/tests/api/test_auth0.py b/tests/api/test_auth0.py index 3d6695c70..a1788dd04 100644 --- a/tests/api/test_auth0.py +++ b/tests/api/test_auth0.py @@ -6,7 +6,7 @@ import mock import pytest from django.conf import settings -from auth0.v3 import exceptions +from auth0 import exceptions # First-party/Local from controlpanel.api import auth0 @@ -15,7 +15,7 @@ @pytest.fixture() def ExtendedAuth0(): with patch( - "auth0.v3.authentication.GetToken.client_credentials" + "auth0.authentication.GetToken.client_credentials" ) as client_credentials: client_credentials.return_value = {"access_token": "access_token_testing"} yield auth0.ExtendedAuth0() diff --git a/tests/api/views/test_customer.py b/tests/api/views/test_customer.py index 18041bdba..18450af9f 100644 --- a/tests/api/views/test_customer.py +++ b/tests/api/views/test_customer.py @@ -3,7 +3,7 @@ from unittest.mock import patch # Third-party -from auth0.v3.management.rest import Auth0Error +from auth0.rest import Auth0Error from bs4 import BeautifulSoup from model_mommy import mommy import pytest diff --git a/tests/conftest.py b/tests/conftest.py index d6452e085..bc3e1e5b7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,7 +17,7 @@ @pytest.fixture() def ExtendedAuth0(): with patch( - "auth0.v3.authentication.GetToken.client_credentials" + "auth0.authentication.GetToken.client_credentials" ) as client_credentials: client_credentials.return_value = {"access_token": "access_token_testing"} yield auth0.ExtendedAuth0()