From e3c466dcabff6e39365be02314295bca52d8fdca Mon Sep 17 00:00:00 2001 From: Erwan Rouchet <rouchet@teklia.com> Date: Tue, 24 Jan 2023 18:20:43 +0100 Subject: [PATCH] Fix sorting of cryptography imports --- .isort.cfg | 2 +- arkindex/ponos/keys.py | 7 +------ arkindex/ponos/models.py | 2 +- arkindex/ponos/serializer_fields.py | 6 +----- arkindex/ponos/tests/test_api.py | 10 +++++----- arkindex/ponos/tests/test_keys.py | 2 +- arkindex/project/tools.py | 6 +++--- 7 files changed, 13 insertions(+), 22 deletions(-) diff --git a/.isort.cfg b/.isort.cfg index 69e050ee6e..3fd5b5e994 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -8,4 +8,4 @@ line_length = 120 default_section=FIRSTPARTY known_first_party = transkribus -known_third_party = SolrClient,bleach,boto3,botocore,corsheaders,django,django_admin_hstore_widget,django_rq,drf_spectacular,enumfields,gitlab,psycopg2,requests,responses,rest_framework,rq,setuptools,sqlparse,teklia_toolbox,tenacity,tripoli,yaml +known_third_party = SolrClient,bleach,boto3,botocore,cryptography,corsheaders,django,django_admin_hstore_widget,django_rq,drf_spectacular,enumfields,gitlab,psycopg2,requests,responses,rest_framework,rq,setuptools,sqlparse,teklia_toolbox,tenacity,tripoli,yaml diff --git a/arkindex/ponos/keys.py b/arkindex/ponos/keys.py index 31d77be0cd..137da04232 100644 --- a/arkindex/ponos/keys.py +++ b/arkindex/ponos/keys.py @@ -7,12 +7,7 @@ from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives.hashes import SHA256 from cryptography.hazmat.primitives.kdf.hkdf import HKDF -from cryptography.hazmat.primitives.serialization import ( - Encoding, - NoEncryption, - PrivateFormat, - load_pem_private_key, -) +from cryptography.hazmat.primitives.serialization import Encoding, NoEncryption, PrivateFormat, load_pem_private_key from django.conf import settings logger = logging.getLogger(__name__) diff --git a/arkindex/ponos/models.py b/arkindex/ponos/models.py index 37784016c7..ce312053fc 100644 --- a/arkindex/ponos/models.py +++ b/arkindex/ponos/models.py @@ -7,6 +7,7 @@ from datetime import timedelta from hashlib import sha256 from botocore.exceptions import ClientError +from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from django.conf import settings from django.core.exceptions import ValidationError from django.core.validators import MinLengthValidator, MinValueValidator, RegexValidator @@ -24,7 +25,6 @@ from arkindex.ponos.keys import gen_nonce from arkindex.ponos.managers import TaskManager from arkindex.ponos.recipe import parse_recipe, recipe_depth from arkindex.ponos.validators import MaxValueValidator -from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from rest_framework_simplejwt.tokens import RefreshToken # Maximum allowed time until an agent is considered inactive since last request diff --git a/arkindex/ponos/serializer_fields.py b/arkindex/ponos/serializer_fields.py index 8b950c2dd6..1fac0de042 100644 --- a/arkindex/ponos/serializer_fields.py +++ b/arkindex/ponos/serializer_fields.py @@ -3,11 +3,7 @@ import base64 from cryptography.exceptions import UnsupportedAlgorithm from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.asymmetric import ec -from cryptography.hazmat.primitives.serialization import ( - Encoding, - PublicFormat, - load_pem_public_key, -) +from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat, load_pem_public_key from enumfields import Enum from rest_framework import serializers diff --git a/arkindex/ponos/tests/test_api.py b/arkindex/ponos/tests/test_api.py index d4d18d5514..5e1cd7da62 100644 --- a/arkindex/ponos/tests/test_api.py +++ b/arkindex/ponos/tests/test_api.py @@ -5,6 +5,11 @@ import uuid from io import BytesIO from unittest.mock import call, patch +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives.asymmetric import ec +from cryptography.hazmat.primitives.hashes import SHA256 +from cryptography.hazmat.primitives.kdf.hkdf import HKDF +from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat from django.conf import settings from django.contrib.auth.models import User from django.test import override_settings @@ -17,11 +22,6 @@ from arkindex.ponos.api import timezone as api_tz from arkindex.ponos.authentication import AgentUser from arkindex.ponos.models import FINAL_STATES, GPU, Agent, Farm, Secret, State, Task, Workflow, encrypt from arkindex.project.tools import build_public_key -from cryptography.hazmat.backends import default_backend -from cryptography.hazmat.primitives.asymmetric import ec -from cryptography.hazmat.primitives.hashes import SHA256 -from cryptography.hazmat.primitives.kdf.hkdf import HKDF -from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat RECIPE = """ env: diff --git a/arkindex/ponos/tests/test_keys.py b/arkindex/ponos/tests/test_keys.py index 697c5717d6..f1d397e970 100644 --- a/arkindex/ponos/tests/test_keys.py +++ b/arkindex/ponos/tests/test_keys.py @@ -1,9 +1,9 @@ import os import tempfile +import cryptography from django.test import TestCase, override_settings -import cryptography from arkindex.ponos.keys import gen_private_key, load_private_key BAD_KEY = """-----BEGIN RSA PRIVATE KEY----- diff --git a/arkindex/project/tools.py b/arkindex/project/tools.py index efdd02f823..1a9348d43a 100644 --- a/arkindex/project/tools.py +++ b/arkindex/project/tools.py @@ -1,14 +1,14 @@ from collections.abc import Iterable, Iterator, Sized +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives.asymmetric import ec +from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat from django.db.models import Aggregate, CharField, Func from django.db.models.expressions import BaseExpression, OrderByList from django.urls import reverse from rest_framework import serializers from arkindex.documents.models import Element, ElementPath -from cryptography.hazmat.backends import default_backend -from cryptography.hazmat.primitives.asymmetric import ec -from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat def build_absolute_url(element, request, name, id_argument='pk', **kwargs): -- GitLab