{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/pulls/comments/87088109","pull_request_review_id":7714049,"id":87088109,"diff_hunk":"@@ -0,0 +1,120 @@\n+#!/usr/bin/python\n+import sys\n+import optparse\n+import requests\n+import ldap\n+import json\n+\n+from auth0_api_settings import AUTH0_API_KEY, AUTH0_API_URL, AUTH0_CONNECTION, LDAP_HOST,\\\n+    LDAP_USER, LDAP_PASS, EXCLUSION_LIST, USE_PROXY, PROXIES\n+\n+# function to build headers that'll be used by all API calls\n+def build_headers():\n+    headers = {}\n+    headers['Authorization'] = 'Bearer %s' % AUTH0_API_KEY\n+    headers['Content-Type'] = \"application/json\"\n+    headers['Accept'] = \"application/json\"\n+    return headers\n+\n+# generic function to just get all users belonging to the specific enterprise connection\n+# it has some logic to page through a list longer than 50, stolen from the Okta version of this script, needs tested once we have more users\n+def list_all_users():\n+    should_return = False\n+    return_list = []\n+    fetch_url = \"%s/users\" % (AUTH0_API_URL)\n+    payload = {'connection': \"%s\" % AUTH0_CONNECTION, 'fields': 'user_id,email,blocked', 'include_fields': 'true'}\n+    while (should_return is False):\n+        prev_url = fetch_url\n+        if USE_PROXY is True:\n+            resp = requests.get(\n+                fetch_url,\n+                headers=build_headers(),\n+                params=payload,\n+                proxies=PROXIES\n+            )\n+        else:\n+            resp = requests.get(fetch_url, headers=build_headers(), params=payload)\n+            req = resp.request\n+        return_list += resp.json()\n+        try:\n+            fetch_url = resp.links['next']['url']\n+            if fetch_url == '' or fetch_url is None or fetch_url == prev_url:\n+                should_return = True\n+        except (KeyError, IndexError):\n+            should_return = True\n+    return return_list\n+\n+\n+# filter out only the active users\n+# active user here is defined as not being currently blocked\n+def list_all_active_users():\n+    users = list_all_users()\n+    return [user for user in users if user[u'blocked'] != True]\n+\n+\n+# this function returns the DN of the user that matches the given e-mail address\n+def get_ldap_user_by_mail(conn, mail):\n+    member = conn.search_s('dc=mozilla',\n+                           ldap.SCOPE_SUBTREE,\n+                           '(&(mail=%s)(!(employeeType=DISABLED)))' % mail,\n+                           attrlist=['mail'])\n+    try:\n+        if member[0][1]['mail'][0]:\n+            return True\n+        else:\n+            return False\n+    except (IndexError, KeyError):\n+        return None\n+\n+# this function does the actual blocking of the user in auth0\n+def disable_user(user_id):\n+    deactive_url = \"users/%s\" % user_id\n+    url = \"%s/%s\" % (AUTH0_API_URL, deactive_url)\n+    body = '{\"blocked\":true}'\n+    if USE_PROXY is True:\n+        requests.patch(url, headers=build_headers(), data=body, proxies=PROXIES)","path":"disable_deactivated_accounts.py","position":75,"original_position":75,"commit_id":"b527ed61ff802496bbe4d2fd9979657f70e7f1b4","original_commit_id":"b527ed61ff802496bbe4d2fd9979657f70e7f1b4","user":{"login":"gdestuynder","id":956866,"avatar_url":"https://avatars.githubusercontent.com/u/956866?v=3","gravatar_id":"","url":"https://api.github.com/users/gdestuynder","html_url":"https://github.com/gdestuynder","followers_url":"https://api.github.com/users/gdestuynder/followers","following_url":"https://api.github.com/users/gdestuynder/following{/other_user}","gists_url":"https://api.github.com/users/gdestuynder/gists{/gist_id}","starred_url":"https://api.github.com/users/gdestuynder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gdestuynder/subscriptions","organizations_url":"https://api.github.com/users/gdestuynder/orgs","repos_url":"https://api.github.com/users/gdestuynder/repos","events_url":"https://api.github.com/users/gdestuynder/events{/privacy}","received_events_url":"https://api.github.com/users/gdestuynder/received_events","type":"User","site_admin":false},"body":"what if the request fails? how do we know disable failed?","created_at":"2016-11-08T21:32:08Z","updated_at":"2016-11-08T21:34:06Z","html_url":"https://github.com/mozilla-iam/auth0-scripts/pull/1#discussion_r87088109","pull_request_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/mozilla-iam/auth0-scripts/pulls/comments/87088109"},"html":{"href":"https://github.com/mozilla-iam/auth0-scripts/pull/1#discussion_r87088109"},"pull_request":{"href":"https://api.github.com/repos/mozilla-iam/auth0-scripts/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/pulls/1","id":92855920,"html_url":"https://github.com/mozilla-iam/auth0-scripts/pull/1","diff_url":"https://github.com/mozilla-iam/auth0-scripts/pull/1.diff","patch_url":"https://github.com/mozilla-iam/auth0-scripts/pull/1.patch","issue_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/issues/1","number":1,"state":"open","locked":false,"title":"Add script to block users in auth0 when disabled in LDAP","user":{"login":"jdow","id":481200,"avatar_url":"https://avatars.githubusercontent.com/u/481200?v=3","gravatar_id":"","url":"https://api.github.com/users/jdow","html_url":"https://github.com/jdow","followers_url":"https://api.github.com/users/jdow/followers","following_url":"https://api.github.com/users/jdow/following{/other_user}","gists_url":"https://api.github.com/users/jdow/gists{/gist_id}","starred_url":"https://api.github.com/users/jdow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdow/subscriptions","organizations_url":"https://api.github.com/users/jdow/orgs","repos_url":"https://api.github.com/users/jdow/repos","events_url":"https://api.github.com/users/jdow/events{/privacy}","received_events_url":"https://api.github.com/users/jdow/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-11-08T20:48:06Z","updated_at":"2016-11-08T21:34:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"337a10b55cfd23525b9f058f491b702d1648236b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/pulls/1/commits","review_comments_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/pulls/1/comments","review_comment_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/issues/1/comments","statuses_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/statuses/b527ed61ff802496bbe4d2fd9979657f70e7f1b4","head":{"label":"jdow:master","ref":"master","sha":"b527ed61ff802496bbe4d2fd9979657f70e7f1b4","user":{"login":"jdow","id":481200,"avatar_url":"https://avatars.githubusercontent.com/u/481200?v=3","gravatar_id":"","url":"https://api.github.com/users/jdow","html_url":"https://github.com/jdow","followers_url":"https://api.github.com/users/jdow/followers","following_url":"https://api.github.com/users/jdow/following{/other_user}","gists_url":"https://api.github.com/users/jdow/gists{/gist_id}","starred_url":"https://api.github.com/users/jdow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdow/subscriptions","organizations_url":"https://api.github.com/users/jdow/orgs","repos_url":"https://api.github.com/users/jdow/repos","events_url":"https://api.github.com/users/jdow/events{/privacy}","received_events_url":"https://api.github.com/users/jdow/received_events","type":"User","site_admin":false},"repo":{"id":73225319,"name":"auth0-scripts","full_name":"jdow/auth0-scripts","owner":{"login":"jdow","id":481200,"avatar_url":"https://avatars.githubusercontent.com/u/481200?v=3","gravatar_id":"","url":"https://api.github.com/users/jdow","html_url":"https://github.com/jdow","followers_url":"https://api.github.com/users/jdow/followers","following_url":"https://api.github.com/users/jdow/following{/other_user}","gists_url":"https://api.github.com/users/jdow/gists{/gist_id}","starred_url":"https://api.github.com/users/jdow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdow/subscriptions","organizations_url":"https://api.github.com/users/jdow/orgs","repos_url":"https://api.github.com/users/jdow/repos","events_url":"https://api.github.com/users/jdow/events{/privacy}","received_events_url":"https://api.github.com/users/jdow/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jdow/auth0-scripts","description":"Scripts to manage auth0 via API","fork":true,"url":"https://api.github.com/repos/jdow/auth0-scripts","forks_url":"https://api.github.com/repos/jdow/auth0-scripts/forks","keys_url":"https://api.github.com/repos/jdow/auth0-scripts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jdow/auth0-scripts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jdow/auth0-scripts/teams","hooks_url":"https://api.github.com/repos/jdow/auth0-scripts/hooks","issue_events_url":"https://api.github.com/repos/jdow/auth0-scripts/issues/events{/number}","events_url":"https://api.github.com/repos/jdow/auth0-scripts/events","assignees_url":"https://api.github.com/repos/jdow/auth0-scripts/assignees{/user}","branches_url":"https://api.github.com/repos/jdow/auth0-scripts/branches{/branch}","tags_url":"https://api.github.com/repos/jdow/auth0-scripts/tags","blobs_url":"https://api.github.com/repos/jdow/auth0-scripts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jdow/auth0-scripts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jdow/auth0-scripts/git/refs{/sha}","trees_url":"https://api.github.com/repos/jdow/auth0-scripts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jdow/auth0-scripts/statuses/{sha}","languages_url":"https://api.github.com/repos/jdow/auth0-scripts/languages","stargazers_url":"https://api.github.com/repos/jdow/auth0-scripts/stargazers","contributors_url":"https://api.github.com/repos/jdow/auth0-scripts/contributors","subscribers_url":"https://api.github.com/repos/jdow/auth0-scripts/subscribers","subscription_url":"https://api.github.com/repos/jdow/auth0-scripts/subscription","commits_url":"https://api.github.com/repos/jdow/auth0-scripts/commits{/sha}","git_commits_url":"https://api.github.com/repos/jdow/auth0-scripts/git/commits{/sha}","comments_url":"https://api.github.com/repos/jdow/auth0-scripts/comments{/number}","issue_comment_url":"https://api.github.com/repos/jdow/auth0-scripts/issues/comments{/number}","contents_url":"https://api.github.com/repos/jdow/auth0-scripts/contents/{+path}","compare_url":"https://api.github.com/repos/jdow/auth0-scripts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jdow/auth0-scripts/merges","archive_url":"https://api.github.com/repos/jdow/auth0-scripts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jdow/auth0-scripts/downloads","issues_url":"https://api.github.com/repos/jdow/auth0-scripts/issues{/number}","pulls_url":"https://api.github.com/repos/jdow/auth0-scripts/pulls{/number}","milestones_url":"https://api.github.com/repos/jdow/auth0-scripts/milestones{/number}","notifications_url":"https://api.github.com/repos/jdow/auth0-scripts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jdow/auth0-scripts/labels{/name}","releases_url":"https://api.github.com/repos/jdow/auth0-scripts/releases{/id}","deployments_url":"https://api.github.com/repos/jdow/auth0-scripts/deployments","created_at":"2016-11-08T20:42:17Z","updated_at":"2016-11-08T20:46:06Z","pushed_at":"2016-11-08T20:46:05Z","git_url":"git://github.com/jdow/auth0-scripts.git","ssh_url":"git@github.com:jdow/auth0-scripts.git","clone_url":"https://github.com/jdow/auth0-scripts.git","svn_url":"https://github.com/jdow/auth0-scripts","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mozilla-iam:master","ref":"master","sha":"3a8be1a1177c13d27b3efcf21c0aece98fe670bb","user":{"login":"mozilla-iam","id":22923188,"avatar_url":"https://avatars.githubusercontent.com/u/22923188?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-iam","html_url":"https://github.com/mozilla-iam","followers_url":"https://api.github.com/users/mozilla-iam/followers","following_url":"https://api.github.com/users/mozilla-iam/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-iam/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-iam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-iam/subscriptions","organizations_url":"https://api.github.com/users/mozilla-iam/orgs","repos_url":"https://api.github.com/users/mozilla-iam/repos","events_url":"https://api.github.com/users/mozilla-iam/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-iam/received_events","type":"Organization","site_admin":false},"repo":{"id":73225291,"name":"auth0-scripts","full_name":"mozilla-iam/auth0-scripts","owner":{"login":"mozilla-iam","id":22923188,"avatar_url":"https://avatars.githubusercontent.com/u/22923188?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-iam","html_url":"https://github.com/mozilla-iam","followers_url":"https://api.github.com/users/mozilla-iam/followers","following_url":"https://api.github.com/users/mozilla-iam/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-iam/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-iam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-iam/subscriptions","organizations_url":"https://api.github.com/users/mozilla-iam/orgs","repos_url":"https://api.github.com/users/mozilla-iam/repos","events_url":"https://api.github.com/users/mozilla-iam/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-iam/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla-iam/auth0-scripts","description":"Scripts to manage auth0 via API","fork":false,"url":"https://api.github.com/repos/mozilla-iam/auth0-scripts","forks_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/forks","keys_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/teams","hooks_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/hooks","issue_events_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/events","assignees_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/tags","blobs_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/languages","stargazers_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/stargazers","contributors_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/contributors","subscribers_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/subscribers","subscription_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/subscription","commits_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/merges","archive_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/downloads","issues_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/labels{/name}","releases_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/releases{/id}","deployments_url":"https://api.github.com/repos/mozilla-iam/auth0-scripts/deployments","created_at":"2016-11-08T20:41:53Z","updated_at":"2016-11-08T20:41:53Z","pushed_at":"2016-11-08T20:48:06Z","git_url":"git://github.com/mozilla-iam/auth0-scripts.git","ssh_url":"git@github.com:mozilla-iam/auth0-scripts.git","clone_url":"https://github.com/mozilla-iam/auth0-scripts.git","svn_url":"https://github.com/mozilla-iam/auth0-scripts","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla-iam/auth0-scripts/pulls/1"},"html":{"href":"https://github.com/mozilla-iam/auth0-scripts/pull/1"},"issue":{"href":"https://api.github.com/repos/mozilla-iam/auth0-scripts/issues/1"},"comments":{"href":"https://api.github.com/repos/mozilla-iam/auth0-scripts/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla-iam/auth0-scripts/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla-iam/auth0-scripts/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla-iam/auth0-scripts/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla-iam/auth0-scripts/statuses/b527ed61ff802496bbe4d2fd9979657f70e7f1b4"}}}}
{"actor":{"display_login":"gdestuynder"}}