config_reader.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """
  2. 根据bucket的名字返回对应的s3 AK, SK,endpoint三元组
  3. """
  4. import json
  5. import os
  6. from loguru import logger
  7. def get_s3_config(bucket_name: str):
  8. """
  9. ~/magic-pdf.json 读出来
  10. """
  11. home_dir = os.path.expanduser("~")
  12. config_file = os.path.join(home_dir, "magic-pdf.json")
  13. if not os.path.exists(config_file):
  14. raise Exception("magic-pdf.json not found")
  15. with open(config_file, "r") as f:
  16. config = json.load(f)
  17. bucket_info = config.get("bucket_info")
  18. if bucket_name not in bucket_info:
  19. raise Exception("bucket_name not found in magic-pdf.json")
  20. access_key, secret_key, storage_endpoint = bucket_info[bucket_name]
  21. if access_key is None or secret_key is None or storage_endpoint is None:
  22. raise Exception("ak, sk or endpoint not found in magic-pdf.json")
  23. # logger.info(f"get_s3_config: ak={access_key}, sk={secret_key}, endpoint={storage_endpoint}")
  24. return access_key, secret_key, storage_endpoint
  25. if __name__ == '__main__':
  26. ak, sk, endpoint = get_s3_config("llm-raw")