File size: 1,068 Bytes
a2e3bb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import sys
from pathlib import Path

from dotenv import load_dotenv
from huggingface_hub import HfApi

ROOT_DIR = Path(__file__).resolve().parents[1]
ENV_PATH = ROOT_DIR / ".env"

if ENV_PATH.exists():
    load_dotenv(dotenv_path=ENV_PATH)

hf_token = os.getenv("HF_TOKEN")
space_id = os.getenv("HF_SPACE_ID")
api_bearer_token = os.getenv("API_BEARER_TOKEN")
cert_zscaler_pem = os.getenv("CERT_ZSCALER_PEM")

missing = [name for name, value in {
    "HF_TOKEN": hf_token,
    "HF_SPACE_ID": space_id,
    "API_BEARER_TOKEN": api_bearer_token,
}.items() if not value]

if missing:
    sys.stderr.write(f"Missing required env vars in .env: {', '.join(missing)}\n")
    sys.exit(1)

if cert_zscaler_pem:
    sys.stderr.write("CERT_ZSCALER_PEM is set. This script will not upload Zscaler certs to HF.\n")
    sys.exit(1)

api = HfApi(token=hf_token)
api.add_space_secret(
    repo_id=space_id,
    key="API_BEARER_TOKEN",
    value=api_bearer_token,
    description="Bearer token for DDGS Search API",
)

print(f"Uploaded secret API_BEARER_TOKEN to {space_id}")