Coverage for src/edwh_restic_plugin/repositories/local.py: 46%

1 import os

2

3 from edwh.helpers import generate_password

4 from invoke import Context

5

6 from . import Repository, register

7

8

9@register(priority=4)

10 class LocalRepository(Repository):

11 def __init__(self):

12 super().__init__()

13 self.password = None

14 self.name = None

15

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 )

28

29 def prepare_for_restic(self, _: Context):

30 """No environment variables need be defined for local"""

31 env = self.env_config

32

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"]

39

40 @property

41 def uri(self):

42 """

43 Get the URI of the class instance.

44

45 The function returns the value of the 'name' attribute, which represents the URI of the class instance.

46 """

47 return self.name