Skip to content

Commit

Permalink
Fix debug_ldap_client tracebacks (#81)
Browse files Browse the repository at this point in the history
Ensure debug_ldap_client does not fail with a traceback when failing to
get the krb5 context or default ccache. A failure in those steps should
be reported in the output.
  • Loading branch information
jborean93 authored Nov 22, 2023
1 parent 377c28f commit f287175
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/debug_ldap_client-failure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- debug_ldap_client - handle failures when attempting to get the krb5 context and default CCache rather than fail with a traceback
12 changes: 6 additions & 6 deletions plugins/action/debug_ldap_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def run(
"dns": dns_info,
"kerberos": kerb_info,
"packages": {
"dnspython": self._import_lib("dns.resolver", package_name="dnspython"),
"dnspython": self._import_lib(
"dns.resolver", package_name="dnspython"
),
"dpapi_ng": self._import_lib("dpapi_ng", package_name="dpapi-ng"),
"krb5": self._import_lib("krb5"),
"pyspnego": self._import_lib("spnego", package_name="pyspnego"),
Expand All @@ -77,8 +79,6 @@ def _get_kerberos_info(self) -> t.Dict[str, t.Any]:
ctx = krb5.init_context()
except Exception:
res["exception"] = traceback.format_exc()

if not ctx:
return res

try:
Expand Down Expand Up @@ -106,8 +106,6 @@ def _get_kerberos_cc_info(
default_cc = krb5.cc_default(ctx)
except Exception:
res["exception"] = traceback.format_exc()

if not default_cc:
return res

try:
Expand Down Expand Up @@ -154,7 +152,9 @@ def _get_server_lookup_info(
}
)

highest_record = next(iter(sorted(records, key=lambda k: (k["priority"], -k["weight"]))), None)
highest_record = next(
iter(sorted(records, key=lambda k: (k["priority"], -k["weight"]))), None
)
if highest_record:
res["default_server"] = highest_record["target"].rstrip(".")
res["default_port"] = highest_record["port"]
Expand Down

0 comments on commit f287175

Please sign in to comment.