mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-23 15:03:26 -06:00
parent
f905dc07cf
commit
d4657dcd32
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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.")
|
||||
|
@ -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('');
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user