From db0e21f5d940c9670758f987edc1281226f8a868 Mon Sep 17 00:00:00 2001 From: wangruidong <940853815@qq.com> Date: Thu, 28 Aug 2025 17:06:24 +0800 Subject: [PATCH] fix: Lazy import Azure and Google Cloud dependencies --- apps/accounts/backends/azure/service.py | 10 +++++++--- apps/common/storage/jms_storage/azure.py | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/accounts/backends/azure/service.py b/apps/accounts/backends/azure/service.py index 800687ee6..4f5ab0f22 100644 --- a/apps/accounts/backends/azure/service.py +++ b/apps/accounts/backends/azure/service.py @@ -1,8 +1,5 @@ # -*- coding: utf-8 -*- # -from azure.core.exceptions import ResourceNotFoundError, ClientAuthenticationError -from azure.identity import ClientSecretCredential -from azure.keyvault.secrets import SecretClient from common.utils import get_logger @@ -14,6 +11,9 @@ __all__ = ['AZUREVaultClient'] class AZUREVaultClient(object): def __init__(self, vault_url, tenant_id, client_id, client_secret): + from azure.identity import ClientSecretCredential + from azure.keyvault.secrets import SecretClient + authentication_endpoint = 'https://login.microsoftonline.com/' \ if ('azure.net' in vault_url) else 'https://login.chinacloudapi.cn/' @@ -23,6 +23,8 @@ class AZUREVaultClient(object): self.client = SecretClient(vault_url=vault_url, credential=credentials) def is_active(self): + from azure.core.exceptions import ResourceNotFoundError, ClientAuthenticationError + try: self.client.set_secret('jumpserver', '666') except (ResourceNotFoundError, ClientAuthenticationError) as e: @@ -32,6 +34,8 @@ class AZUREVaultClient(object): return True, '' def get(self, name, version=None): + from azure.core.exceptions import ResourceNotFoundError, ClientAuthenticationError + try: secret = self.client.get_secret(name, version) return secret.value diff --git a/apps/common/storage/jms_storage/azure.py b/apps/common/storage/jms_storage/azure.py index 35a686f70..5a0c8b20d 100644 --- a/apps/common/storage/jms_storage/azure.py +++ b/apps/common/storage/jms_storage/azure.py @@ -3,14 +3,14 @@ import os -from azure.storage.blob import BlobServiceClient - from .base import ObjectStorage class AzureStorage(ObjectStorage): def __init__(self, config): + from azure.storage.blob import BlobServiceClient + self.account_name = config.get("ACCOUNT_NAME", None) self.account_key = config.get("ACCOUNT_KEY", None) self.container_name = config.get("CONTAINER_NAME", None)