This repository has been archived by the owner on Oct 26, 2021. It is now read-only.
Support for aliases #2
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dc8b02a
adds support to remove accounts with email domains added managed by L…
jdow 183d74a
simplifying mail and alias lookup into a single ldap query
jdow fe423a0
adding a bailout clause for if the ldap query returns more than one r…
jdow 0d8fe62
removing old commented out code
jdow 8ac44e0
fixing typo of member variable
jdow 4d513b0
replacing id variable name with identity
jdow File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,8 @@ def list_all_users(): | |
should_return = False | ||
return_list = [] | ||
fetch_url = "%s/users" % auth0_config['auth0_api_url'] | ||
payload = {'connection': "%s" % auth0_config['auth0_connection'], 'fields': 'user_id,email,blocked', 'include_fields': 'true'} | ||
# payload = {'connection': "%s" % auth0_config['auth0_connection'], 'fields': 'user_id,email,blocked', 'include_fields': 'true'} | ||
payload = {'fields': 'identities,user_id,email,blocked', 'include_fields': 'true'} | ||
while (should_return is False): | ||
prev_url = fetch_url | ||
if proxy_config['use_proxy'] is True: | ||
|
@@ -53,11 +54,9 @@ def list_all_users(): | |
should_return = True | ||
return return_list | ||
|
||
|
||
# filter out only the active users | ||
# active user here is defined as not being currently blocked | ||
def list_all_active_users(): | ||
users = list_all_users() | ||
def list_active_users(users): | ||
ret_users = [] | ||
for user in users: | ||
if u'blocked' not in user: | ||
|
@@ -69,8 +68,12 @@ def list_all_active_users(): | |
# return [user for user in users if u'blocked' not in user or user[u'blocked'] != True] | ||
|
||
# this function returns the DN of the user that matches the given e-mail address | ||
def get_ldap_user_by_mail(conn, mail): | ||
mail_query = '(%s=%s)' % (ldap_config['mail_attribute'], mail) | ||
def get_ldap_user_by_mail(conn, mail, attribute_type): | ||
if attribute_type is "canonical": | ||
mail_attribute = ldap_config['mail_attribute'] | ||
elif attribute_type is "alias": | ||
mail_attribute = ldap_config['alias_attribute'] | ||
mail_query = '(%s=%s)' % (mail_attribute, mail) | ||
disabled_query = ldap_config['disabled_query'] | ||
member = conn.search_s('dc=mozilla', | ||
ldap.SCOPE_SUBTREE, | ||
|
@@ -115,7 +118,9 @@ def main(prog_args=None): | |
|
||
opt, args = parser.parse_args(sys.argv[1:]) | ||
|
||
active_users = list_all_active_users() | ||
all_users = list_all_users() | ||
|
||
active_users = list_active_users(all_users) | ||
|
||
ldap_conn = ldap.initialize('ldap://%s' % ldap_config['ldap_host']) | ||
ldap_conn.simple_bind_s(ldap_config['ldap_user'], ldap_config['ldap_pass']) | ||
|
@@ -132,12 +137,14 @@ def main(prog_args=None): | |
print "Cannot get id attribute for user" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wont the code fail here, if id is not defined/defined to last value from previous loop? |
||
|
||
if id and email: | ||
active_ldap_account = get_ldap_user_by_mail(ldap_conn, email) | ||
if active_ldap_account is not True\ | ||
and email not in disable_deactivated_accounts_config['exclusion_list']: | ||
print "Disabling Auth0 for %s" % email | ||
if not opt.debug: | ||
disable_user(id) | ||
for domain in ldap_config['ldap_domains']: | ||
if domain in email: | ||
if get_ldap_user_by_mail(ldap_conn, email, "canonical") is not True\ | ||
and get_ldap_user_by_mail(ldap_conn, email, "alias") is not True\ | ||
and email not in disable_deactivated_accounts_config['exclusion_list']: | ||
print "Disabling Auth0 for %s" % email | ||
if not opt.debug: | ||
disable_user(id) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no commented out code =)