From d4657dcd32f5abf95b469fdfa8d76855fc60c8fb Mon Sep 17 00:00:00 2001 From: Yogesh Mahajan Date: Tue, 28 Jun 2022 11:28:55 +0530 Subject: [PATCH] Fixed module import issue. refs #7506 --- web/pgacloud/providers/azure.py | 20 ++++++++++++++----- web/pgadmin/misc/cloud/azure/__init__.py | 3 ++- web/pgadmin/misc/cloud/azure/azure_cache.py | 19 ++++++++++-------- .../components/sections/GraphVisualiser.jsx | 5 ++++- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/web/pgacloud/providers/azure.py b/web/pgacloud/providers/azure.py index fbfae9ded..b9fda8f15 100644 --- a/web/pgacloud/providers/azure.py +++ b/web/pgacloud/providers/azure.py @@ -21,6 +21,10 @@ from providers._abstract import AbsProvider import os from utils.io import debug, error, output from utils.misc import get_my_ip, get_random_id +import sys +CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) +root = os.path.dirname(os.path.dirname(CURRENT_PATH)) +sys.path.insert(0, root) from pgadmin.misc.cloud.azure.azure_cache import load_persistent_cache, \ TokenCachePersistenceOptions @@ -59,7 +63,11 @@ class AzureProvider(AbsProvider): self._database_pass = os.environ['AZURE_DATABASE_PASSWORD'] if 'AZURE_CRED_CACHE_NAME' in os.environ: - self.azure_cred_cache_name = os.environ['AZURE_CRED_CACHE_NAME'] + self._azure_cred_cache_name = os.environ['AZURE_CRED_CACHE_NAME'] + + if 'AZURE_CRED_CACHE_LOCATION' in os.environ: + self._azure_cred_cache_location = \ + os.environ['AZURE_CRED_CACHE_LOCATION'] def init_args(self, parsers): """ Create the command line parser for this provider """ @@ -170,8 +178,9 @@ class AzureProvider(AbsProvider): timeout=180, _cache=load_persistent_cache( TokenCachePersistenceOptions( - name=self.azure_cred_cache_name, - allow_unencrypted_storage=True)), + name=self._azure_cred_cache_name, + allow_unencrypted_storage=True, + cache_location=self._azure_cred_cache_location)), authentication_record=deserialized_auth_record) else: _credential = InteractiveBrowserCredential( @@ -179,8 +188,9 @@ class AzureProvider(AbsProvider): timeout=180, _cache=load_persistent_cache( TokenCachePersistenceOptions( - name=self.azure_cred_cache_name, - allow_unencrypted_storage=True)) + name=self._azure_cred_cache_name, + allow_unencrypted_storage=True, + cache_location=self._azure_cred_cache_location)) ) return _credential diff --git a/web/pgadmin/misc/cloud/azure/__init__.py b/web/pgadmin/misc/cloud/azure/__init__.py index 0d49cd666..e29222bc5 100644 --- a/web/pgadmin/misc/cloud/azure/__init__.py +++ b/web/pgadmin/misc/cloud/azure/__init__.py @@ -246,8 +246,8 @@ class Azure: self.subscription_id = None self._availability_zone = None self._available_capabilities_list = [] - self.cache_name = None self.cache_name = current_user.username + "_msal.cache" + self.azure_cache_location = config.AZURE_CREDENTIAL_CACHE_DIR + '/' ########################################################################## # Azure Helper functions @@ -685,6 +685,7 @@ def deploy_on_azure(data): env['AZURE_SUBSCRIPTION_ID'] = azure.subscription_id env['AUTH_TYPE'] = data['secret']['auth_type'] env['AZURE_CRED_CACHE_NAME'] = azure.cache_name + env['AZURE_CRED_CACHE_LOCATION'] = azure.azure_cache_location if azure.authentication_record_json is not None: env['AUTHENTICATION_RECORD_JSON'] = \ azure.authentication_record_json diff --git a/web/pgadmin/misc/cloud/azure/azure_cache.py b/web/pgadmin/misc/cloud/azure/azure_cache.py index 5b0eb9255..c8f3be253 100644 --- a/web/pgadmin/misc/cloud/azure/azure_cache.py +++ b/web/pgadmin/misc/cloud/azure/azure_cache.py @@ -59,6 +59,7 @@ class TokenCachePersistenceOptions(object): self.allow_unencrypted_storage = \ kwargs.get("allow_unencrypted_storage", False) self.name = kwargs.get("name", "msal.cache") + self.cache_location = kwargs.get("cache_location", None) def load_persistent_cache(options): @@ -68,13 +69,14 @@ def load_persistent_cache(options): persistence = _get_persistence( allow_unencrypted=options.allow_unencrypted_storage, account_name="MSALCache", - cache_name=options.name + cache_name=options.name, + cache_location=options.cache_location ) return msal_extensions.PersistedTokenCache(persistence) -def _get_persistence(allow_unencrypted, account_name, cache_name): - # type: (bool, str, str) -> msal_extensions.persistence.BasePersistence +def _get_persistence( + allow_unencrypted, account_name, cache_name, cache_location): """Get an msal_extensions persistence instance for the current platform. On Windows the cache is a file protected by the Data Protection API. @@ -88,18 +90,19 @@ def _get_persistence(allow_unencrypted, account_name, cache_name): current environment """ import msal_extensions - cache_location = \ - os.path.join(config.AZURE_CREDENTIAL_CACHE_DIR, cache_name) + if cache_location is None: + cache_location = config.AZURE_CREDENTIAL_CACHE_DIR + '/' + cache_file_path = os.path.join(cache_location, cache_name) if sys.platform.startswith("win") and "LOCALAPPDATA" in os.environ: return \ - msal_extensions.FilePersistenceWithDataProtection(cache_location) + msal_extensions.FilePersistenceWithDataProtection(cache_file_path) if sys.platform.startswith("darwin"): # the cache uses this file's modified timestamp # to decide whether to reload return msal_extensions.KeychainPersistence( - cache_location, + cache_file_path, "Microsoft.Developer.IdentityService", account_name) @@ -130,7 +133,7 @@ def _get_persistence(allow_unencrypted, account_name, cache_name): " instead of raising this exception." ) six.raise_from(error, ex) - return msal_extensions.FilePersistence(cache_location) + return msal_extensions.FilePersistence(cache_file_path) raise NotImplementedError("A persistent cache is not " "available in this environment.") diff --git a/web/pgadmin/tools/sqleditor/static/js/components/sections/GraphVisualiser.jsx b/web/pgadmin/tools/sqleditor/static/js/components/sections/GraphVisualiser.jsx index c93e81fe8..5b41998da 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/sections/GraphVisualiser.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/sections/GraphVisualiser.jsx @@ -253,6 +253,10 @@ export function GraphVisualiser({initColumns}) { const onGenerate = async ()=>{ setLoaderText(gettext('Fetching all the records...')); + if (graphData?.datasets?.length > 0) { + onResetZoom(); + } + let url = url_for('sqleditor.fetch_all_from_start', { 'trans_id': queryToolCtx.params.trans_id, 'limit': queryToolCtx.preferences.sqleditor.row_limit @@ -266,7 +270,6 @@ export function GraphVisualiser({initColumns}) { getGraphDataSet(res.data.data.result, columns, xaxis, yaxis, queryToolCtx) ); - onResetZoom(); setLoaderText(''); };