From fff192eb9569e49c27633f2cc24b7cb0a7bd5c77 Mon Sep 17 00:00:00 2001 From: Yogesh Mahajan Date: Tue, 11 Jun 2024 14:48:11 +0530 Subject: [PATCH] Ensure that a user can connect to a server using SSL certificates and identity files from a shared storage. #7306 --- .../browser/server_groups/servers/__init__.py | 1 + .../static/js/components/FormComponents.jsx | 9 ++++-- web/pgadmin/utils/__init__.py | 31 +++++++++++++++++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py index aa4cbe6d9..be170db0e 100644 --- a/web/pgadmin/browser/server_groups/servers/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/__init__.py @@ -165,6 +165,7 @@ class ServerModule(sg.ServerGroupPluginModule): server.tunnel_username = sharedserver.tunnel_username server.tunnel_password = sharedserver.tunnel_password server.save_password = sharedserver.save_password + server.tunnel_identity_file = sharedserver.tunnel_identity_file if hasattr(server, 'connection_params') and \ hasattr(sharedserver, 'connection_params') and \ 'passfile' in server.connection_params and \ diff --git a/web/pgadmin/static/js/components/FormComponents.jsx b/web/pgadmin/static/js/components/FormComponents.jsx index 4f22a587e..68fc0f9f6 100644 --- a/web/pgadmin/static/js/components/FormComponents.jsx +++ b/web/pgadmin/static/js/components/FormComponents.jsx @@ -43,6 +43,7 @@ import { withColorPicker } from '../helpers/withColorPicker'; import { useWindowSize } from '../custom_hooks'; import PgTreeView from '../PgTreeView'; import Loader from 'sources/components/Loader'; +import { MY_STORAGE } from '../../../misc/file_manager/static/js/components/FileManagerConstants'; const Root = styled('div')(({theme}) => ({ @@ -459,8 +460,12 @@ export function InputFileSelect({ controlProps, onChange, disabled, readonly, is dialog_title: controlProps.dialogTitle || '', btn_primary: controlProps.btnPrimary || '', }; - showFileManager(params, (fileName)=>{ - onChange?.(decodeURI(fileName)); + showFileManager(params, (fileName, dir)=>{ + if (dir && dir != MY_STORAGE){ + onChange?.(dir + ':' + decodeURI(fileName)); + }else{ + onChange?.(decodeURI(fileName)); + } inpRef.current.focus(); }); }; diff --git a/web/pgadmin/utils/__init__.py b/web/pgadmin/utils/__init__.py index 733cb0c53..e25fbf79b 100644 --- a/web/pgadmin/utils/__init__.py +++ b/web/pgadmin/utils/__init__.py @@ -11,6 +11,7 @@ import os import sys import json import subprocess +import re from collections import defaultdict from operator import attrgetter @@ -211,6 +212,25 @@ else: return os.path.realpath(os.path.expanduser('~/')) +def get_directory_and_file_name(drivefilepath): + """ + Returns directory name if specified and file name + :param drivefilepath: file path like ':/filename' or + '/filename' + :return: directory name and file name + """ + dir_name = '' + file_name = drivefilepath + if config.SHARED_STORAGE: + shared_dirs = [sdir['name'] + ':' for sdir in config.SHARED_STORAGE] + if len(re.findall(r"(?=(" + '|'.join(shared_dirs) + r"))", + drivefilepath)) > 0: + dir_file_paths = drivefilepath.split(':/') + dir_name = dir_file_paths[0] + file_name = dir_file_paths[1] + return dir_name, file_name + + def get_complete_file_path(file, validate=True): """ Args: @@ -226,7 +246,11 @@ def get_complete_file_path(file, validate=True): if current_app.PGADMIN_RUNTIME or not current_app.config['SERVER_MODE']: return file if os.path.isfile(file) else None - storage_dir = get_storage_directory() + # get dir name and file name + dir_name, file = get_directory_and_file_name(file) + + storage_dir = get_storage_directory(shared_storage=dir_name) if dir_name \ + else get_storage_directory() if storage_dir: file = os.path.join( storage_dir, @@ -246,12 +270,15 @@ def filename_with_file_manager_path(_file, create_file=False, skip_permission_check=False): """ Args: - file: File name returned from client file manager + _file: File name returned from client file manager create_file: Set flag to False when file creation doesn't require skip_permission_check: Returns: Filename to use for backup with full path taken from preference """ + # get dir name and file name + _dir_name, _file = get_directory_and_file_name(_file) + # retrieve storage directory path try: last_storage = Preferences.module('file_manager').preference(