Files
microsoft--promptflow/scripts/tool/generate_connection_config.py
wehub-resource-sync e768098d0e
Flake8 Lint / flake8 (push) Waiting to run
Spell check CI / Spell_Check (push) Waiting to run
tools_continuous_delivery / Private PyPI non-main branch release (push) Has been skipped
tools_continuous_delivery / Private PyPI main branch release (push) Failing after 2m42s
Publish Promptflow Doc / Build (push) Has been cancelled
Publish Promptflow Doc / Deploy (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:39:52 +08:00

40 lines
1.4 KiB
Python

import argparse
import json
from pathlib import Path
from utils.secret_manager import get_secret, get_secret_client, list_secret_names
CONNECTION_FILE_NAME = "connections.json"
PROMPTFLOW_TOOLS_ROOT = Path(__file__) / "../../../src/promptflow-tools"
CONNECTION_TPL_FILE_PATH = PROMPTFLOW_TOOLS_ROOT / "connections.json.example"
def fill_key_to_dict(template_dict, keys_dict):
if not isinstance(template_dict, dict):
return
for key, val in template_dict.items():
if isinstance(val, str) and val in keys_dict:
template_dict[key] = keys_dict[val]
continue
fill_key_to_dict(val, keys_dict)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--local", action='store_true', help="local debug mode")
args = parser.parse_args()
template_dict = json.loads(open(CONNECTION_TPL_FILE_PATH.resolve().absolute(), "r").read())
file_path = (PROMPTFLOW_TOOLS_ROOT / CONNECTION_FILE_NAME).resolve().absolute().as_posix()
print(f"file_path: {file_path}")
if not args.local:
client = get_secret_client()
all_secret_names = list_secret_names(client)
data = {secret_name: get_secret(secret_name, client) for secret_name in all_secret_names}
fill_key_to_dict(template_dict, data)
with open(file_path, "w") as f:
json.dump(template_dict, f)