Upload data_sync.py
Browse files- src/data_sync.py +11 -2
src/data_sync.py
CHANGED
|
@@ -17,6 +17,7 @@ from typing import Optional, Dict, List
|
|
| 17 |
|
| 18 |
from huggingface_hub import HfApi, hf_hub_download, upload_folder
|
| 19 |
from loguru import logger
|
|
|
|
| 20 |
|
| 21 |
# 文件监控(可选)
|
| 22 |
try:
|
|
@@ -94,9 +95,17 @@ class DatasetManager:
|
|
| 94 |
if self.path_mapping['config'].exists():
|
| 95 |
shutil.copy2(self.path_mapping['config'], self.temp_dir / 'config' / 'config.yaml')
|
| 96 |
|
| 97 |
-
# 环境变量(敏感信息)
|
| 98 |
if self.path_mapping['env'].exists():
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
# OAuth 认证
|
| 102 |
if self.path_mapping['auth'].exists():
|
|
|
|
| 17 |
|
| 18 |
from huggingface_hub import HfApi, hf_hub_download, upload_folder
|
| 19 |
from loguru import logger
|
| 20 |
+
import re
|
| 21 |
|
| 22 |
# 文件监控(可选)
|
| 23 |
try:
|
|
|
|
| 95 |
if self.path_mapping['config'].exists():
|
| 96 |
shutil.copy2(self.path_mapping['config'], self.temp_dir / 'config' / 'config.yaml')
|
| 97 |
|
| 98 |
+
# 环境变量(敏感信息)- 上传前 masking 处理
|
| 99 |
if self.path_mapping['env'].exists():
|
| 100 |
+
env_src = self.path_mapping['env']
|
| 101 |
+
env_dst = self.temp_dir / 'config' / '.env'
|
| 102 |
+
with open(env_src, 'r', encoding='utf-8') as f:
|
| 103 |
+
env_content = f.read()
|
| 104 |
+
# Mask Hugging Face tokens to prevent upload rejection
|
| 105 |
+
env_content = re.sub(r'(HF_TOKEN|HUGGING_FACE_HUB_TOKEN)=hf_[a-zA-Z0-9]+', r'\1=***masked***', env_content)
|
| 106 |
+
env_content = re.sub(r'(HF_TOKEN|HUGGING_FACE_HUB_TOKEN)=.+', r'\1=***masked***', env_content)
|
| 107 |
+
with open(env_dst, 'w', encoding='utf-8') as f:
|
| 108 |
+
f.write(env_content)
|
| 109 |
|
| 110 |
# OAuth 认证
|
| 111 |
if self.path_mapping['auth'].exists():
|