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

1 import os

2

3 from edwh.helpers import generate_password

4 from invoke import Context

5

6 from . import register

7 from .s3 import S3Repository

8

9

10@register()

11 class OracleRepository(S3Repository):

12 # https://docs.oracle.com/en-us/iaas/Content/Object/Tasks/s3compatibleapi.htm

13

14 def setup(self) -> None:

15 self.check_env(

16 "ORACLE_NAME",

17 default=None,

18 comment="Bucket to store your backups",

19 )

20

21 self.check_env(

22 "ORACLE_PASSWORD",

23 default=generate_password(silent=True),

24 comment="Create a Restic password, keep it safe.",

25 )

26

27 # Namespace is shown on the bucket page and transformed into an S3-compat uri automatically

28 self.check_env("ORACLE_NAMESPACE", default=None, comment="Oracle Object Storage Namespace")

29

30 # https://docs.oracle.com/en-us/iaas/Content/Identity/Tasks/managingcredentials.htm#Working2

31 self.check_env("ORACLE_ACCESS_KEY_ID", default=None, comment="(Customer) Access Key")

32 self.check_env("ORACLE_SECRET_ACCESS_KEY", default=None, comment="(Customer) Access Secret")

33

34 self.check_env(

35 "ORACLE_REGION", default="eu-amsterdam-1", comment="In which Oracle region is your bucket located?"

36 )

37

38 def prepare_for_restic(self, _: Context) -> None:

39 env = self.env_config

40 os.environ["RESTIC_PASSWORD"] = env["ORACLE_PASSWORD"]

41 os.environ["RESTIC_REPOSITORY"] = self.uri

42

43 os.environ["AWS_ACCESS_KEY_ID"] = env["ORACLE_ACCESS_KEY_ID"]

44 os.environ["AWS_SECRET_ACCESS_KEY"] = env["ORACLE_SECRET_ACCESS_KEY"]

45

46 @property

47 def uri(self) -> str:

48 env = self.env_config

49 return "s3:{namespace}.compat.objectstorage.{region}.oraclecloud.com/{bucket}".format(

50 namespace=env.get("ORACLE_NAMESPACE", "?"),

51 region=env.get("ORACLE_REGION", "?"),

52 bucket=env.get("ORACLE_NAME", "?"),

53 )