Skip to content

Commit

Permalink
Changes to pass flake test and review
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgePantelakis committed Feb 2, 2024
1 parent 242e307 commit 6ce00c6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
7 changes: 6 additions & 1 deletion SCAutolib/cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,18 @@ def setup_user(ctx, name, card_dir, card_type, passwd, pin, user_type):
exit(ReturnCode.FAILURE.value)
exit(ReturnCode.SUCCESS.value)


@click.command()
@click.pass_context
def cleanup(ctx):
"""Configure entire system for smart cards based on the config file."""
"""
Cleanup all the configurations and system changes done by the prepare
command.
"""
ctx.obj["CONTROLLER"].cleanup()
exit(ReturnCode.SUCCESS.value)


cli.add_command(setup_ca)
cli.add_command(prepare)
cli.add_command(setup_user)
Expand Down
7 changes: 3 additions & 4 deletions SCAutolib/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,16 @@ def cleanup(self):

opensc_cache_dir = Path(os.path.expanduser('~') + "/.cache/opensc/")
if opensc_cache_dir.exists():
for file in opensc_cache_dir.iterdir():
file.unlink()
logger.debug("Removed opesc cache")
for cache_file in opensc_cache_dir.iterdir():
cache_file.unlink()
logger.debug("Removed opensc file cache")

self.sssd_conf.restore()
pcscd_service = File("/usr/lib/systemd/system/pcscd.service")
pcscd_service.restore()
opensc_module = File("/usr/share/p11-kit/modules/opensc.module")
opensc_module.restore()


@staticmethod
def _validate_configuration(conf: dict, params: {} = None) -> dict:
"""
Expand Down
2 changes: 1 addition & 1 deletion SCAutolib/models/CA.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from socket import gethostname

from SCAutolib import TEMPLATES_DIR, logger, run, LIB_DIR, LIB_DUMP_CAS, \
LIB_BACKUP
LIB_BACKUP
from SCAutolib.exceptions import SCAutolibException
from SCAutolib.models.file import OpensslCnf
from SCAutolib.enums import CAType
Expand Down
1 change: 1 addition & 0 deletions SCAutolib/models/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ def delete(self):
logger.info(f"Virtual card dir of {self.name} removed")

self._service_location.unlink()
run("systemctl daemon-reload", sleep=3)
logger.debug(f"Service {self._service_name} was removed")

if self.dump_file.exists():
Expand Down
12 changes: 7 additions & 5 deletions SCAutolib/models/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,13 @@ def restore(self, name: str = None):
f"{name if name else self._conf_file.name}.backup")

if original_path.exists():
with (self._conf_file.open("w") as config,
original_path.open() as backup):
with self._conf_file.open("w") as config, \
original_path.open() as backup:
config.write(backup.read())
original_path.unlink()
logger.debug(f"File {self._conf_file} is restored to {original_path}")
logger.debug(
f"File {self._conf_file} is restored to {original_path}"
)


class SSSDConf(File):
Expand Down Expand Up @@ -429,8 +431,8 @@ def restore(self):
"""

if self._backup_original and self._backup_original.exists():
with (self._backup_original.open() as original,
self._conf_file.open("w") as config):
with self._backup_original.open() as original, \
self._conf_file.open("w") as config:
config.write(original.read())
self._backup_original.unlink()
else:
Expand Down

0 comments on commit 6ce00c6

Please sign in to comment.