Skip to content

Commit

Permalink
Enable more debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley-wenyizha committed Mar 6, 2023
1 parent b6151f3 commit 85b0f2f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/mount_efs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ def _fatal_error(message):
'Warning: region obtained from "dns_name_format" field. Please set the "region" '
"parameter in the efs-utils configuration file."
)
logging.debug("[*][1]No parameter in the efs-utils configuration file")
return region
except Exception:
logging.warning('Legacy check for region in "dns_name_format" failed')
Expand All @@ -396,6 +397,7 @@ def get_region_from_instance_metadata(config):
instance_identity = get_instance_identity_info_from_instance_metadata(
config, "region"
)
logging.debug("[*][2] Success - get_region_from_instance_metadata with --> %s", instance_identity)

if not instance_identity:
raise Exception(
Expand All @@ -410,6 +412,7 @@ def get_az_from_instance_metadata(config):
instance_identity = get_instance_identity_info_from_instance_metadata(
config, "availabilityZone"
)
logging.debug("[*][3] Success - get_az_from_instance_metadata with --> %s", instance_identity)

if not instance_identity:
raise Exception("Cannot retrieve az from instance_metadata")
Expand All @@ -432,6 +435,7 @@ def get_instance_identity_info_from_instance_metadata(config, property):
logging.debug(
"Instance metadata already retrieved in previous call, use the cached values."
)
logging.debug("[*][4] Success - get_region_from_instance_metadata with --> %s", INSTANCE_IDENTITY)
instance_identity = INSTANCE_IDENTITY
else:
instance_identity = url_request_helper(
Expand All @@ -441,6 +445,7 @@ def get_instance_identity_info_from_instance_metadata(config, property):
ec2_metadata_url_error_msg,
)
INSTANCE_IDENTITY = instance_identity
logging.debug("[*][5] Success - url_request returned with --> %s", INSTANCE_IDENTITY)

if instance_identity:
try:
Expand All @@ -465,7 +470,9 @@ def get_region_from_legacy_dns_format(config):
dns_name_format = config.get(CONFIG_SECTION, "dns_name_format")
if "{region}" not in dns_name_format:
split_dns_name_format = dns_name_format.split(".")
logging.debug("(1)split_dns_name_format in get_region_from_legacy_dns_format is %s", split_dns_name_format)
if "{dns_name_suffix}" in dns_name_format:
logging.debug("(2) split_dns_name_format in get_region_from_legacy_dns_format is %s", split_dns_name_format)
return split_dns_name_format[-2]
elif "amazonaws.com" in dns_name_format:
return split_dns_name_format[-3]
Expand Down Expand Up @@ -595,6 +602,7 @@ def get_aws_security_credentials(
# through IAM role name security credentials lookup uri
iam_role_name = get_iam_role_name(config)
if iam_role_name:
logging.debug("IAM role name is %s", iam_role_name)
(
credentials,
credentials_source,
Expand Down Expand Up @@ -648,6 +656,8 @@ def get_aws_security_credentials_from_ecs(config, aws_creds_uri, is_fatal=False)
config, ecs_uri, ecs_unsuccessful_resp, ecs_url_error_msg
)

logging.debug("ecs_security_dict has retrieved info of %s ", ecs_security_dict)

if ecs_security_dict and all(k in ecs_security_dict for k in CREDENTIALS_KEYS):
return ecs_security_dict, "ecs:" + aws_creds_uri

Expand Down Expand Up @@ -686,6 +696,8 @@ def get_aws_security_credentials_from_webidentity(
)
)

logging.debug("Retrieved webidentity_url is %s ", webidentity_url)

unsuccessful_resp = (
"Unsuccessful retrieval of AWS security credentials at %s." % STS_ENDPOINT_URL
)
Expand Down Expand Up @@ -713,7 +725,7 @@ def get_aws_security_credentials_from_webidentity(
"SecretAccessKey": creds["SecretAccessKey"],
"Token": creds["SessionToken"],
}, "webidentity:" + ",".join([role_arn, token_file])

logging.debug("Retrieved creds is : %s", creds)
# Fail if credentials cannot be fetched from the given aws_creds_uri
if is_fatal:
fatal_error(unsuccessful_resp, unsuccessful_resp)
Expand All @@ -735,13 +747,16 @@ def get_aws_security_credentials_from_instance_metadata(config, iam_role_name):
config, security_creds_lookup_url, unsuccessful_resp, url_error_msg
)

logging.debug("iam_security_dict is %s", iam_security_dict)

if iam_security_dict and all(k in iam_security_dict for k in CREDENTIALS_KEYS):
return iam_security_dict, "metadata:"
else:
return None, None


def get_iam_role_name(config):
logging.debug("Retrieved config when trying to get iam role, %s and INSTANCE_IAM_URL is %s,", config, INSTANCE_IAM_URL)
iam_role_unsuccessful_resp = (
"Unsuccessful retrieval of IAM role name at %s." % INSTANCE_IAM_URL
)
Expand All @@ -752,6 +767,7 @@ def get_iam_role_name(config):
iam_role_name = url_request_helper(
config, INSTANCE_IAM_URL, iam_role_unsuccessful_resp, iam_role_url_error_msg
)
logging.debug("Retrieved iam_role_name, %s", config, iam_role_name)
return iam_role_name


Expand Down Expand Up @@ -827,7 +843,7 @@ def get_aws_profile(options, use_iam):
return "default"
except (NoSectionError, NoOptionError):
continue

logging.debug("get_aws_profile got use_iam of %s", use_iam)
return awsprofile


Expand Down

0 comments on commit 85b0f2f

Please sign in to comment.