xenoslib 0.1.29.18__tar.gz → 0.1.29.20__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 (22) hide show
  1. {xenoslib-0.1.29.18/xenoslib.egg-info → xenoslib-0.1.29.20}/PKG-INFO +1 -1
  2. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib/about.py +1 -1
  3. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib/base.py +3 -1
  4. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib/extend.py +12 -5
  5. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20/xenoslib.egg-info}/PKG-INFO +1 -1
  6. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/LICENSE +0 -0
  7. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/README.md +0 -0
  8. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/setup.cfg +0 -0
  9. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/setup.py +0 -0
  10. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib/__init__.py +0 -0
  11. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib/__main__.py +0 -0
  12. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib/dev.py +0 -0
  13. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib/linux.py +0 -0
  14. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib/mail.py +0 -0
  15. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib/mock.py +0 -0
  16. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib/onedrive.py +0 -0
  17. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib/win_trayicon.py +0 -0
  18. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib/windows.py +0 -0
  19. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib.egg-info/SOURCES.txt +0 -0
  20. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib.egg-info/dependency_links.txt +0 -0
  21. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib.egg-info/requires.txt +0 -0
  22. {xenoslib-0.1.29.18 → xenoslib-0.1.29.20}/xenoslib.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xenoslib
3
- Version: 0.1.29.18
3
+ Version: 0.1.29.20
4
4
  Summary: Xenos' common lib
5
5
  Home-page: https://github.com/XenosLu/xenoslib.git
6
6
  Author: Xenocider
@@ -4,4 +4,4 @@ __url__ = "https://github.com/XenosLu/xenoslib.git"
4
4
  __author__ = "Xenocider"
5
5
  __author_email__ = "xenos.lu@gmail.com"
6
6
  __license__ = "MIT License"
7
- __version__ = "0.1.29.18"
7
+ __version__ = "0.1.29.20"
@@ -244,7 +244,9 @@ class Singleton:
244
244
 
245
245
 
246
246
  class SingletonWithArgs:
247
- """带参数的单例模式, 通过继承使用,需放到第一继承位"""
247
+ """带参数的单例模式, 通过继承使用,需放到第一继承位
248
+ Please note that __init__() will still run every time
249
+ """
248
250
 
249
251
  def __new__(cls, *args, **kwargs):
250
252
  arg = f"{args}{kwargs}"
@@ -214,17 +214,18 @@ class ConfigLoader(SingletonWithArgs):
214
214
  """
215
215
 
216
216
  cache = {}
217
+ vault_client = None
217
218
 
218
219
  def __init__(self, config_file_path="config.yml", vault_secret_id=None):
219
220
  """Initialize the ConfigLoader with a configuration file and optional Vault secret."""
220
221
  with open(config_file_path, "r") as f:
221
222
  self._raw_config = yaml.safe_load(f) or {}
222
- self.vault_client = None
223
223
 
224
224
  if vault_secret_id is not None:
225
- self._init_vault_client(vault_secret_id)
225
+ self.vault_secret_id = vault_secret_id
226
+ self._check_and_renew_vault_client()
226
227
 
227
- def _init_vault_client(self, vault_secret_id):
228
+ def _init_vault_client(self):
228
229
  """Initialize and authenticate the Vault client (imports hvac on demand).
229
230
 
230
231
  Args:
@@ -252,11 +253,17 @@ class ConfigLoader(SingletonWithArgs):
252
253
  raise KeyError("Missing required Vault configuration in config.yml")
253
254
 
254
255
  self.vault_client = hvac.Client(url=vault_url, namespace=vault_space)
255
- self.vault_client.auth.approle.login(role_id=vault_role_id, secret_id=vault_secret_id)
256
+ self.vault_client.auth.approle.login(role_id=vault_role_id, secret_id=self.vault_secret_id)
256
257
  except Exception as e:
257
258
  self.vault_client = None
258
259
  raise Exception(f"Failed to initialize Vault client: {str(e)}")
259
260
 
261
+ def _check_and_renew_vault_client(self):
262
+ # 检查当前Token的状态,包括过期时间和可续租性
263
+ if not self.vault_client or not self.vault_client.is_authenticated():
264
+ # 如果当前Token无效,则重新认证
265
+ self._init_vault_client()
266
+
260
267
  def get(self, section, key_name, use_cache=True):
261
268
  """Retrieve a configuration value.
262
269
 
@@ -366,5 +373,5 @@ if __name__ == "__main__":
366
373
 
367
374
  # This will only work if you provide a valid Vault secret ID
368
375
  # and hvac package is installed
369
- config_with_vault = ConfigLoader("config.yml", vault_secret_id="your-secret-id")
376
+ config_with_vault = ConfigLoader("config.yml", vault_secret_id=os.getenv("VAULT_CF_LANDSCAPES_SECRET_ID"))
370
377
  print("With Vault:", config_with_vault.get("cis", "cis_client_id"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xenoslib
3
- Version: 0.1.29.18
3
+ Version: 0.1.29.20
4
4
  Summary: Xenos' common lib
5
5
  Home-page: https://github.com/XenosLu/xenoslib.git
6
6
  Author: Xenocider
File without changes
File without changes
File without changes
File without changes