Fixed module import issue.

refs #7506
This commit is contained in:
Yogesh Mahajan 2022-06-28 11:28:55 +05:30 committed by Akshay Joshi
parent f905dc07cf
commit d4657dcd32
4 changed files with 32 additions and 15 deletions

View File

@ -21,6 +21,10 @@ from providers._abstract import AbsProvider
import os import os
from utils.io import debug, error, output from utils.io import debug, error, output
from utils.misc import get_my_ip, get_random_id 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, \ from pgadmin.misc.cloud.azure.azure_cache import load_persistent_cache, \
TokenCachePersistenceOptions TokenCachePersistenceOptions
@ -59,7 +63,11 @@ class AzureProvider(AbsProvider):
self._database_pass = os.environ['AZURE_DATABASE_PASSWORD'] self._database_pass = os.environ['AZURE_DATABASE_PASSWORD']
if 'AZURE_CRED_CACHE_NAME' in os.environ: 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): def init_args(self, parsers):
""" Create the command line parser for this provider """ """ Create the command line parser for this provider """
@ -170,8 +178,9 @@ class AzureProvider(AbsProvider):
timeout=180, timeout=180,
_cache=load_persistent_cache( _cache=load_persistent_cache(
TokenCachePersistenceOptions( TokenCachePersistenceOptions(
name=self.azure_cred_cache_name, name=self._azure_cred_cache_name,
allow_unencrypted_storage=True)), allow_unencrypted_storage=True,
cache_location=self._azure_cred_cache_location)),
authentication_record=deserialized_auth_record) authentication_record=deserialized_auth_record)
else: else:
_credential = InteractiveBrowserCredential( _credential = InteractiveBrowserCredential(
@ -179,8 +188,9 @@ class AzureProvider(AbsProvider):
timeout=180, timeout=180,
_cache=load_persistent_cache( _cache=load_persistent_cache(
TokenCachePersistenceOptions( TokenCachePersistenceOptions(
name=self.azure_cred_cache_name, name=self._azure_cred_cache_name,
allow_unencrypted_storage=True)) allow_unencrypted_storage=True,
cache_location=self._azure_cred_cache_location))
) )
return _credential return _credential

View File

@ -246,8 +246,8 @@ class Azure:
self.subscription_id = None self.subscription_id = None
self._availability_zone = None self._availability_zone = None
self._available_capabilities_list = [] self._available_capabilities_list = []
self.cache_name = None
self.cache_name = current_user.username + "_msal.cache" self.cache_name = current_user.username + "_msal.cache"
self.azure_cache_location = config.AZURE_CREDENTIAL_CACHE_DIR + '/'
########################################################################## ##########################################################################
# Azure Helper functions # Azure Helper functions
@ -685,6 +685,7 @@ def deploy_on_azure(data):
env['AZURE_SUBSCRIPTION_ID'] = azure.subscription_id env['AZURE_SUBSCRIPTION_ID'] = azure.subscription_id
env['AUTH_TYPE'] = data['secret']['auth_type'] env['AUTH_TYPE'] = data['secret']['auth_type']
env['AZURE_CRED_CACHE_NAME'] = azure.cache_name 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: if azure.authentication_record_json is not None:
env['AUTHENTICATION_RECORD_JSON'] = \ env['AUTHENTICATION_RECORD_JSON'] = \
azure.authentication_record_json azure.authentication_record_json

View File

@ -59,6 +59,7 @@ class TokenCachePersistenceOptions(object):
self.allow_unencrypted_storage = \ self.allow_unencrypted_storage = \
kwargs.get("allow_unencrypted_storage", False) kwargs.get("allow_unencrypted_storage", False)
self.name = kwargs.get("name", "msal.cache") self.name = kwargs.get("name", "msal.cache")
self.cache_location = kwargs.get("cache_location", None)
def load_persistent_cache(options): def load_persistent_cache(options):
@ -68,13 +69,14 @@ def load_persistent_cache(options):
persistence = _get_persistence( persistence = _get_persistence(
allow_unencrypted=options.allow_unencrypted_storage, allow_unencrypted=options.allow_unencrypted_storage,
account_name="MSALCache", account_name="MSALCache",
cache_name=options.name cache_name=options.name,
cache_location=options.cache_location
) )
return msal_extensions.PersistedTokenCache(persistence) return msal_extensions.PersistedTokenCache(persistence)
def _get_persistence(allow_unencrypted, account_name, cache_name): def _get_persistence(
# type: (bool, str, str) -> msal_extensions.persistence.BasePersistence allow_unencrypted, account_name, cache_name, cache_location):
"""Get an msal_extensions persistence instance for the current platform. """Get an msal_extensions persistence instance for the current platform.
On Windows the cache is a file protected by the Data Protection API. 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 current environment
""" """
import msal_extensions import msal_extensions
cache_location = \ if cache_location is None:
os.path.join(config.AZURE_CREDENTIAL_CACHE_DIR, cache_name) 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: if sys.platform.startswith("win") and "LOCALAPPDATA" in os.environ:
return \ return \
msal_extensions.FilePersistenceWithDataProtection(cache_location) msal_extensions.FilePersistenceWithDataProtection(cache_file_path)
if sys.platform.startswith("darwin"): if sys.platform.startswith("darwin"):
# the cache uses this file's modified timestamp # the cache uses this file's modified timestamp
# to decide whether to reload # to decide whether to reload
return msal_extensions.KeychainPersistence( return msal_extensions.KeychainPersistence(
cache_location, cache_file_path,
"Microsoft.Developer.IdentityService", "Microsoft.Developer.IdentityService",
account_name) account_name)
@ -130,7 +133,7 @@ def _get_persistence(allow_unencrypted, account_name, cache_name):
" instead of raising this exception." " instead of raising this exception."
) )
six.raise_from(error, ex) 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 " raise NotImplementedError("A persistent cache is not "
"available in this environment.") "available in this environment.")

View File

@ -253,6 +253,10 @@ export function GraphVisualiser({initColumns}) {
const onGenerate = async ()=>{ const onGenerate = async ()=>{
setLoaderText(gettext('Fetching all the records...')); setLoaderText(gettext('Fetching all the records...'));
if (graphData?.datasets?.length > 0) {
onResetZoom();
}
let url = url_for('sqleditor.fetch_all_from_start', { let url = url_for('sqleditor.fetch_all_from_start', {
'trans_id': queryToolCtx.params.trans_id, 'trans_id': queryToolCtx.params.trans_id,
'limit': queryToolCtx.preferences.sqleditor.row_limit 'limit': queryToolCtx.preferences.sqleditor.row_limit
@ -266,7 +270,6 @@ export function GraphVisualiser({initColumns}) {
getGraphDataSet(res.data.data.result, columns, xaxis, yaxis, queryToolCtx) getGraphDataSet(res.data.data.result, columns, xaxis, yaxis, queryToolCtx)
); );
onResetZoom();
setLoaderText(''); setLoaderText('');
}; };