Compare commits

...

9 Commits

Author SHA1 Message Date
CZJCC df8f9d2dcd
Merge pull request #237 from Sunrisea/master-fix-login-bug
Fix bug of Inject security info
2025-07-17 19:08:17 +08:00
濯光 4600b89e45 fix bug of get_access_token 2025-07-17 19:00:22 +08:00
濯光 ce22e6a437 fix bug of get_access_token 2025-07-17 18:51:14 +08:00
CZJCC b3c26c7ba9
Merge pull request #235 from Sunrisea/master-fix-deadlock-bug
[ISSUE #233] Fix bug of deadlock and v1 config publish
2025-07-02 15:25:43 +08:00
濯光 cb17109542 fix bug of deadlock and v1 config publish 2025-07-02 14:39:16 +08:00
CZJCC 1892ebbe43
Merge pull request #232 from CZJCC/feature/v2-readme
fix typeing.Dict
2025-05-06 16:59:19 +08:00
CZJCC bcdda37351 fix typeing.Dict 2025-05-06 16:57:26 +08:00
CZJCC d3f9b0daec
Merge pull request #231 from CZJCC/feature/v2-readme
fix 安装命令
2025-05-06 16:34:42 +08:00
CZJCC 95236b1643 fix 安装命令 2025-05-06 16:32:33 +08:00
9 changed files with 22 additions and 19 deletions

View File

@ -18,7 +18,7 @@ Supported Nacos version over 2.x
## Installation ## Installation
```shell ```shell
pip install nacos-sdk-python==2.0.3 pip install nacos-sdk-python
``` ```
## Client Configuration ## Client Configuration

View File

@ -425,7 +425,7 @@ class NacosClient:
params["type"] = config_type params["type"] = config_type
try: try:
resp = self._do_sync_req("/nacos/v1/cs/configs", None, params, None, resp = self._do_sync_req("/nacos/v1/cs/configs", None, None, params,
timeout or self.default_timeout, "POST") timeout or self.default_timeout, "POST")
c = resp.read() c = resp.read()
logger.info("[publish] publish content, group:%s, data_id:%s, server response:%s" % ( logger.info("[publish] publish content, group:%s, data_id:%s, server response:%s" % (

View File

@ -1,6 +1,6 @@
import asyncio import asyncio
from logging import Logger from logging import Logger
from typing import Optional, Callable, List from typing import Optional, Callable, List, Dict
from v2.nacos.common.constants import Constants from v2.nacos.common.constants import Constants
from v2.nacos.config.cache.config_info_cache import ConfigInfoCache from v2.nacos.config.cache.config_info_cache import ConfigInfoCache
@ -15,7 +15,7 @@ class ConfigSubscribeManager:
def __init__(self, logger: Logger, config_info_cache: ConfigInfoCache, namespace_id: str, def __init__(self, logger: Logger, config_info_cache: ConfigInfoCache, namespace_id: str,
config_filter_chain_manager: ConfigFilterChainManager, config_filter_chain_manager: ConfigFilterChainManager,
execute_config_listen_channel: asyncio.Queue): execute_config_listen_channel: asyncio.Queue):
self.subscribe_cache_map: dict[str, SubscribeCacheData] = {} self.subscribe_cache_map: Dict[str, SubscribeCacheData] = {}
self.logger = logger self.logger = logger
self.lock = asyncio.Lock() self.lock = asyncio.Lock()
self.namespace_id = namespace_id self.namespace_id = namespace_id
@ -87,7 +87,7 @@ class ConfigSubscribeManager:
await subscribe_cache.execute_listener() await subscribe_cache.execute_listener()
async def execute_listener_and_build_tasks(self, is_sync_all: bool): async def execute_listener_and_build_tasks(self, is_sync_all: bool):
listen_fetch_task_map: dict[int, List[SubscribeCacheData]] = {} listen_fetch_task_map: Dict[int, List[SubscribeCacheData]] = {}
for cache_data in self.subscribe_cache_map.values(): for cache_data in self.subscribe_cache_map.values():
if cache_data.is_sync_with_server: if cache_data.is_sync_with_server:
await cache_data.execute_listener() await cache_data.execute_listener()

View File

@ -1,3 +1,5 @@
from typing import Dict
from v2.nacos.common.client_config import KMSConfig from v2.nacos.common.client_config import KMSConfig
from v2.nacos.common.constants import Constants from v2.nacos.common.constants import Constants
from v2.nacos.common.nacos_exception import NacosException, INVALID_PARAM from v2.nacos.common.nacos_exception import NacosException, INVALID_PARAM
@ -11,7 +13,7 @@ from v2.nacos.config.model.config_param import HandlerParam
class KMSHandler: class KMSHandler:
def __init__(self, kms_config: KMSConfig): def __init__(self, kms_config: KMSConfig):
self.kms_plugins: dict[str, EncryptionPlugin] = {} self.kms_plugins: Dict[str, EncryptionPlugin] = {}
self.kms_client = KmsClient.create_kms_client(kms_config) self.kms_client = KmsClient.create_kms_client(kms_config)
kms_aes_128_encryption_plugin = KmsAes128EncryptionPlugin(self.kms_client) kms_aes_128_encryption_plugin = KmsAes128EncryptionPlugin(self.kms_client)
self.kms_plugins[kms_aes_128_encryption_plugin.algorithm_name()] = kms_aes_128_encryption_plugin self.kms_plugins[kms_aes_128_encryption_plugin.algorithm_name()] = kms_aes_128_encryption_plugin

View File

@ -1,5 +1,5 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Optional, List from typing import Optional, List, Dict
from v2.nacos.config.model.config import ConfigListenContext from v2.nacos.config.model.config import ConfigListenContext
from v2.nacos.transport.model.rpc_request import Request from v2.nacos.transport.model.rpc_request import Request
@ -46,7 +46,7 @@ class ConfigQueryRequest(AbstractConfigRequest):
class ConfigPublishRequest(AbstractConfigRequest): class ConfigPublishRequest(AbstractConfigRequest):
content: Optional[str] content: Optional[str]
casMd5: Optional[str] casMd5: Optional[str]
additionMap: dict[str, str] = {} additionMap: Dict[str, str] = {}
def get_request_type(self): def get_request_type(self):
return "ConfigPublishRequest" return "ConfigPublishRequest"

View File

@ -2,7 +2,7 @@ import asyncio
import json import json
import logging import logging
import os import os
from typing import Callable, Optional, List from typing import Callable, Optional, List, Dict
from v2.nacos.common.client_config import ClientConfig from v2.nacos.common.client_config import ClientConfig
from v2.nacos.common.constants import Constants from v2.nacos.common.constants import Constants
@ -18,7 +18,7 @@ class ServiceInfoCache:
def __init__(self, client_config: ClientConfig): def __init__(self, client_config: ClientConfig):
self.logger = logging.getLogger(Constants.NAMING_MODULE) self.logger = logging.getLogger(Constants.NAMING_MODULE)
self.cache_dir = os.path.join(client_config.cache_dir, Constants.NAMING_MODULE, client_config.namespace_id) self.cache_dir = os.path.join(client_config.cache_dir, Constants.NAMING_MODULE, client_config.namespace_id)
self.service_info_map: dict[str, Service] = {} self.service_info_map: Dict[str, Service] = {}
self.update_time_map = {} self.update_time_map = {}
self.lock = asyncio.Lock() self.lock = asyncio.Lock()
self.sub_callback_manager = SubscribeManager() self.sub_callback_manager = SubscribeManager()

View File

@ -1,4 +1,4 @@
from typing import Optional, Callable, List from typing import Optional, Callable, List, Dict
from pydantic import BaseModel from pydantic import BaseModel
from v2.nacos.common.constants import Constants from v2.nacos.common.constants import Constants
@ -10,7 +10,7 @@ class RegisterInstanceParam(BaseModel):
weight: float = 1.0 weight: float = 1.0
enabled: bool = True enabled: bool = True
healthy: bool = True healthy: bool = True
metadata: dict[str, str] = {} metadata: Dict[str, str] = {}
cluster_name: str = '' cluster_name: str = ''
service_name: str service_name: str
group_name: str = Constants.DEFAULT_GROUP group_name: str = Constants.DEFAULT_GROUP

View File

@ -94,4 +94,6 @@ class NacosServerConnector:
async def inject_security_info(self, headers): async def inject_security_info(self, headers):
if self.client_config.username and self.client_config.password: if self.client_config.username and self.client_config.password:
access_token = await self.auth_client.get_access_token(False) access_token = await self.auth_client.get_access_token(False)
headers[Constants.ACCESS_TOKEN] = access_token if access_token is not None and access_token != "":
headers[Constants.ACCESS_TOKEN] = access_token
return

View File

@ -70,7 +70,7 @@ class RpcClient(ABC):
def __init__(self, logger, name: str, nacos_server: NacosServerConnector): def __init__(self, logger, name: str, nacos_server: NacosServerConnector):
self.logger = logger self.logger = logger
self.name = name self.name = name
self.labels: dict[str, str] = {} self.labels: Dict[str, str] = {}
self.current_connection = None self.current_connection = None
self.rpc_client_status = RpcClientStatus.INITIALIZED self.rpc_client_status = RpcClientStatus.INITIALIZED
self.event_chan = asyncio.Queue() self.event_chan = asyncio.Queue()
@ -137,11 +137,10 @@ class RpcClient(ABC):
self.logger.error("%s server healthy check fail, currentConnection=%s" self.logger.error("%s server healthy check fail, currentConnection=%s"
, self.name, self.current_connection.get_connection_id()) , self.name, self.current_connection.get_connection_id())
async with self.lock: if self.rpc_client_status == RpcClientStatus.SHUTDOWN:
if self.rpc_client_status == RpcClientStatus.SHUTDOWN: continue
continue self.rpc_client_status = RpcClientStatus.UNHEALTHY
self.rpc_client_status = RpcClientStatus.UNHEALTHY await self.reconnect(ReconnectContext(server_info=None, on_request_fail=False))
await self.reconnect(ReconnectContext(server_info=None, on_request_fail=False))
except asyncio.CancelledError: except asyncio.CancelledError:
break break
except asyncio.CancelledError: except asyncio.CancelledError: