Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/mount_efs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
STUNNEL_EFS_CONFIG = {
"client": "yes",
"accept": "127.0.0.1:%s",
"connect": "%s:2049",
"connect": "%s:%s",
"sslVersion": "TLSv1.2",
"renegotiation": "no",
"TIMEOUTbusy": "20",
Expand Down Expand Up @@ -621,6 +621,30 @@ def get_boolean_config_item_value(
return default_value
return config.getboolean(config_section, config_item)

def get_int_config_item_value(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method seems like a duplicate of get_boolean_config_item_value, we can have a generic method like

  def _get_config_item_value(config, section, item, default, getter, emit_warning=True):
      # shared section/option check + warning emission
      ...
       return getter(section, item)

def get_boolean_config_item_value(...): return _get_config_item_value(..., config.getboolean, ...)
def get_int_config_item_value(...):     return _get_config_item_value(..., config.getint, ...)

config, config_section, config_item, default_value, emit_warning_message=True
):
warning_message = None
if not config.has_section(config_section):
warning_message = (
"Warning: config file does not have section %s." % config_section
)
elif not config.has_option(config_section, config_item):
warning_message = (
"Warning: config file does not have %s item in section %s."
% (config_item, config_section)
)

if warning_message:
if emit_warning_message:
sys.stdout.write(
"%s. You should be able to find a new config file in the same folder as current config file %s. "
"Consider update the new config file to latest config file. Use the default value [%s = %s]."
% (warning_message, CONFIG_FILE, config_item, default_value)
)

@vmishra22 vmishra22 Jun 2, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning is written to sys.stdout, but mount.efs's stdout can be parsed by callers (systemd units, automount helpers, scripts wrapping mount). Diagnostics like this should go to stderr

return default_value
return config.getint(config_section, config_item)


def fetch_ec2_metadata_token_disabled(config):
return get_boolean_config_item_value(
Expand Down Expand Up @@ -1514,10 +1538,11 @@ def write_stunnel_config_file(
efs_config = dict(STUNNEL_EFS_CONFIG)
efs_config["accept"] = efs_config["accept"] % tls_port

stunnel_efs_port = get_int_config_item_value(config, CONFIG_SECTION, "stunnel_efs_port", 2049)
if fallback_ip_address:
efs_config["connect"] = efs_config["connect"] % fallback_ip_address
efs_config["connect"] = efs_config["connect"] % (fallback_ip_address, stunnel_efs_port)
else:
efs_config["connect"] = efs_config["connect"] % dns_name
efs_config["connect"] = efs_config["connect"] % (dns_name, stunnel_efs_port)

# Verify level is only valid for tls mounts
if (verify_level is not None) and tls_enabled(options):
Expand Down