Skip to content

Commit

Permalink
chore(lint): Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
merkata committed Sep 2, 2024
1 parent 44c5d97 commit 7ceae18
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
6 changes: 4 additions & 2 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See LICENSE file for licensing details.

"""File containing constants to be used in the charm."""

import pathlib

# App
Expand All @@ -23,7 +23,9 @@
IRC_BRIDGE_UNIT_FILE_PATH = SYSTEMD_DIR_PATH / "matrix-appservice-irc.service"
IRC_BRIDGE_TARGET_FILE_PATH = SYSTEMD_DIR_PATH / "matrix-appservice-irc.target"
IRC_BRIDGE_TEMPLATE_UNIT_FILE_PATH = IRC_BRIDGE_TEMPLATE_DIR_PATH / "matrix-appservice-irc.service"
IRC_BRIDGE_TEMPLATE_TARGET_FILE_PATH = IRC_BRIDGE_TEMPLATE_DIR_PATH / "matrix-appservice-irc.target"
IRC_BRIDGE_TEMPLATE_TARGET_FILE_PATH = (
IRC_BRIDGE_TEMPLATE_DIR_PATH / "matrix-appservice-irc.target"
)
IRC_BRIDGE_PEM_FILE_PATH = IRC_BRIDGE_CONFIG_DIR_PATH / "irc_passkey.pem"
IRC_BRIDGE_REGISTRATION_FILE_PATH = IRC_BRIDGE_CONFIG_DIR_PATH / "appservice-registration-irc.yaml"

Expand Down
11 changes: 5 additions & 6 deletions src/database_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class DatabaseObserver(Object):
Attributes:
relation_name: The name of the relation to observe.
database: The database relation interface.
uri: The database uri.
"""

def __init__(self, charm: CharmBase, relation_name: str):
Expand All @@ -44,15 +43,15 @@ def _on_database_created(self, _: DatabaseCreatedEvent) -> None:
self._charm.reconcile() # type: ignore

def get_db(self) -> typing.Optional[DatasourcePostgreSQL]:
"""Return a postgresql datasource model."""
"""Return a postgresql datasource model.
Returns:
DatasourcePostgreSQL: The datasource model.
"""
# not using get_relation due this issue
# https://github.com/canonical/operator/issues/1153
if not self.model.relations.get(self.database.relation_name):
return None

relation = self.model.get_relation(self.relation_name)
return DatasourcePostgreSQL.from_relation(relation)

relation_id = self.database.relations[0].id
relation_data = self.database.fetch_relation_data(relation_ids=[relation_id])[0]

15 changes: 7 additions & 8 deletions src/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""IRC Bridge charm business logic."""

import logging
import pathlib
import shutil
import subprocess # nosec

Expand All @@ -15,21 +14,21 @@
import exceptions
from charm_types import CharmConfig, DatasourceMatrix, DatasourcePostgreSQL
from constants import (
IRC_BRIDGE_CONFIG_DIR_PATH,
IRC_BRIDGE_CONFIG_FILE_PATH,
IRC_BRIDGE_HEALTH_PORT,
IRC_BRIDGE_KEY_ALGO,
IRC_BRIDGE_KEY_OPTS,
IRC_BRIDGE_CONFIG_DIR_PATH,
IRC_BRIDGE_CONFIG_FILE_PATH,
IRC_BRIDGE_PEM_FILE_PATH,
IRC_BRIDGE_REGISTRATION_FILE_PATH,
IRC_BRIDGE_SNAP_NAME,
IRC_BRIDGE_TARGET_FILE_PATH,
IRC_BRIDGE_TEMPLATE_CONFIG_FILE_PATH,
IRC_BRIDGE_TEMPLATE_TARGET_FILE_PATH,
IRC_BRIDGE_TEMPLATE_UNIT_FILE_PATH,
IRC_BRIDGE_TARGET_FILE_PATH,
IRC_BRIDGE_UNIT_FILE_PATH,
IRC_BRIDGE_SNAP_NAME,
SNAP_PACKAGES,
SYSTEMD_DIR_PATH
SYSTEMD_DIR_PATH,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -148,8 +147,8 @@ def _generate_pem_file_local(self) -> None:
"/bin/bash",
"-c",
f"[[ -f {IRC_BRIDGE_PEM_FILE_PATH} ]] || "
+ "openssl genpkey -out {IRC_BRIDGE_PEM_FILE_PATH} "
+ "-outform PEM -algorithm {IRC_BRIDGE_KEY_ALGO} -pkeyopt {IRC_BRIDGE_KEY_OPTS}",
f"openssl genpkey -out {IRC_BRIDGE_PEM_FILE_PATH} "
f"-outform PEM -algorithm {IRC_BRIDGE_KEY_ALGO} -pkeyopt {IRC_BRIDGE_KEY_OPTS}",
]
logger.info("Creating PEM file for IRC bridge.")
subprocess.run(pem_create_command, shell=True, check=True, capture_output=True) # nosec
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/test_irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
IRC_BRIDGE_TEMPLATE_CONFIG_FILE_PATH,
IRC_BRIDGE_TEMPLATE_TARGET_FILE_PATH,
IRC_BRIDGE_TEMPLATE_UNIT_FILE_PATH,
IRC_BRIDGE_TEMPLATE_DIR_PATH,
SYSTEMD_DIR_PATH
SYSTEMD_DIR_PATH,
)
from irc import InstallError, IRCBridgeService, ReloadError, StartError, StopError

Expand Down Expand Up @@ -268,8 +267,8 @@ def test_configure_generates_pem_file_local(irc_bridge_service, mocker):
"/bin/bash",
"-c",
f"[[ -f {IRC_BRIDGE_PEM_FILE_PATH} ]] || "
+ "openssl genpkey -out {IRC_BRIDGE_PEM_FILE_PATH} "
+ "-outform PEM -algorithm {IRC_BRIDGE_KEY_ALGO} -pkeyopt {IRC_BRIDGE_KEY_OPTS}",
f"openssl genpkey -out {IRC_BRIDGE_PEM_FILE_PATH} "
f"-outform PEM -algorithm {IRC_BRIDGE_KEY_ALGO} -pkeyopt {IRC_BRIDGE_KEY_OPTS}",
],
shell=True, # nosec
check=True,
Expand Down

0 comments on commit 7ceae18

Please sign in to comment.