Skip to content

Commit 9960bc2

Browse files
Merge pull request #239 from peppelinux/ldap_attribute_store
Fix for local variable referenced before assignment in ldap_attribute-store
2 parents 224b65f + 66a9781 commit 9960bc2

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/satosa/micro_services/ldap_attribute_store.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,10 @@ def process(self, context, data):
400400
# Initialize an empty LDAP record. The first LDAP record found using the ordered
401401
# list of search filter values will be the record used.
402402
record = None
403+
err_msg = None
403404

404405
try:
405406
connection = config['connection']
406-
407407
for filter_val in filter_values:
408408
if record:
409409
break
@@ -423,17 +423,16 @@ def process(self, context, data):
423423
satosa_logging(logger, logging.WARN, "LDAP server returned {} records using search filter value {}".format(len(responses), filter_val), context.state)
424424
record = responses[0]
425425
break
426-
except LDAPException as err:
427-
satosa_logging(logger, logging.ERROR, "Caught LDAP exception: {}".format(err), context.state)
428-
except LdapAttributeStoreError as err:
429-
satosa_logging(logger, logging.ERROR, "Caught LDAP Attribute Store exception: {}".format(err), context.state)
430-
except Exception as err:
431-
satosa_logging(logger, logging.ERROR, "Caught unhandled exception: {}".format(err), context.state)
432-
else:
433-
err = None
434-
finally:
435-
if err:
436-
return super().process(context, data)
426+
except LDAPException as e:
427+
err_msg = "Caught LDAP exception: {}".format(e)
428+
except LdapAttributeStoreError as e:
429+
err_msg = "Caught LDAP Attribute Store exception: {}".format(e)
430+
except Exception as e:
431+
err_msg = "Caught unhandled exception: {}".format(e)
432+
433+
if err_msg:
434+
satosa_logging(logger, logging.ERROR, err_msg, context.state)
435+
return super().process(context, data)
437436

438437
# Before using a found record, if any, to populate attributes
439438
# clear any attributes incoming to this microservice if so configured.

0 commit comments

Comments
 (0)