Skip to content

Commit

Permalink
refactor: isort for package import
Browse files Browse the repository at this point in the history
  • Loading branch information
phbelitz committed Dec 23, 2022
1 parent 9248bd1 commit 420fb36
Show file tree
Hide file tree
Showing 35 changed files with 115 additions and 68 deletions.
3 changes: 1 addition & 2 deletions connaisseur/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
from logging.config import dictConfig

from cheroot.server import HTTPServer
from cheroot.wsgi import Server
from cheroot.ssl.builtin import BuiltinSSLAdapter
from cheroot.wsgi import Server

from connaisseur.flask_application import APP
from connaisseur.logging_wrapper import ConnaisseurLoggingWrapper


if __name__ == "__main__":
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")

Expand Down
4 changes: 2 additions & 2 deletions connaisseur/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import requests
from jinja2 import StrictUndefined, Template

from connaisseur.util import safe_json_open, validate_schema
from connaisseur.admission_request import AdmissionRequest
from connaisseur.exceptions import (
AlertSendingError,
ConfigurationError,
InvalidConfigurationFormatError,
InvalidImageFormatError,
)
from connaisseur.admission_request import AdmissionRequest
from connaisseur.util import safe_json_open, validate_schema


class AlertingConfiguration:
Expand Down
1 change: 1 addition & 0 deletions connaisseur/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import collections
import fnmatch
import os

import yaml

from connaisseur.exceptions import (
Expand Down
1 change: 1 addition & 0 deletions connaisseur/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SHA256 = "sha256"
3 changes: 1 addition & 2 deletions connaisseur/flask_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import traceback

from flask import Flask, jsonify, request
from prometheus_flask_exporter import PrometheusMetrics, NO_PREFIX
from prometheus_flask_exporter import NO_PREFIX, PrometheusMetrics

import connaisseur.constants as const
from connaisseur.admission_request import AdmissionRequest
Expand All @@ -17,7 +17,6 @@
)
from connaisseur.util import get_admission_review


APP = Flask(__name__)
"""
Flask application that admits the request send to the k8s cluster, validates it and
Expand Down
1 change: 1 addition & 0 deletions connaisseur/kube_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import requests


Expand Down
2 changes: 1 addition & 1 deletion connaisseur/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Optional

import yaml
from jsonschema import FormatChecker, validate, ValidationError
from jsonschema import FormatChecker, ValidationError, validate

from connaisseur.exceptions import PathTraversalError

Expand Down
10 changes: 6 additions & 4 deletions connaisseur/validators/cosign/cosign_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
import os
import re
import subprocess # nosec

from concurrent.futures import ThreadPoolExecutor

import connaisseur.constants as const
from connaisseur.exceptions import (
CosignError,
CosignTimeout,
NotFoundException,
InvalidFormatException,
NotFoundException,
UnexpectedCosignData,
ValidationError,
WrongKeyError,
)
from connaisseur.image import Image
from connaisseur.trust_root import KMSKey, TrustRoot, ECDSAKey
from connaisseur.trust_root import ECDSAKey, KMSKey, TrustRoot
from connaisseur.util import safe_path_func # nosec
from connaisseur.validators.interface import ValidatorInterface

Expand Down Expand Up @@ -163,7 +162,10 @@ def __get_cosign_validated_digests(self, image: str, trust_root: dict):
digest = sig_data["critical"]["image"].get(
"docker-manifest-digest", ""
)
if re.match(rf"{const.SHA256}:[0-9A-Fa-f]{{64}}", digest) is None:
if (
re.match(rf"{const.SHA256}:[0-9A-Fa-f]{{64}}", digest)
is None
):
msg = "Digest '{digest}' does not match expected digest pattern."
raise InvalidFormatException(message=msg, digest=digest)
except Exception as err:
Expand Down
2 changes: 1 addition & 1 deletion connaisseur/validators/notaryv1/key_store.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import connaisseur.constants as const
from connaisseur.exceptions import NotFoundException
from connaisseur.trust_root import TrustRoot
import connaisseur.constants as const


class KeyStore:
Expand Down
2 changes: 1 addition & 1 deletion connaisseur/validators/notaryv1/trust_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ValidationError,
WrongKeyError,
)
from connaisseur.trust_root import TrustRoot, ECDSAKey
from connaisseur.trust_root import ECDSAKey, TrustRoot
from connaisseur.util import validate_schema
from connaisseur.validators.notaryv1.key_store import KeyStore

Expand Down
1 change: 0 additions & 1 deletion connaisseur/workload_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from connaisseur.exceptions import ParentNotFoundError, UnknownAPIVersionError
from connaisseur.image import Image


SUPPORTED_API_VERSIONS = {
"Pod": ["v1"],
"Deployment": ["apps/v1", "apps/v1beta1", "apps/v1beta2"],
Expand Down
3 changes: 2 additions & 1 deletion scripts/changelogger.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import argparse
import base64
import requests
import subprocess
import sys
import time

import requests

sep = "@@__CHGLOG__@@"
delim = "@@__CHGLOG_DELIMITER__@@"
ha = "%H"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from setuptools import setup, find_packages
from setuptools import find_packages, setup

setup(name="connaisseur", packages=find_packages())
17 changes: 9 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import json
import os
import re
import json
from contextlib import contextmanager

import pytest
import requests
from aioresponses import CallbackResult
import connaisseur.kube_api
import connaisseur.config as co

import connaisseur.admission_request as admreq
import connaisseur.alert as alert
from connaisseur.trust_root import TrustRoot
import connaisseur.validators.notaryv1.trust_data as td
import connaisseur.config as co
import connaisseur.kube_api
import connaisseur.util as util
import connaisseur.validators.notaryv1.key_store as ks
import connaisseur.validators.notaryv1.notary as no
import connaisseur.validators.notaryv1.notaryv1_validator as nv1
import connaisseur.util as util
from contextlib import contextmanager

import connaisseur.validators.notaryv1.trust_data as td
from connaisseur.trust_root import TrustRoot

"""
This file is used for sharing fixtures across all other test files.
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/alerting/app/alert_checker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import Flask, request
import json

from flask import Flask, request

APP = Flask(__name__)

endpoint_hits = {}
Expand Down
3 changes: 2 additions & 1 deletion tests/test_admission_request.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest
from . import conftest as fix

import connaisseur.admission_request as admreq
import connaisseur.exceptions as exc

from . import conftest as fix

static_adm_req = [
{
Expand Down
8 changes: 5 additions & 3 deletions tests/test_alert.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import pytest
from datetime import datetime, timedelta
import json
from datetime import datetime, timedelta

import pytest

from . import conftest as fix
import connaisseur.alert as alert
from connaisseur.admission_request import AdmissionRequest
from connaisseur.exceptions import AlertSendingError, ConfigurationError

from . import conftest as fix

with open(
"tests/data/sample_admission_requests/ad_request_deployments.json", "r"
) as readfile:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import pytest
from . import conftest as fix

import connaisseur.config as co
import connaisseur.exceptions as exc
import connaisseur.validators as vals
from connaisseur.image import Image

from . import conftest as fix


@pytest.fixture(autouse=True)
def mock_config_path(monkeypatch):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

import pytest

import connaisseur.exceptions as exc


Expand Down
5 changes: 4 additions & 1 deletion tests/test_flask_application.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import re

import pytest
from aioresponses import aioresponses
from . import conftest as fix

import connaisseur.alert as alert
import connaisseur.config as co
import connaisseur.exceptions as exc
from connaisseur.admission_request import AdmissionRequest
from connaisseur.image import Image
from connaisseur.validators.static.static_validator import StaticValidator

from . import conftest as fix


@pytest.fixture(autouse=True)
def m_config(monkeypatch, sample_nv1):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
from . import conftest as fix
import connaisseur.image as img

import connaisseur.exceptions as exc
import connaisseur.image as img

from . import conftest as fix


@pytest.mark.parametrize(
Expand Down
4 changes: 3 additions & 1 deletion tests/test_kube_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
from . import conftest as fix

import connaisseur.kube_api as k_api

from . import conftest as fix


@pytest.mark.parametrize(
"url, response",
Expand Down
5 changes: 3 additions & 2 deletions tests/test_logging_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pytest
import time

from . import conftest as fix
import pytest

import connaisseur.logging_wrapper as lw

from . import conftest as fix


@pytest.fixture
def mock_time(monkeypatch):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_trust_root.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest
from . import conftest as fix

import connaisseur.exceptions as exc
import connaisseur.trust_root as trust_root

from . import conftest as fix

sample_ecdsa = "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEOXYta5TgdCwXTCnLU09W5T4M4r9f\nQQrqJuADP6U7g5r9ICgPSmZuRHP/1AYUfOQW3baveKsT969EfELKj1lfCA==\n-----END PUBLIC KEY-----"
sample_rsa = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs5pC7R5OTSTUMJHUniPk\nrLfmGDAUxZtRlvIE+pGPCD6cUXH22advkK87xwpupjxdVYuKTFnWHUIyFJwjI3vu\nsievezcAr0E/xxyeo49tWog9kFoooK3qmXjpETC8OpvNROZ0K3qhlm9PZkGo3gSJ\n/B4rMU/d+jkCI8eiUPpdVQOczdBoD5nzQAF1mfmffWGsbKY+d8/l77Vset0GXExR\nzUtnglMhREyHNpDeQUg5OEn+kuGLlTzIxpIF+MlbzP3+xmNEzH2iafr0ae2g5kX2\n880priXpxG8GXW2ybZmPvchclnvFu4ZfZcM10FpgYJFvR/9iofFeAka9u5z6VZcc\nmQIDAQAB\n-----END PUBLIC KEY-----"
Expand Down
6 changes: 4 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
from . import conftest as fix
import connaisseur.util as ut

import connaisseur.exceptions as exc
import connaisseur.util as ut

from . import conftest as fix


@pytest.mark.parametrize(
Expand Down
5 changes: 3 additions & 2 deletions tests/test_workload_object.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pytest
from . import conftest as fix
import connaisseur.workload_object as wl

import connaisseur.exceptions as exc
import connaisseur.workload_object as wl
from connaisseur.image import Image

from . import conftest as fix

static_k8s = [
{
Expand Down
11 changes: 7 additions & 4 deletions tests/validators/cosign/test_cosign_validator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import subprocess

import pytest
import pytest_subprocess
import subprocess
from ... import conftest as fix
from connaisseur.image import Image
import connaisseur.validators.cosign.cosign_validator as co

import connaisseur.exceptions as exc
import connaisseur.validators.cosign.cosign_validator as co
from connaisseur.image import Image
from connaisseur.trust_root import TrustRoot

from ... import conftest as fix

example_key = (
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE6uuXb"
"ZhEfTYb4Mnb/LdrtXKTIIbzNBp8mwriocbaxXxzqu"
Expand Down
9 changes: 6 additions & 3 deletions tests/validators/notaryv1/test_keystore.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import base64
from connaisseur.trust_root import TrustRoot

import pytest
from ... import conftest as fix

import connaisseur.exceptions as exc
import connaisseur.validators.notaryv1.key_store as ks
from connaisseur.trust_root import TrustRoot
from connaisseur.validators.notaryv1.trust_data import TrustData
import connaisseur.exceptions as exc

from ... import conftest as fix

sample_key = (
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEtR5kwrDK22SyCu"
Expand Down
15 changes: 9 additions & 6 deletions tests/validators/notaryv1/test_notary.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from requests.models import HTTPError
import yaml
import pytest
import re
from aioresponses import aioresponses

import pytest
import yaml
from aiohttp.client_exceptions import ClientResponseError
from ... import conftest as fix
import connaisseur.validators.notaryv1.notary as notary
from aioresponses import aioresponses
from requests.models import HTTPError

import connaisseur.exceptions as exc
import connaisseur.util
import connaisseur.validators.notaryv1.notary as notary
from connaisseur.image import Image

from ... import conftest as fix


@pytest.fixture
def sample_notaries():
Expand Down
Loading

0 comments on commit 420fb36

Please sign in to comment.