Skip to content

Commit

Permalink
Enable ruff format skip-magic-trailing-comma
Browse files Browse the repository at this point in the history
  • Loading branch information
dekkers committed May 21, 2024
1 parent 951a529 commit 7b8fd72
Show file tree
Hide file tree
Showing 399 changed files with 1,610 additions and 6,587 deletions.
7 changes: 1 addition & 6 deletions boefjes/boefjes/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@

@click.command()
@click.argument("worker_type", type=click.Choice([q.value for q in WorkerManager.Queue]))
@click.option(
"--log-level",
type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR"]),
help="Log level",
default="INFO",
)
@click.option("--log-level", type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR"]), help="Log level", default="INFO")
def cli(worker_type: str, log_level: str):
logger.setLevel(log_level)
logger.info("Starting runtime for %s", worker_type)
Expand Down
6 changes: 1 addition & 5 deletions boefjes/boefjes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ def get_scheduler_client():


def get_bytes_client():
return BytesAPIClient(
str(settings.bytes_api),
username=settings.bytes_username,
password=settings.bytes_password,
)
return BytesAPIClient(str(settings.bytes_api), username=settings.bytes_username, password=settings.bytes_password)


@app.get("/healthz")
Expand Down
5 changes: 1 addition & 4 deletions boefjes/boefjes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,7 @@ def _format_exit_code(exitcode: int | None) -> str:


def _start_working(
task_queue: mp.Queue,
handler: Handler,
scheduler_client: SchedulerClientInterface,
handling_tasks: dict[int, str],
task_queue: mp.Queue, handler: Handler, scheduler_client: SchedulerClientInterface, handling_tasks: dict[int, str]
):
logger.info("Started listening for tasks from worker[pid=%s]", os.getpid())

Expand Down
9 changes: 2 additions & 7 deletions boefjes/boefjes/clients/bytes_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ def __init__(self, base_url: str, username: str, password: str):
transport=(HTTPTransport(retries=6)),
)

self.credentials = {
"username": username,
"password": password,
}
self.credentials = {"username": username, "password": password}
self.headers: dict[str, str] = {}

def login(self) -> None:
Expand All @@ -63,9 +60,7 @@ def _get_authentication_headers(self) -> dict[str, str]:

def _get_token(self) -> str:
response = self._session.post(
"/token",
data=self.credentials,
headers={"content-type": "application/x-www-form-urlencoded"},
"/token", data=self.credentials, headers={"content-type": "application/x-www-form-urlencoded"}
)

return str(response.json()["access_token"])
Expand Down
19 changes: 4 additions & 15 deletions boefjes/boefjes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,12 @@ class Settings(BaseSettings):
..., examples=["http://localhost:8001"], description="Octopoes API URL", validation_alias="OCTOPOES_API"
)
api: AnyHttpUrl = Field(
...,
examples=["http://boefje:8000"],
description="The URL on which the boefjes API is available",
..., examples=["http://boefje:8000"], description="The URL on which the boefjes API is available"
)
# Boefje server settings
api_host: str = Field(
"0.0.0.0",
description="Host address of the Boefje API server",
)
api_port: int = Field(
8000,
description="Host port of the Boefje API server",
)
docker_network: str = Field(
"bridge",
description="Docker network to run Boefjes in",
)
api_host: str = Field("0.0.0.0", description="Host address of the Boefje API server")
api_port: int = Field(8000, description="Host port of the Boefje API server")
docker_network: str = Field("bridge", description="Docker network to run Boefjes in")
bytes_api: AnyHttpUrl = Field(
..., examples=["http://localhost:8002"], description="Bytes API URL", validation_alias="BYTES_API"
)
Expand Down
4 changes: 1 addition & 3 deletions boefjes/boefjes/docker_boefjes_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def __init__(self, boefje_resource: Boefje, boefje_meta: BoefjeMeta):
self.docker_client = docker.from_env()
self.scheduler_client = SchedulerAPIClient(str(settings.scheduler_api))
self.bytes_api_client = BytesAPIClient(
str(settings.bytes_api),
username=settings.bytes_username,
password=settings.bytes_password,
str(settings.bytes_api), username=settings.bytes_username, password=settings.bytes_password
)

def run(self) -> None:
Expand Down
12 changes: 3 additions & 9 deletions boefjes/boefjes/job_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
logger = logging.getLogger(__name__)

bytes_api_client = BytesAPIClient(
str(settings.bytes_api),
username=settings.bytes_username,
password=settings.bytes_password,
str(settings.bytes_api), username=settings.bytes_username, password=settings.bytes_password
)


Expand Down Expand Up @@ -68,8 +66,7 @@ def get_environment_settings(boefje_meta: BoefjeMeta, environment_keys: list[str
try:
katalogus_api = str(settings.katalogus_api).rstrip("/")
response = httpx.get(
f"{katalogus_api}/v1/organisations/{boefje_meta.organization}/{boefje_meta.boefje.id}/settings",
timeout=30,
f"{katalogus_api}/v1/organisations/{boefje_meta.organization}/{boefje_meta.boefje.id}/settings", timeout=30
)
response.raise_for_status()
environment = response.json()
Expand All @@ -91,10 +88,7 @@ def get_environment_settings(boefje_meta: BoefjeMeta, environment_keys: list[str

class BoefjeHandler(Handler):
def __init__(
self,
job_runner: BoefjeJobRunner,
local_repository: LocalPluginRepository,
bytes_client: BytesAPIClient,
self, job_runner: BoefjeJobRunner, local_repository: LocalPluginRepository, bytes_client: BytesAPIClient
):
self.job_runner = job_runner
self.local_repository = local_repository
Expand Down
5 changes: 1 addition & 4 deletions boefjes/boefjes/katalogus/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@
def entity_not_found_handler(request: Request, exc: StorageError):
logger.exception("some error", exc_info=exc)

return JSONResponse(
status_code=status.HTTP_404_NOT_FOUND,
content={"message": exc.message},
)
return JSONResponse(status_code=status.HTTP_404_NOT_FOUND, content={"message": exc.message})


class ServiceHealth(BaseModel):
Expand Down
7 changes: 1 addition & 6 deletions boefjes/boefjes/katalogus/dependencies/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,7 @@ def update_by_id(self, repository_id: str, plugin_id: str, organisation_id: str,
all_settings = self.settings_storage.get_all(organisation_id, plugin_id)
self._assert_settings_match_schema(all_settings, organisation_id, plugin_id)

self.plugin_enabled_store.update_or_create_by_id(
plugin_id,
repository_id,
enabled,
organisation_id,
)
self.plugin_enabled_store.update_or_create_by_id(plugin_id, repository_id, enabled, organisation_id)

def _plugins_for_repos(
self, repositories: Iterable[Repository], organisation_id: str
Expand Down
4 changes: 1 addition & 3 deletions boefjes/boefjes/katalogus/dependencies/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
logger = logging.getLogger(__name__)


def get_repository_store(
organisation_id: str,
) -> Iterator[RepositoryStorage]:
def get_repository_store(organisation_id: str) -> Iterator[RepositoryStorage]:
yield from session_managed_iterator(create_repository_storage)
22 changes: 5 additions & 17 deletions boefjes/boefjes/katalogus/routers/organisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@


def check_organisation_exists(
organisation_id: str,
storage: OrganisationStorage = Depends(get_organisations_store),
organisation_id: str, storage: OrganisationStorage = Depends(get_organisations_store)
) -> None:
"""
Checks if an organisation exists, if not, creates it.
Expand All @@ -24,36 +23,25 @@ def check_organisation_exists(


@router.get("", response_model=dict[str, Organisation])
def list_organisations(
storage: OrganisationStorage = Depends(get_organisations_store),
):
def list_organisations(storage: OrganisationStorage = Depends(get_organisations_store)):
return storage.get_all()


@router.get("/{organisation_id}", response_model=Organisation)
def get_organisation(
organisation_id: str,
storage: OrganisationStorage = Depends(get_organisations_store),
):
def get_organisation(organisation_id: str, storage: OrganisationStorage = Depends(get_organisations_store)):
try:
return storage.get_by_id(organisation_id)
except (KeyError, ObjectNotFoundException):
raise HTTPException(status.HTTP_404_NOT_FOUND, "Unknown organisation")


@router.post("/", status_code=status.HTTP_201_CREATED)
def add_organisation(
organisation: Organisation,
storage: OrganisationStorage = Depends(get_organisations_store),
):
def add_organisation(organisation: Organisation, storage: OrganisationStorage = Depends(get_organisations_store)):
with storage as store:
store.create(organisation)


@router.delete("/{organisation_id}")
def remove_organisation(
organisation_id: str,
storage: OrganisationStorage = Depends(get_organisations_store),
):
def remove_organisation(organisation_id: str, storage: OrganisationStorage = Depends(get_organisations_store)):
with storage as store:
store.delete_by_id(organisation_id)
36 changes: 9 additions & 27 deletions boefjes/boefjes/katalogus/routers/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
from boefjes.katalogus.types import FilterParameters, PaginationParameters

router = APIRouter(
prefix="/organisations/{organisation_id}",
tags=["plugins"],
dependencies=[Depends(check_organisation_exists)],
prefix="/organisations/{organisation_id}", tags=["plugins"], dependencies=[Depends(check_organisation_exists)]
)


Expand Down Expand Up @@ -49,10 +47,7 @@ def list_plugins(

# filter plugins by id, name or description
if filter_params.q is not None:
plugins = filter(
partial(_plugin_matches_query, query=filter_params.q),
plugins,
)
plugins = filter(partial(_plugin_matches_query, query=filter_params.q), plugins)

# filter plugins by type
if filter_params.type is not None:
Expand All @@ -74,9 +69,7 @@ def list_plugins(

@router.get("/plugins/{plugin_id}", response_model=PluginType)
def get_plugin(
plugin_id: str,
organisation_id: str,
plugin_service: PluginService = Depends(get_plugin_service),
plugin_id: str, organisation_id: str, plugin_service: PluginService = Depends(get_plugin_service)
) -> PluginType:
try:
with plugin_service as p:
Expand All @@ -87,14 +80,9 @@ def get_plugin(
raise HTTPException(ex.response.status_code)


@router.get(
"/repositories/{repository_id}/plugins",
response_model=dict[str, PluginType],
)
@router.get("/repositories/{repository_id}/plugins", response_model=dict[str, PluginType])
def list_repository_plugins(
repository_id: str,
organisation_id: str,
plugin_service: PluginService = Depends(get_plugin_service),
repository_id: str, organisation_id: str, plugin_service: PluginService = Depends(get_plugin_service)
):
with plugin_service as p:
return p.repository_plugins(repository_id, organisation_id)
Expand Down Expand Up @@ -135,8 +123,7 @@ def update_plugin_state(

@router.get("/plugins/{plugin_id}/schema.json", include_in_schema=False)
def get_plugin_schema(
plugin_id: str,
plugin_service: PluginService = Depends(get_plugin_service),
plugin_id: str, plugin_service: PluginService = Depends(get_plugin_service)
) -> JSONResponse: # TODO: support for plugin covers in plugin repositories (?)
try:
with plugin_service as p:
Expand All @@ -149,8 +136,7 @@ def get_plugin_schema(

@router.get("/plugins/{plugin_id}/cover.jpg", include_in_schema=False)
def get_plugin_cover(
plugin_id: str,
plugin_service: PluginService = Depends(get_plugin_service),
plugin_id: str, plugin_service: PluginService = Depends(get_plugin_service)
) -> FileResponse: # TODO: support for plugin covers in plugin repositories (?)
try:
with plugin_service as p:
Expand All @@ -163,9 +149,7 @@ def get_plugin_cover(

@router.get("/plugins/{plugin_id}/description.md", include_in_schema=False)
def get_plugin_description(
plugin_id: str,
organisation_id: str,
plugin_service: PluginService = Depends(get_plugin_service),
plugin_id: str, organisation_id: str, plugin_service: PluginService = Depends(get_plugin_service)
) -> Response: # TODO: support for markdown descriptions in plugin repositories (?)
try:
with plugin_service as p:
Expand All @@ -178,9 +162,7 @@ def get_plugin_description(

@router.post("/settings/clone/{to_organisation_id}")
def clone_organisation_settings(
organisation_id: str,
to_organisation_id: str,
storage: PluginService = Depends(get_plugin_service),
organisation_id: str, to_organisation_id: str, storage: PluginService = Depends(get_plugin_service)
):
with storage as store:
store.clone_settings_to_organisation(organisation_id, to_organisation_id)
10 changes: 2 additions & 8 deletions boefjes/boefjes/katalogus/routers/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,13 @@ def get_repository(repository_id: str, storage: RepositoryStorage = Depends(get_


@router.post("/", status_code=status.HTTP_201_CREATED)
def add_repository(
repository: Repository,
storage: RepositoryStorage = Depends(get_repository_store),
):
def add_repository(repository: Repository, storage: RepositoryStorage = Depends(get_repository_store)):
with storage as store:
store.create(repository)


@router.delete("/{repository_id}")
def remove_repository(
repository_id: str,
storage: RepositoryStorage = Depends(get_repository_store),
):
def remove_repository(repository_id: str, storage: RepositoryStorage = Depends(get_repository_store)):
if repository_id == RESERVED_LOCAL_ID:
raise HTTPException(status.HTTP_403_FORBIDDEN, "LOCAL repository cannot be deleted")
with storage as store:
Expand Down
11 changes: 2 additions & 9 deletions boefjes/boefjes/katalogus/routers/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,14 @@


@router.get("", response_model=dict)
def list_settings(
organisation_id: str,
plugin_id: str,
plugin_service: PluginService = Depends(get_plugin_service),
):
def list_settings(organisation_id: str, plugin_id: str, plugin_service: PluginService = Depends(get_plugin_service)):
with plugin_service as p:
return p.get_all_settings(organisation_id, plugin_id)


@router.put("")
def upsert_settings(
organisation_id: str,
plugin_id: str,
values: dict,
plugin_service: PluginService = Depends(get_plugin_service),
organisation_id: str, plugin_id: str, values: dict, plugin_service: PluginService = Depends(get_plugin_service)
):
with plugin_service as p:
p.upsert_settings(values, organisation_id, plugin_id)
Expand Down
12 changes: 2 additions & 10 deletions boefjes/boefjes/katalogus/storage/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ def delete_by_id(self, organisation_id: str) -> None:


class RepositoryStorageMemory(RepositoryStorage):
def __init__(
self,
organisation_id: str,
defaults: dict[str, Repository] | None = None,
):
def __init__(self, organisation_id: str, defaults: dict[str, Repository] | None = None):
self._data = repositories.setdefault(organisation_id, {}) if defaults is None else defaults
self._organisation_id = organisation_id

Expand Down Expand Up @@ -79,11 +75,7 @@ def delete(self, organisation_id: str, plugin_id: str) -> None:


class PluginStatesStorageMemory(PluginEnabledStorage):
def __init__(
self,
organisation: str,
defaults: dict[str, bool] | None = None,
):
def __init__(self, organisation: str, defaults: dict[str, bool] | None = None):
self._data = plugins_state.setdefault(organisation, {}) if defaults is None else defaults
self._organisation = organisation

Expand Down
8 changes: 1 addition & 7 deletions boefjes/boefjes/katalogus/tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ def setUp(self) -> None:
self.plugin_state_storage = SQLPluginEnabledStorage(session, settings)

with self.repository_storage as store:
store.create(
Repository(
id="LOCAL",
name="Test",
base_url="http://test.url",
)
)
store.create(Repository(id="LOCAL", name="Test", base_url="http://test.url"))

self.org = Organisation(id="test", name="Test Organisation")

Expand Down
Loading

0 comments on commit 7b8fd72

Please sign in to comment.