-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_app_settings.py
More file actions
77 lines (64 loc) · 2.72 KB
/
Copy pathsetup_app_settings.py
File metadata and controls
77 lines (64 loc) · 2.72 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import json
import subprocess
import sys
import argparse
def run_command(command):
"""Runs a command and returns its output."""
print(f"Executing: {' '.join(command)}")
try:
result = subprocess.run(command, capture_output=True, text=True, check=True)
return result.stdout.strip()
except subprocess.CalledProcessError as e:
print(f"Error running command: {e.stderr}")
sys.exit(1)
def main():
parser = argparse.ArgumentParser(description="Set Azure Function App settings from local.settings.json.")
parser.add_argument("--name", required=True, help="The name of the Function App.")
parser.add_argument("--resource-group", required=True, help="The name of the resource group.")
parser.add_argument("--storage-account", required=True, help="The name of the storage account.")
args = parser.parse_args()
print("--- Getting Storage Connection String ---")
storage_connection_string = run_command([
"az", "storage", "account", "show-connection-string",
"--name", args.storage_account,
"--resource-group", args.resource_group,
"--query", "connectionString",
"--output", "tsv"
])
print("\n--- Reading local.settings.json ---")
try:
with open("local.settings.json", "r") as f:
settings = json.load(f)
except FileNotFoundError:
print("Error: local.settings.json not found in the current directory.")
sys.exit(1)
app_settings = settings.get("Values", {})
app_settings["AzureWebJobsStorage"] = storage_connection_string
app_settings["AZURE_STORAGE_CONNECTION_STRING"] = storage_connection_string
# Define a set of keys to exclude from the update. These are typically
# platform-managed or sensitive settings that should not be overwritten from local.settings.json.
EXCLUDE_KEYS = {
"APPLICATIONINSIGHTS_CONNECTION_STRING",
"AzureWebJobsStorage",
"FUNCTIONS_EXTENSION_VERSION",
"FUNCTIONS_WORKER_RUNTIME",
"FUNCTIONS_WORKER_RUNTIME_VERSION",
"MACHINEKEY_DecryptionKey",
"WEBSITES_ENABLE_APP_SERVICE_STORAGE",
"WEBSITE_TIME_ZONE"
}
filtered_app_settings = {
key: value for key, value in app_settings.items() if key not in EXCLUDE_KEYS
}
settings_to_set = [f'{key}={value}' for key, value in filtered_app_settings.items()]
print("\n--- Setting Application Settings in Azure ---")
command = [
"az", "functionapp", "config", "appsettings", "set",
"--name", args.name,
"--resource-group", args.resource_group,
"--settings"
] + settings_to_set
run_command(command)
print("\nSuccessfully set application settings.")
if __name__ == "__main__":
main()