Skip to content

Commit 1c1db24

Browse files
hestolzCopilot
andauthored
AzureMonitorAgent: accept string "true" in public settings (#2176)
- Add _is_truthy_setting() helper and use it for GCS_AUTO_CONFIG, genevaConfiguration.enable, azureMonitorConfiguration.enable, and proxy.auth so both JSON boolean true and string "true" are accepted (case-insensitive, trimmed). Other values are unchanged. Co-authored-by: hestolz <hestolz@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1a6aee8 commit 1c1db24

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

AzureMonitorAgent/agent.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ def get_free_space_mb(dirname):
257257
st = os.statvfs(dirname)
258258
return (st.f_bavail * st.f_frsize) // (1024 * 1024)
259259

260+
def is_truthy(value):
261+
"""
262+
Check if value represents a truthy value in public settings.
263+
"""
264+
if value is True:
265+
return True
266+
if isinstance(value, str) and value.strip().lower() == "true":
267+
return True
268+
return False
269+
260270
def is_systemd():
261271
"""
262272
Check if the system is using systemd
@@ -882,19 +892,19 @@ def enable():
882892
if len(public_settings) > 1 and ((geneva_configuration and not azure_monitor_configuration) or (azure_monitor_configuration and not geneva_configuration)):
883893
log_and_exit("Enable", MissingorInvalidParameterErrorCode, 'Mixing genevaConfiguration or azureMonitorConfiguration with other configuration schemas is not allowed')
884894

885-
if geneva_configuration and geneva_configuration.get("enable") == True:
895+
if geneva_configuration and is_truthy(geneva_configuration.get("enable")):
886896
hutil_log_info("Detected Geneva+ mode; azuremonitoragentmgr service will be started to handle Geneva tenants")
887897
ensure["azuremonitoragentmgr"] = True
888898

889-
if azure_monitor_configuration and azure_monitor_configuration.get("enable") == True:
899+
if azure_monitor_configuration and is_truthy(azure_monitor_configuration.get("enable")):
890900
hutil_log_info("Detected Azure Monitor+ mode; azuremonitoragent service will be started to handle Azure Monitor tenant")
891901
ensure["azuremonitoragent"] = True
892902
azure_monitor_public_settings = azure_monitor_configuration.get("configuration")
893903
azure_monitor_protected_settings = protected_settings.get(AzureMonitorConfigKey) if protected_settings is not None else None
894904
handle_mcs_config(azure_monitor_public_settings, azure_monitor_protected_settings, default_configs)
895905

896906
# Legacy schema
897-
elif public_settings is not None and public_settings.get("GCS_AUTO_CONFIG") == True:
907+
elif public_settings is not None and is_truthy(public_settings.get("GCS_AUTO_CONFIG")):
898908
hutil_log_info("Detected Auto-Config mode; azuremonitoragentmgr service will be started to handle Geneva tenants")
899909
ensure["azuremonitoragentmgr"] = True
900910

@@ -1164,12 +1174,12 @@ def get_control_plane_mode():
11641174
geneva_configuration = public_settings.get(GenevaConfigKey)
11651175
azure_monitor_configuration = public_settings.get(AzureMonitorConfigKey)
11661176

1167-
if geneva_configuration and geneva_configuration.get("enable") == True:
1177+
if geneva_configuration and is_truthy(geneva_configuration.get("enable")):
11681178
GcsEnabled = True
1169-
if azure_monitor_configuration and azure_monitor_configuration.get("enable") == True:
1179+
if azure_monitor_configuration and is_truthy(azure_monitor_configuration.get("enable")):
11701180
McsEnabled = True
11711181
# Legacy schema
1172-
elif public_settings is not None and public_settings.get("GCS_AUTO_CONFIG") == True:
1182+
elif public_settings is not None and is_truthy(public_settings.get("GCS_AUTO_CONFIG")):
11731183
GcsEnabled = True
11741184
elif (protected_settings is None or len(protected_settings) == 0) or get_proxy_mode(public_settings) == "application":
11751185
McsEnabled = True
@@ -1342,7 +1352,7 @@ def apply_application_proxy(public_settings, protected_settings, default_configs
13421352

13431353
username = ""
13441354
password = ""
1345-
if proxy_config.get("auth") == True:
1355+
if is_truthy(proxy_config.get("auth")):
13461356
protected_proxy = (protected_settings or {}).get("proxy", {})
13471357
username = protected_proxy.get("username")
13481358
password = protected_proxy.get("password")

0 commit comments

Comments
 (0)