From 09c24b2a55e20123fc41a86b235ae30b54e995ff Mon Sep 17 00:00:00 2001 From: Matthias Veit Date: Mon, 24 Jun 2024 12:13:57 +0200 Subject: [PATCH] [core][fix] Backup: correct endpoint when using https (#2123) --- fixcore/fixcore/cli/command.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/fixcore/fixcore/cli/command.py b/fixcore/fixcore/cli/command.py index 2991caec32..e5175f98ad 100644 --- a/fixcore/fixcore/cli/command.py +++ b/fixcore/fixcore/cli/command.py @@ -3724,7 +3724,12 @@ async def create_backup(self, arg: Optional[str]) -> AsyncIterator[JsonElement]: try: db_config = self.dependencies.config.db if not shutil.which("arangodump"): - raise CLIParseError("db_backup expects the executable `arangodump` to be in path!") + raise CLIParseError("backup expects the executable `arangodump` to be in path!") + if db_config.server.startswith("https"): + endpoint = db_config.server.replace("https", "http+ssl") + else: + endpoint = db_config.server.replace("http", "http+tcp") + # fmt: off process = await asyncio.create_subprocess_exec( "arangodump", @@ -3734,8 +3739,8 @@ async def create_backup(self, arg: Optional[str]) -> AsyncIterator[JsonElement]: "--log.level", "error", # only print error messages "--output-directory", temp_dir, # directory to write to "--overwrite", "true", # required for existing directories - "--server.endpoint", db_config.server.replace("http", "http+tcp"), - "--server.authentication", "false" if db_config.no_ssl_verify else "true", + "--server.endpoint", endpoint, + "--server.authentication", "false", "--server.database", db_config.database, "--server.username", db_config.username, "--server.password", db_config.password, @@ -3785,7 +3790,14 @@ async def restore_backup(self, backup_file: Optional[str], ctx: CLIContext) -> A tar.extractall(temp_dir, members=safe_members_in_tarfile(tar)) # fmt: off - db_conf = self.dependencies.config.db + db_config = self.dependencies.config.db + if not shutil.which("arangorestore"): + raise CLIParseError("restore expects the executable `arangorestore` to be in path!") + if db_config.server.startswith("https"): + endpoint = db_config.server.replace("https", "http+ssl") + else: + endpoint = db_config.server.replace("http", "http+tcp") + process = await asyncio.create_subprocess_exec( "arangorestore", "--progress", "false", # do not show progress @@ -3794,11 +3806,11 @@ async def restore_backup(self, backup_file: Optional[str], ctx: CLIContext) -> A "--log.level", "error", # only print error messages "--input-directory", temp_dir, # directory to write to "--overwrite", "true", # required for existing db collections - "--server.endpoint", db_conf.server.replace("http", "http+tcp"), - "--server.authentication", "false" if db_conf.no_ssl_verify else "true", - "--server.database", db_conf.database, - "--server.username", db_conf.username, - "--server.password", db_conf.password, + "--server.endpoint", endpoint, + "--server.authentication", "false", + "--server.database", db_config.database, + "--server.username", db_config.username, + "--server.password", db_config.password, "--configuration", "none", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,