Coverage for src/edwh_restic_plugin/repositories/local.py: 46%
24 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-28 16:28 +0100
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-28 16:28 +0100
1import os
3from edwh.helpers import generate_password
4from invoke import Context
6from . import Repository, register
9@register(priority=4)
10class LocalRepository(Repository):
11 def __init__(self):
12 super().__init__()
13 self.password = None
14 self.name = None
16 def setup(self):
17 """Ensure the required settings are defined in the .env file."""
18 self.name = self.check_env(
19 "LOCAL_NAME",
20 default=None,
21 comment="Repository name is mandatory (directory)",
22 )
23 self.password = self.check_env(
24 "LOCAL_PASSWORD",
25 default=generate_password(silent=True),
26 comment="Create a password, keep it safe.",
27 )
29 def prepare_for_restic(self, _: Context):
30 """No environment variables need be defined for local"""
31 env = self.env_config
33 self.name = env["LOCAL_NAME"]
34 os.environ["HOST"] = self.hostarg
35 os.environ["URI"] = self.uri
36 os.environ["RESTIC_HOST"] = self.hostarg
37 os.environ["RESTIC_REPOSITORY"] = self.uri
38 os.environ["RESTIC_PASSWORD"] = self.password = env["LOCAL_PASSWORD"]
40 @property
41 def uri(self):
42 """
43 Get the URI of the class instance.
45 The function returns the value of the 'name' attribute, which represents the URI of the class instance.
46 """
47 return getattr(self, "name", None) or self.env_config.get("LOCAL_NAME")