nacos-sdk-python 2.0.0b5__tar.gz → 2.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/PKG-INFO +6 -4
  2. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/README.md +5 -3
  3. nacos-sdk-python-2.0.2/nacos/auth.py +26 -0
  4. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos/client.py +48 -39
  5. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos_sdk_python.egg-info/PKG-INFO +6 -4
  6. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos_sdk_python.egg-info/SOURCES.txt +2 -0
  7. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/setup.py +1 -1
  8. nacos-sdk-python-2.0.2/v2/nacos/common/auth.py +32 -0
  9. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/common/client_config.py +3 -3
  10. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/common/client_config_builder.py +13 -2
  11. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/remote/config_grpc_client_proxy.py +6 -3
  12. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/remote/naming_grpc_client_proxy.py +6 -3
  13. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/grpc_client.py +8 -4
  14. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/model/internal_request.py +0 -4
  15. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/nacos_server_connector.py +3 -0
  16. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/rpc_client.py +1 -1
  17. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos/__init__.py +0 -0
  18. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos/commons.py +0 -0
  19. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos/exception.py +0 -0
  20. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos/files.py +0 -0
  21. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos/listener.py +0 -0
  22. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos/params.py +0 -0
  23. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos/task.py +0 -0
  24. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos/timer.py +0 -0
  25. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos_sdk_python.egg-info/dependency_links.txt +0 -0
  26. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos_sdk_python.egg-info/requires.txt +0 -0
  27. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/nacos_sdk_python.egg-info/top_level.txt +0 -0
  28. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/setup.cfg +0 -0
  29. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/__init__.py +0 -0
  30. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/__init__.py +0 -0
  31. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/common/__init__.py +0 -0
  32. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/common/constants.py +0 -0
  33. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/common/nacos_exception.py +0 -0
  34. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/common/payload_registry.py +0 -0
  35. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/common/preserved_metadata_key.py +0 -0
  36. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/__init__.py +0 -0
  37. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/cache/__init__.py +0 -0
  38. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/cache/config_info_cache.py +0 -0
  39. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/cache/config_subscribe_manager.py +0 -0
  40. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/encryption/__init__.py +0 -0
  41. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/encryption/kms_client.py +0 -0
  42. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/encryption/kms_handler.py +0 -0
  43. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/encryption/plugin/__init__.py +0 -0
  44. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/encryption/plugin/encryption_plugin.py +0 -0
  45. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/encryption/plugin/kms_aes_128_encrytion_plugin.py +0 -0
  46. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/encryption/plugin/kms_aes_256_encrytion_plugin.py +0 -0
  47. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/encryption/plugin/kms_base_encryption_plugin.py +0 -0
  48. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/encryption/plugin/kms_encrytion_plugin.py +0 -0
  49. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/filter/__init__.py +0 -0
  50. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/filter/config_encryption_filter.py +0 -0
  51. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/filter/config_filter.py +0 -0
  52. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/model/__init__.py +0 -0
  53. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/model/config.py +0 -0
  54. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/model/config_param.py +0 -0
  55. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/model/config_request.py +0 -0
  56. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/model/config_response.py +0 -0
  57. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/nacos_config_service.py +0 -0
  58. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/remote/__init__.py +0 -0
  59. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/remote/config_change_notify_request_handler.py +0 -0
  60. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/remote/config_grpc_connection_event_listener.py +0 -0
  61. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/util/__init__.py +0 -0
  62. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/config/util/config_client_util.py +0 -0
  63. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/nacos_client.py +0 -0
  64. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/__init__.py +0 -0
  65. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/cache/__init__.py +0 -0
  66. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/cache/service_info_cache.py +0 -0
  67. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/cache/subscribe_manager.py +0 -0
  68. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/event/__init__.py +0 -0
  69. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/event/instance_change_notifier.py +0 -0
  70. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/model/__init__.py +0 -0
  71. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/model/instance.py +0 -0
  72. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/model/naming_param.py +0 -0
  73. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/model/naming_request.py +0 -0
  74. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/model/naming_response.py +0 -0
  75. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/model/service.py +0 -0
  76. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/nacos_naming_service.py +0 -0
  77. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/remote/__init__.py +0 -0
  78. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/remote/naming_grpc_connection_event_listener.py +0 -0
  79. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/remote/naming_push_request_handler.py +0 -0
  80. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/util/__init__.py +0 -0
  81. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/util/naming_client_util.py +0 -0
  82. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/naming/util/naming_remote_constants.py +0 -0
  83. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/proto/__init__.py +0 -0
  84. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/__init__.py +0 -0
  85. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/auth_client.py +0 -0
  86. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/connection.py +0 -0
  87. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/connection_event_listener.py +0 -0
  88. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/grpc_connection.py +0 -0
  89. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/grpc_util.py +0 -0
  90. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/grpcauto/__init__.py +0 -0
  91. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/grpcauto/nacos_grpc_service_pb2.py +0 -0
  92. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/grpcauto/nacos_grpc_service_pb2_grpc.py +0 -0
  93. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/http_agent.py +0 -0
  94. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/model/__init__.py +0 -0
  95. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/model/internal_response.py +0 -0
  96. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/model/rpc_request.py +0 -0
  97. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/model/rpc_response.py +0 -0
  98. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/model/server_info.py +0 -0
  99. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/rpc_client_factory.py +0 -0
  100. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/transport/server_request_handler.py +0 -0
  101. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/utils/__init__.py +0 -0
  102. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/utils/aes_util.py +0 -0
  103. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/utils/common_util.py +0 -0
  104. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/utils/content_util.py +0 -0
  105. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/utils/encode_util.py +0 -0
  106. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/utils/file_util.py +0 -0
  107. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/utils/hmac_util.py +0 -0
  108. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/utils/md5_util.py +0 -0
  109. {nacos-sdk-python-2.0.0b5 → nacos-sdk-python-2.0.2}/v2/nacos/utils/net_util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nacos-sdk-python
3
- Version: 2.0.0b5
3
+ Version: 2.0.2
4
4
  Summary: Python client for Nacos.
5
5
  Home-page: https://github.com/nacos-group/nacos-sdk-python
6
6
  Author: nacos
@@ -68,6 +68,7 @@ Description:
68
68
  * *namespace* - Namespace. | default: `None`
69
69
  * *ak* - The accessKey to authenticate. | default: null
70
70
  * *sk* - The secretKey to authentication. | default: null
71
+ * *credentials_provider* - The custom access key manager | default: null
71
72
  * *log_level* - Log level. | default: null
72
73
  * *log_rotation_backup_count* - The number of log files to keep. | default: `7`
73
74
 
@@ -249,9 +250,9 @@ Description:
249
250
 
250
251
  ### Subscribe Service Instances Changed
251
252
 
252
- > `NacosClient.subscribe(listener_fn, listener_interval=7, *args, **kwargs)`
253
+ >`NacosClient.subscribe(listener_fn, listener_interval=7, *args, **kwargs)`
253
254
 
254
- * `param` *listener_fn* **required** Customized listener function.
255
+ * `param` *listener_fn* **required** Customized listener function. with signature `fn_listener1(event, instance)->None`
255
256
  * `param` *listener_interval* Listen interval , default 7 second.
256
257
  * `param` *service_name* **required** Service name which subscribes.
257
258
  * `param` *clusters* Cluster names separated by comma.
@@ -304,7 +305,7 @@ Description:
304
305
  ## Installation
305
306
 
306
307
  ```shell
307
- pip install nacos-sdk-python==2.0.0b4
308
+ pip install nacos-sdk-python==2.0.0b5
308
309
  ```
309
310
 
310
311
  ## Client Configuration
@@ -326,6 +327,7 @@ Description:
326
327
  * *server_address* - **required** - Nacos server address
327
328
  * *access_key* - The aliyun accessKey to authenticate.
328
329
  * *secret_key* - The aliyun secretKey to authenticate.
330
+ * *credentials_provider* - The custom access key manager.
329
331
  * *username* - The username to authenticate.
330
332
  * *password* - The password to authenticate.
331
333
  * *log_level* - Log level | default: `logging.INFO`
@@ -56,6 +56,7 @@ client = NacosClient(server_addresses, namespace=your_ns, ak=your_ak, sk=your_sk
56
56
  * *namespace* - Namespace. | default: `None`
57
57
  * *ak* - The accessKey to authenticate. | default: null
58
58
  * *sk* - The secretKey to authentication. | default: null
59
+ * *credentials_provider* - The custom access key manager | default: null
59
60
  * *log_level* - Log level. | default: null
60
61
  * *log_rotation_backup_count* - The number of log files to keep. | default: `7`
61
62
 
@@ -237,9 +238,9 @@ Remove one data item from Nacos.
237
238
 
238
239
  ### Subscribe Service Instances Changed
239
240
 
240
- > `NacosClient.subscribe(listener_fn, listener_interval=7, *args, **kwargs)`
241
+ >`NacosClient.subscribe(listener_fn, listener_interval=7, *args, **kwargs)`
241
242
 
242
- * `param` *listener_fn* **required** Customized listener function.
243
+ * `param` *listener_fn* **required** Customized listener function. with signature `fn_listener1(event, instance)->None`
243
244
  * `param` *listener_interval* Listen interval , default 7 second.
244
245
  * `param` *service_name* **required** Service name which subscribes.
245
246
  * `param` *clusters* Cluster names separated by comma.
@@ -292,7 +293,7 @@ Supported Nacos version over 2.x
292
293
  ## Installation
293
294
 
294
295
  ```shell
295
- pip install nacos-sdk-python==2.0.0b4
296
+ pip install nacos-sdk-python==2.0.0b5
296
297
  ```
297
298
 
298
299
  ## Client Configuration
@@ -314,6 +315,7 @@ client_config = (ClientConfigBuilder()
314
315
  * *server_address* - **required** - Nacos server address
315
316
  * *access_key* - The aliyun accessKey to authenticate.
316
317
  * *secret_key* - The aliyun secretKey to authenticate.
318
+ * *credentials_provider* - The custom access key manager.
317
319
  * *username* - The username to authenticate.
318
320
  * *password* - The password to authenticate.
319
321
  * *log_level* - Log level | default: `logging.INFO`
@@ -0,0 +1,26 @@
1
+ class Credentials(object):
2
+ def __init__(self, access_key_id, access_key_secret, security_token=None):
3
+ self.access_key_id = access_key_id
4
+ self.access_key_secret = access_key_secret
5
+ self.security_token = security_token
6
+
7
+ def get_access_key_id(self):
8
+ return self.access_key_id
9
+
10
+ def get_access_key_secret(self):
11
+ return self.access_key_secret
12
+
13
+ def get_security_token(self):
14
+ return self.security_token
15
+
16
+ class CredentialsProvider(object):
17
+ def get_credentials(self):
18
+ return
19
+
20
+
21
+ class StaticCredentialsProvider(CredentialsProvider):
22
+ def __init__(self, access_key_id="", access_key_secret="", security_token=""):
23
+ self.credentials = Credentials(access_key_id, access_key_secret, security_token)
24
+
25
+ def get_credentials(self):
26
+ return self.credentials
@@ -14,6 +14,7 @@ from logging.handlers import TimedRotatingFileHandler
14
14
  from typing import Dict
15
15
 
16
16
  from .task import HeartbeatInfo, HeartbeatTask
17
+ from .auth import StaticCredentialsProvider
17
18
 
18
19
  try:
19
20
  import ssl
@@ -276,7 +277,8 @@ class NacosClient:
276
277
  logger.propagate = False
277
278
 
278
279
  def __init__(self, server_addresses=None, endpoint=None, namespace=None, ak=None,
279
- sk=None, username=None, password=None, logDir=None, log_level=None, log_rotation_backup_count=None):
280
+ sk=None, username=None, password=None, logDir=None, log_level=None,
281
+ log_rotation_backup_count=None, credentials_provider=None):
280
282
  self.server_list = list()
281
283
  self.initLog(logDir, log_level, log_rotation_backup_count)
282
284
  try:
@@ -308,8 +310,7 @@ class NacosClient:
308
310
 
309
311
  self.endpoint = endpoint
310
312
  self.namespace = namespace or DEFAULT_NAMESPACE or ""
311
- self.ak = ak
312
- self.sk = sk
313
+ self.credentials_provider = credentials_provider if credentials_provider else StaticCredentialsProvider(ak, sk)
313
314
  self.username = username
314
315
  self.password = password
315
316
 
@@ -330,7 +331,8 @@ class NacosClient:
330
331
  self.process_mgr = None
331
332
 
332
333
  self.default_timeout = DEFAULTS["TIMEOUT"]
333
- self.auth_enabled = self.ak and self.sk
334
+ credentials = self.credentials_provider.get_credentials()
335
+ self.auth_enabled = credentials.get_access_key_id() and credentials.get_access_key_secret()
334
336
  self.cai_enabled = True
335
337
  self.pulling_timeout = DEFAULTS["PULLING_TIMEOUT"]
336
338
  self.pulling_config_size = DEFAULTS["PULLING_CONFIG_SIZE"]
@@ -747,6 +749,7 @@ class NacosClient:
747
749
  cache_pool[cache_key] = CacheData(cache_key, self)
748
750
 
749
751
  while cache_list:
752
+ time.sleep(1)
750
753
  unused_keys = set(cache_pool.keys())
751
754
  contains_init_key = False
752
755
  probe_update_string = ""
@@ -784,10 +787,8 @@ class NacosClient:
784
787
  logger.info("[do-pulling] following keys are changed from server %s" % truncate(str(changed_keys)))
785
788
  except NacosException as e:
786
789
  logger.error("[do-pulling] nacos exception: %s, waiting for recovery" % str(e))
787
- time.sleep(1)
788
790
  except Exception as e:
789
791
  logger.exception("[do-pulling] exception %s occur, return empty list, waiting for recovery" % str(e))
790
- time.sleep(1)
791
792
 
792
793
  for cache_key, cache_data in cache_pool.items():
793
794
  cache_data.is_init = False
@@ -813,35 +814,38 @@ class NacosClient:
813
814
  logger.info("[init-pulling] init completed")
814
815
 
815
816
  def _process_polling_result(self):
816
- while True:
817
- cache_key, content, md5 = self.notify_queue.get()
818
- logger.info("[process-polling-result] receive an event:%s" % cache_key)
819
- wl = self.watcher_mapping.get(cache_key)
820
- if not wl:
821
- logger.warning("[process-polling-result] no watcher on %s, ignored" % cache_key)
822
- continue
817
+ try:
818
+ while True:
819
+ cache_key, content, md5 = self.notify_queue.get()
820
+ logger.info("[process-polling-result] receive an event:%s" % cache_key)
821
+ wl = self.watcher_mapping.get(cache_key)
822
+ if not wl:
823
+ logger.warning("[process-polling-result] no watcher on %s, ignored" % cache_key)
824
+ continue
823
825
 
824
- data_id, group, namespace = parse_key(cache_key)
825
- plain_content = content
826
-
827
- params = {
828
- "data_id": data_id,
829
- "group": group,
830
- "namespace": namespace,
831
- "raw_content": content,
832
- "content": plain_content,
833
- }
834
- for watcher in wl:
835
- if not watcher.last_md5 == md5:
836
- logger.info(
837
- "[process-polling-result] md5 changed since last call, calling %s with changed md5: %s ,params: %s"
838
- % (watcher.callback.__name__, md5, params))
839
- try:
840
- self.callback_tread_pool.apply(watcher.callback, (params,))
841
- except Exception as e:
842
- logger.exception("[process-polling-result] exception %s occur while calling %s " % (
843
- str(e), watcher.callback.__name__))
844
- watcher.last_md5 = md5
826
+ data_id, group, namespace = parse_key(cache_key)
827
+ plain_content = content
828
+
829
+ params = {
830
+ "data_id": data_id,
831
+ "group": group,
832
+ "namespace": namespace,
833
+ "raw_content": content,
834
+ "content": plain_content,
835
+ }
836
+ for watcher in wl:
837
+ if not watcher.last_md5 == md5:
838
+ logger.info(
839
+ "[process-polling-result] md5 changed since last call, calling %s with changed md5: %s ,params: %s"
840
+ % (watcher.callback.__name__, md5, params))
841
+ try:
842
+ self.callback_tread_pool.apply(watcher.callback, (params,))
843
+ except Exception as e:
844
+ logger.exception("[process-polling-result] exception %s occur while calling %s " % (
845
+ str(e), watcher.callback.__name__))
846
+ watcher.last_md5 = md5
847
+ except (EOFError, OSError) as e:
848
+ logger.exception(f"[process-polling-result] break when receive exception of {type(e)}")
845
849
 
846
850
  @staticmethod
847
851
  def _inject_version_info(headers):
@@ -884,7 +888,8 @@ class NacosClient:
884
888
  if not params and not data:
885
889
  return
886
890
  ts = str(int(time.time() * 1000))
887
- ak, sk = self.ak, self.sk
891
+ # now we have a fixed credentials (access key or sts token)
892
+ credentials = self.credentials_provider.get_credentials()
888
893
 
889
894
  sign_str = ""
890
895
 
@@ -892,7 +897,7 @@ class NacosClient:
892
897
  # config signature
893
898
  if "config" == module:
894
899
  headers.update({
895
- "Spas-AccessKey": ak,
900
+ "Spas-AccessKey": credentials.get_access_key_id(),
896
901
  "timeStamp": ts,
897
902
  })
898
903
 
@@ -905,7 +910,9 @@ class NacosClient:
905
910
  sign_str = sign_str + group + "+"
906
911
  if sign_str:
907
912
  sign_str += ts
908
- headers["Spas-Signature"] = self.__do_sign(sign_str, sk)
913
+ headers["Spas-Signature"] = self.__do_sign(sign_str, credentials.get_access_key_secret())
914
+ if credentials.get_security_token():
915
+ headers["Spas-SecurityToken"] = credentials.get_security_token()
909
916
 
910
917
  # naming signature
911
918
  else:
@@ -922,10 +929,12 @@ class NacosClient:
922
929
  sign_str = ts
923
930
 
924
931
  params.update({
925
- "ak": ak,
932
+ "ak": credentials.get_access_key_id(),
926
933
  "data": sign_str,
927
- "signature": self.__do_sign(sign_str, sk),
934
+ "signature": self.__do_sign(sign_str, credentials.get_access_key_secret()),
928
935
  })
936
+ if credentials.get_security_token():
937
+ params.update({"Spas-SecurityToken": credentials.get_security_token()})
929
938
 
930
939
  def __do_sign(self, sign_str, sk):
931
940
  return base64.encodebytes(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nacos-sdk-python
3
- Version: 2.0.0b5
3
+ Version: 2.0.2
4
4
  Summary: Python client for Nacos.
5
5
  Home-page: https://github.com/nacos-group/nacos-sdk-python
6
6
  Author: nacos
@@ -68,6 +68,7 @@ Description:
68
68
  * *namespace* - Namespace. | default: `None`
69
69
  * *ak* - The accessKey to authenticate. | default: null
70
70
  * *sk* - The secretKey to authentication. | default: null
71
+ * *credentials_provider* - The custom access key manager | default: null
71
72
  * *log_level* - Log level. | default: null
72
73
  * *log_rotation_backup_count* - The number of log files to keep. | default: `7`
73
74
 
@@ -249,9 +250,9 @@ Description:
249
250
 
250
251
  ### Subscribe Service Instances Changed
251
252
 
252
- > `NacosClient.subscribe(listener_fn, listener_interval=7, *args, **kwargs)`
253
+ >`NacosClient.subscribe(listener_fn, listener_interval=7, *args, **kwargs)`
253
254
 
254
- * `param` *listener_fn* **required** Customized listener function.
255
+ * `param` *listener_fn* **required** Customized listener function. with signature `fn_listener1(event, instance)->None`
255
256
  * `param` *listener_interval* Listen interval , default 7 second.
256
257
  * `param` *service_name* **required** Service name which subscribes.
257
258
  * `param` *clusters* Cluster names separated by comma.
@@ -304,7 +305,7 @@ Description:
304
305
  ## Installation
305
306
 
306
307
  ```shell
307
- pip install nacos-sdk-python==2.0.0b4
308
+ pip install nacos-sdk-python==2.0.0b5
308
309
  ```
309
310
 
310
311
  ## Client Configuration
@@ -326,6 +327,7 @@ Description:
326
327
  * *server_address* - **required** - Nacos server address
327
328
  * *access_key* - The aliyun accessKey to authenticate.
328
329
  * *secret_key* - The aliyun secretKey to authenticate.
330
+ * *credentials_provider* - The custom access key manager.
329
331
  * *username* - The username to authenticate.
330
332
  * *password* - The password to authenticate.
331
333
  * *log_level* - Log level | default: `logging.INFO`
@@ -1,6 +1,7 @@
1
1
  README.md
2
2
  setup.py
3
3
  nacos/__init__.py
4
+ nacos/auth.py
4
5
  nacos/client.py
5
6
  nacos/commons.py
6
7
  nacos/exception.py
@@ -18,6 +19,7 @@ v2/__init__.py
18
19
  v2/nacos/__init__.py
19
20
  v2/nacos/nacos_client.py
20
21
  v2/nacos/common/__init__.py
22
+ v2/nacos/common/auth.py
21
23
  v2/nacos/common/client_config.py
22
24
  v2/nacos/common/client_config_builder.py
23
25
  v2/nacos/common/constants.py
@@ -53,7 +53,7 @@ class UploadCommand(Command):
53
53
 
54
54
  setup(
55
55
  name="nacos-sdk-python",
56
- version="2.0.0.beta5",
56
+ version="2.0.2",
57
57
  packages=find_packages(
58
58
  exclude=["test", "*.tests", "*.tests.*", "tests.*", "tests"]),
59
59
  url="https://github.com/nacos-group/nacos-sdk-python",
@@ -0,0 +1,32 @@
1
+ class Credentials(object):
2
+ def __init__(self, access_key_id, access_key_secret, security_token=None):
3
+ self.access_key_id = access_key_id
4
+ self.access_key_secret = access_key_secret
5
+ self.security_token = security_token
6
+
7
+ def get_access_key_id(self):
8
+ return self.access_key_id
9
+
10
+ def get_access_key_secret(self):
11
+ return self.access_key_secret
12
+
13
+ def get_security_token(self):
14
+ return self.security_token
15
+
16
+ class CredentialsProvider(object):
17
+ def get_credentials(self):
18
+ return
19
+
20
+
21
+ class StaticCredentialsProvider(CredentialsProvider):
22
+ def __init__(self, access_key_id="", access_key_secret="", security_token=""):
23
+ self.credentials = Credentials(access_key_id, access_key_secret, security_token)
24
+
25
+ def get_credentials(self):
26
+ return self.credentials
27
+
28
+ def set_access_key_id(self, access_key_id):
29
+ self.credentials.access_key_id = access_key_id
30
+
31
+ def set_access_key_secret(self, access_key_secret):
32
+ self.credentials.access_key_secret = access_key_secret
@@ -2,6 +2,7 @@ import logging
2
2
 
3
3
  from v2.nacos.common.constants import Constants
4
4
  from v2.nacos.common.nacos_exception import NacosException, INVALID_PARAM
5
+ from v2.nacos.common.auth import StaticCredentialsProvider
5
6
 
6
7
 
7
8
  class KMSConfig:
@@ -44,7 +45,7 @@ class GRPCConfig:
44
45
  class ClientConfig:
45
46
  def __init__(self, server_addresses=None, endpoint=None, namespace_id='', context_path='', access_key=None,
46
47
  secret_key=None, username=None, password=None, app_name='', app_key='', log_dir='', log_level=None,
47
- log_rotation_backup_count=None, app_conn_labels=None):
48
+ log_rotation_backup_count=None, app_conn_labels=None, credentials_provider=None):
48
49
  self.server_list = []
49
50
  try:
50
51
  if server_addresses is not None and server_addresses.strip() != "":
@@ -57,9 +58,8 @@ class ClientConfig:
57
58
  self.endpoint_context_path = Constants.WEB_CONTEXT
58
59
  self.endpoint_query_header = None
59
60
  self.namespace_id = namespace_id
60
- self.access_key = access_key
61
+ self.credentials_provider = credentials_provider if credentials_provider else StaticCredentialsProvider(access_key, secret_key)
61
62
  self.context_path = context_path
62
- self.secret_key = secret_key
63
63
  self.username = username # the username for nacos auth
64
64
  self.password = password # the password for nacos auth
65
65
  self.app_name = app_name
@@ -1,5 +1,6 @@
1
1
  from typing import Dict, List
2
2
 
3
+ from v2.nacos.common.auth import CredentialsProvider, StaticCredentialsProvider
3
4
  from v2.nacos.common.client_config import ClientConfig, GRPCConfig
4
5
  from v2.nacos.common.client_config import KMSConfig
5
6
  from v2.nacos.common.client_config import TLSConfig
@@ -43,11 +44,21 @@ class ClientConfigBuilder:
43
44
  return self
44
45
 
45
46
  def access_key(self, access_key: str) -> "ClientConfigBuilder":
46
- self._config.access_key = access_key
47
+ if not self._config.credentials_provider:
48
+ self._config.credentials_provider = StaticCredentialsProvider(access_key_id=access_key)
49
+ else:
50
+ self._config.credentials_provider.set_access_key_id(access_key)
47
51
  return self
48
52
 
49
53
  def secret_key(self, secret_key: str) -> "ClientConfigBuilder":
50
- self._config.secret_key = secret_key
54
+ if not self._config.credentials_provider:
55
+ self._config.credentials_provider = StaticCredentialsProvider(access_key_secret=secret_key)
56
+ else:
57
+ self._config.credentials_provider.set_access_key_secret(secret_key)
58
+ return self
59
+
60
+ def credentials_provider(self, credentials_provider: CredentialsProvider) -> "ClientConfigBuilder":
61
+ self._config.credentials_provider = credentials_provider
51
62
  return self
52
63
 
53
64
  def username(self, username: str) -> "ClientConfigBuilder":
@@ -94,7 +94,8 @@ class ConfigGRPCClientProxy:
94
94
  'Timestamp': str(now),
95
95
  })
96
96
 
97
- if self.client_config.access_key is not None and self.client_config.secret_key is not None:
97
+ credentials = self.client_config.credentials_provider.get_credentials()
98
+ if credentials.get_access_key_id() and credentials.get_access_key_secret():
98
99
  if request.tenant:
99
100
  resource = request.tenant + "+" + request.group
100
101
  else:
@@ -106,11 +107,13 @@ class ConfigGRPCClientProxy:
106
107
  sign_str = str(now)
107
108
 
108
109
  request.put_all_headers({
109
- 'Spas-AccessKey': self.client_config.access_key,
110
+ 'Spas-AccessKey': credentials.get_access_key_id(),
110
111
  'Spas-Signature': base64.encodebytes(
111
- hmac.new(self.client_config.secret_key.encode(), sign_str.encode(),
112
+ hmac.new(credentials.get_access_key_secret().encode(), sign_str.encode(),
112
113
  digestmod=hashlib.sha1).digest()).decode().strip(),
113
114
  })
115
+ if credentials.get_security_token():
116
+ request.put_header("Spas-SecurityToken", credentials.get_security_token())
114
117
 
115
118
  response = await rpc_client.request(request, self.client_config.grpc_config.grpc_timeout)
116
119
  if response.get_result_code() != 200:
@@ -64,7 +64,8 @@ class NamingGRPCClientProxy:
64
64
  try:
65
65
  await self.nacos_server_connector.inject_security_info(request.get_headers())
66
66
 
67
- if self.client_config.access_key is not None and self.client_config.secret_key is not None:
67
+ credentials = self.client_config.credentials_provider.get_credentials()
68
+ if credentials.get_access_key_id() and credentials.get_access_key_secret():
68
69
  service_name = get_group_name(request.serviceName, request.groupName)
69
70
  if service_name.strip():
70
71
  sign_str = str(get_current_time_millis()) + Constants.SERVICE_INFO_SPLITER + service_name
@@ -72,11 +73,13 @@ class NamingGRPCClientProxy:
72
73
  sign_str = str(get_current_time_millis())
73
74
 
74
75
  request.put_all_headers({
75
- "ak": self.client_config.access_key,
76
+ "ak": credentials.get_access_key_id(),
76
77
  "data": sign_str,
77
- "signature": base64.encodebytes(hmac.new(self.client_config.secret_key.encode(), sign_str.encode(),
78
+ "signature": base64.encodebytes(hmac.new(credentials.get_access_key_secret().encode(), sign_str.encode(),
78
79
  digestmod=hashlib.sha1).digest()).decode().strip()
79
80
  })
81
+ if credentials.get_security_token():
82
+ request.put_header("Spas-SecurityToken", credentials.get_security_token())
80
83
 
81
84
  response = await self.rpc_client.request(request, self.client_config.grpc_config.grpc_timeout)
82
85
  if response.get_result_code() != 200:
@@ -6,7 +6,7 @@ import pydantic
6
6
 
7
7
  from v2.nacos.common.client_config import ClientConfig
8
8
  from v2.nacos.common.constants import Constants
9
- from v2.nacos.common.nacos_exception import NacosException
9
+ from v2.nacos.common.nacos_exception import NacosException, CLIENT_DISCONNECT
10
10
  from v2.nacos.transport.connection import Connection
11
11
  from v2.nacos.transport.grpc_connection import GrpcConnection
12
12
  from v2.nacos.transport.grpc_util import GrpcUtils
@@ -53,9 +53,13 @@ class GrpcClient(RpcClient):
53
53
  else:
54
54
  channel = grpc.aio.insecure_channel(f'{server_ip}:{grpc_port}',
55
55
  options=options)
56
- await channel.channel_ready()
57
-
58
- return channel
56
+ try:
57
+ await asyncio.wait_for(channel.channel_ready(), self.grpc_config.grpc_timeout / 1000)
58
+ except asyncio.TimeoutError as e:
59
+ await channel.close()
60
+ raise NacosException(CLIENT_DISCONNECT, 'failed to connect nacos server') from e
61
+ else:
62
+ return channel
59
63
 
60
64
  async def _server_check(self, server_ip, server_port, channel_stub: RequestStub):
61
65
  for i in range(self.RETRY_TIMES):
@@ -8,16 +8,12 @@ CLIENT_DETECTION_REQUEST_TYPE = "ClientDetectionRequest"
8
8
 
9
9
 
10
10
  class InternalRequest(Request, ABC):
11
- def __init__(self):
12
- super().__init__()
13
11
 
14
12
  def get_module(self) -> str:
15
13
  return 'internal'
16
14
 
17
15
 
18
16
  class HealthCheckRequest(InternalRequest):
19
- def __init__(self):
20
- super().__init__()
21
17
 
22
18
  def get_request_type(self):
23
19
  return "HealthCheckRequest"
@@ -32,6 +32,9 @@ class NacosServerConnector:
32
32
  asyncio.create_task(self.auth_client.get_access_token(True))
33
33
 
34
34
  async def init(self):
35
+ if len(self.server_list) != 0:
36
+ return
37
+
35
38
  await self._get_server_list_from_endpoint()
36
39
  if len(self.server_list) == 0:
37
40
  raise NacosException(INVALID_SERVER_STATUS, "server list is empty")
@@ -374,7 +374,7 @@ class RpcClient(ABC):
374
374
  # when client request immediately after server starts, server may not ready to serve new request
375
375
  # the server will return code 3xx, tell the client to retry after a while
376
376
  # this situation, just return true,because the healthCheck will start again after 5 seconds
377
- if response.get_error_code() >= 300 and response.get_error_code < 400:
377
+ if response.get_error_code() >= 300 and response.get_error_code() < 400:
378
378
  return True
379
379
  return False
380
380
  return response and response.is_success()