{"action":"created","comment":{"url":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls/comments/70208831","id":70208831,"diff_hunk":"@@ -23,150 +23,197 @@\n \n \n import json\n+import datetime\n+\n+from fiwareskuld.conf import settings\n import requests\n-from datetime import datetime\n-from conf import settings\n from fiwareskuld.utils.log import logger\n+from fiwareskuld.utils import osclients\n+from fiwareskuld.create_users import CreateUser\n \n \n class ExpiredUsers:\n     def __init__(self, tenant=None, username=None, password=None):\n-        \"\"\" Initialize the class with the appropriate parameters.\n-        \"\"\"\n-        self.TRIAL_ROLE_ID = settings.TRIAL_ROLE_ID\n-        self.BASIC_ROLE_ID = settings.BASIC_ROLE_ID\n-        self.KEYSTONE_ENDPOINT = settings.KEYSTONE_ENDPOINT\n-        self.v20 = \"v2.0/\"\n-        self.v30 = \"v3/\"\n-        self.token = None\n-        self.listUsers = []\n-        self.MAX_NUMBER_OF_DAYS = settings.MAX_NUMBER_OF_DAYS\n-        self.finalList = []\n-        self.yellowList = []\n+        \"\"\"Constructor. Create a keystone client\"\"\"\n         self.__tenant = tenant\n         self.__username = username\n         self.__password = password\n-\n-    def get_admin_token(self):\n+        clients = osclients.OpenStackClients()\n+        clients.override_endpoint(\n+            'identity', clients.region, 'admin', settings.KEYSTONE_ENDPOINT)\n+        self.TRIAL_MAX_NUMBER_OF_DAYS = settings.TRIAL_MAX_NUMBER_OF_DAYS\n+        self.COMMUNITY_MAX_NUMBER_OF_DAYS = settings.COMMUNITY_MAX_NUMBER_OF_DAYS\n+        self.keystoneclient = clients.get_keystoneclientv3()\n+        self.protected = set()\n+        self.user_create = CreateUser()\n+\n+    def get_trial_user_ids(self):\n+        \"\"\"Get a set of trial users; only the ids\n+        :return: a set of user ids, corresponding to trial users.\n         \"\"\"\n-        Return the admin token for a administrator user, this value is\n-        maintained in the internal attribute \"token\" of the class.\n-        :return: The admin token to be used in the X-Auth-Token header\n+        k = self.keystoneclient\n+        role = k.roles.find(name=\"trial\")\n+        return set(e.user['id'] for e in k.role_assignments.list(\n+            role=role.id))\n+\n+    def get_community_user_ids(self):\n+        \"\"\"Get a set of community users; only the ids\n+        :return: a set of user ids, corresponding to trial users.\n         \"\"\"\n+        k = self.keystoneclient\n+        role = k.roles.find(name=\"community\")\n+        return set(e.user['id'] for e in k.role_assignments.list(\n+            role=role.id))\n+\n+    def get_basic_users_ids(self):\n+        \"\"\"Get a set of basic users; only the ids\n+        :return: a set of user ids, corresponding to trial users.\n+        \"\"\"\n+        k = self.keystoneclient\n+        role = k.roles.find(name=\"basic\")\n+        return set(e.user['id'] for e in k.role_assignments.list(\n+            role=role.id))\n+\n+    def get_basic_users(self):\n+        \"\"\"Get the list of basic users; the full objects are included.\n+        :return: a list of trial users\n+        \"\"\"\n+        user_ids = self.get_basic_users_ids()\n+        return list(user for user in self.keystoneclient.users.list() if user.id in user_ids)\n \n-        self.__check_credentials()\n-\n-        payload = \"{\\\"auth\\\":{\\\"tenantName\\\":\\\"%s\\\",\" \\\n-                  \"\\\"passwordCredentials\\\":{\\\"username\\\":\\\"%s\\\",\\\"password\\\":\\\"%s\\\"}}}\" \\\n-                  % (self.__tenant, self.__username, self.__password)\n-        headers = {'content-type': 'application/json'}\n-        url = self.KEYSTONE_ENDPOINT + self.v20 + \"tokens\"\n-        r = requests.post(url=url, data=payload, headers=headers)\n-\n-        rjson = json.loads(r.text)\n-\n-        if r.status_code == 200:\n+    def get_trial_users(self):\n+        \"\"\"Get the list of trial users; the full objects are included.\n+        :return: a list of trial users\n+        \"\"\"\n+        user_ids = self.get_trial_user_ids()\n+        return list(user for user in self.keystoneclient.users.list() if user.id in user_ids)\n \n-            self.token = rjson['access']['token']['id']\n+    def get_community_users(self):\n+        \"\"\"Get the list of community users; the full objects are included.\n+        :return: a list of community users\n+        \"\"\"\n+        user_ids = self.get_community_user_ids()\n \n-            logger.info(\"Admin token requested: %s\", self.token)\n-        else:\n-            raise Exception(rjson['error']['message'])\n+        d = list(user for user in self.keystoneclient.users.list() if user.id in user_ids)\n+        return d\n \n-        return self.token\n+    def get_users(self):\n+        \"\"\"Get the list of trial users; the full objects are included.","path":"fiwareskuld/expired_users.py","position":115,"original_position":115,"commit_id":"df25d0beabb1046101228203ee02dcfa5cb58e37","original_commit_id":"df25d0beabb1046101228203ee02dcfa5cb58e37","user":{"login":"flopezag","id":1379796,"avatar_url":"https://avatars.githubusercontent.com/u/1379796?v=3","gravatar_id":"","url":"https://api.github.com/users/flopezag","html_url":"https://github.com/flopezag","followers_url":"https://api.github.com/users/flopezag/followers","following_url":"https://api.github.com/users/flopezag/following{/other_user}","gists_url":"https://api.github.com/users/flopezag/gists{/gist_id}","starred_url":"https://api.github.com/users/flopezag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flopezag/subscriptions","organizations_url":"https://api.github.com/users/flopezag/orgs","repos_url":"https://api.github.com/users/flopezag/repos","events_url":"https://api.github.com/users/flopezag/events{/privacy}","received_events_url":"https://api.github.com/users/flopezag/received_events","type":"User","site_admin":false},"body":"I think that the descripcion is not correct.","created_at":"2016-07-11T06:54:32Z","updated_at":"2016-07-11T06:54:32Z","html_url":"https://github.com/telefonicaid/fiware-skuld/pull/94#discussion_r70208831","pull_request_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls/94","_links":{"self":{"href":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls/comments/70208831"},"html":{"href":"https://github.com/telefonicaid/fiware-skuld/pull/94#discussion_r70208831"},"pull_request":{"href":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls/94"}}},"pull_request":{"url":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls/94","id":76744053,"html_url":"https://github.com/telefonicaid/fiware-skuld/pull/94","diff_url":"https://github.com/telefonicaid/fiware-skuld/pull/94.diff","patch_url":"https://github.com/telefonicaid/fiware-skuld/pull/94.patch","issue_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/issues/94","number":94,"state":"open","locked":false,"title":"Acceptance tests","user":{"login":"hmunfru","id":1541508,"avatar_url":"https://avatars.githubusercontent.com/u/1541508?v=3","gravatar_id":"","url":"https://api.github.com/users/hmunfru","html_url":"https://github.com/hmunfru","followers_url":"https://api.github.com/users/hmunfru/followers","following_url":"https://api.github.com/users/hmunfru/following{/other_user}","gists_url":"https://api.github.com/users/hmunfru/gists{/gist_id}","starred_url":"https://api.github.com/users/hmunfru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hmunfru/subscriptions","organizations_url":"https://api.github.com/users/hmunfru/orgs","repos_url":"https://api.github.com/users/hmunfru/repos","events_url":"https://api.github.com/users/hmunfru/events{/privacy}","received_events_url":"https://api.github.com/users/hmunfru/received_events","type":"User","site_admin":false},"body":"#### REVIEWERS\r\n@flopezag  @hmunfru \r\n\r\n#### DESCRIPTION\r\n- Adding acceptance tests for get users and expired users\r\n\r\n#### TESTING\r\nLocally","created_at":"2016-07-08T12:18:38Z","updated_at":"2016-07-11T06:54:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9fbf8b152addf607fab803f83b7309f06fd4d24e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls/94/commits","review_comments_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls/94/comments","review_comment_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls/comments{/number}","comments_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/issues/94/comments","statuses_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/statuses/df25d0beabb1046101228203ee02dcfa5cb58e37","head":{"label":"telefonicaid:acceptance_tests","ref":"acceptance_tests","sha":"df25d0beabb1046101228203ee02dcfa5cb58e37","user":{"login":"telefonicaid","id":968363,"avatar_url":"https://avatars.githubusercontent.com/u/968363?v=3","gravatar_id":"","url":"https://api.github.com/users/telefonicaid","html_url":"https://github.com/telefonicaid","followers_url":"https://api.github.com/users/telefonicaid/followers","following_url":"https://api.github.com/users/telefonicaid/following{/other_user}","gists_url":"https://api.github.com/users/telefonicaid/gists{/gist_id}","starred_url":"https://api.github.com/users/telefonicaid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telefonicaid/subscriptions","organizations_url":"https://api.github.com/users/telefonicaid/orgs","repos_url":"https://api.github.com/users/telefonicaid/repos","events_url":"https://api.github.com/users/telefonicaid/events{/privacy}","received_events_url":"https://api.github.com/users/telefonicaid/received_events","type":"Organization","site_admin":false},"repo":{"id":42667533,"name":"fiware-skuld","full_name":"telefonicaid/fiware-skuld","owner":{"login":"telefonicaid","id":968363,"avatar_url":"https://avatars.githubusercontent.com/u/968363?v=3","gravatar_id":"","url":"https://api.github.com/users/telefonicaid","html_url":"https://github.com/telefonicaid","followers_url":"https://api.github.com/users/telefonicaid/followers","following_url":"https://api.github.com/users/telefonicaid/following{/other_user}","gists_url":"https://api.github.com/users/telefonicaid/gists{/gist_id}","starred_url":"https://api.github.com/users/telefonicaid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telefonicaid/subscriptions","organizations_url":"https://api.github.com/users/telefonicaid/orgs","repos_url":"https://api.github.com/users/telefonicaid/repos","events_url":"https://api.github.com/users/telefonicaid/events{/privacy}","received_events_url":"https://api.github.com/users/telefonicaid/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/telefonicaid/fiware-skuld","description":"FIWARE FIOps project to delete the resources of the expired Trial Users","fork":false,"url":"https://api.github.com/repos/telefonicaid/fiware-skuld","forks_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/forks","keys_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/keys{/key_id}","collaborators_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/teams","hooks_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/hooks","issue_events_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/issues/events{/number}","events_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/events","assignees_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/assignees{/user}","branches_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/branches{/branch}","tags_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/tags","blobs_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/git/refs{/sha}","trees_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/git/trees{/sha}","statuses_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/statuses/{sha}","languages_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/languages","stargazers_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/stargazers","contributors_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/contributors","subscribers_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/subscribers","subscription_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/subscription","commits_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/commits{/sha}","git_commits_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/git/commits{/sha}","comments_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/comments{/number}","issue_comment_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/issues/comments{/number}","contents_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/contents/{+path}","compare_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/compare/{base}...{head}","merges_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/merges","archive_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/downloads","issues_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/issues{/number}","pulls_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls{/number}","milestones_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/milestones{/number}","notifications_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/labels{/name}","releases_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/releases{/id}","deployments_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/deployments","created_at":"2015-09-17T16:25:26Z","updated_at":"2016-01-13T16:44:13Z","pushed_at":"2016-07-08T12:18:38Z","git_url":"git://github.com/telefonicaid/fiware-skuld.git","ssh_url":"git@github.com:telefonicaid/fiware-skuld.git","clone_url":"https://github.com/telefonicaid/fiware-skuld.git","svn_url":"https://github.com/telefonicaid/fiware-skuld","homepage":null,"size":534,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"base":{"label":"telefonicaid:develop","ref":"develop","sha":"5ddc2f8558a8ea97edb16cb91d6a39cfaecb8821","user":{"login":"telefonicaid","id":968363,"avatar_url":"https://avatars.githubusercontent.com/u/968363?v=3","gravatar_id":"","url":"https://api.github.com/users/telefonicaid","html_url":"https://github.com/telefonicaid","followers_url":"https://api.github.com/users/telefonicaid/followers","following_url":"https://api.github.com/users/telefonicaid/following{/other_user}","gists_url":"https://api.github.com/users/telefonicaid/gists{/gist_id}","starred_url":"https://api.github.com/users/telefonicaid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telefonicaid/subscriptions","organizations_url":"https://api.github.com/users/telefonicaid/orgs","repos_url":"https://api.github.com/users/telefonicaid/repos","events_url":"https://api.github.com/users/telefonicaid/events{/privacy}","received_events_url":"https://api.github.com/users/telefonicaid/received_events","type":"Organization","site_admin":false},"repo":{"id":42667533,"name":"fiware-skuld","full_name":"telefonicaid/fiware-skuld","owner":{"login":"telefonicaid","id":968363,"avatar_url":"https://avatars.githubusercontent.com/u/968363?v=3","gravatar_id":"","url":"https://api.github.com/users/telefonicaid","html_url":"https://github.com/telefonicaid","followers_url":"https://api.github.com/users/telefonicaid/followers","following_url":"https://api.github.com/users/telefonicaid/following{/other_user}","gists_url":"https://api.github.com/users/telefonicaid/gists{/gist_id}","starred_url":"https://api.github.com/users/telefonicaid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telefonicaid/subscriptions","organizations_url":"https://api.github.com/users/telefonicaid/orgs","repos_url":"https://api.github.com/users/telefonicaid/repos","events_url":"https://api.github.com/users/telefonicaid/events{/privacy}","received_events_url":"https://api.github.com/users/telefonicaid/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/telefonicaid/fiware-skuld","description":"FIWARE FIOps project to delete the resources of the expired Trial Users","fork":false,"url":"https://api.github.com/repos/telefonicaid/fiware-skuld","forks_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/forks","keys_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/keys{/key_id}","collaborators_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/teams","hooks_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/hooks","issue_events_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/issues/events{/number}","events_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/events","assignees_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/assignees{/user}","branches_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/branches{/branch}","tags_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/tags","blobs_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/git/refs{/sha}","trees_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/git/trees{/sha}","statuses_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/statuses/{sha}","languages_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/languages","stargazers_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/stargazers","contributors_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/contributors","subscribers_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/subscribers","subscription_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/subscription","commits_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/commits{/sha}","git_commits_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/git/commits{/sha}","comments_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/comments{/number}","issue_comment_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/issues/comments{/number}","contents_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/contents/{+path}","compare_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/compare/{base}...{head}","merges_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/merges","archive_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/downloads","issues_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/issues{/number}","pulls_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls{/number}","milestones_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/milestones{/number}","notifications_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/labels{/name}","releases_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/releases{/id}","deployments_url":"https://api.github.com/repos/telefonicaid/fiware-skuld/deployments","created_at":"2015-09-17T16:25:26Z","updated_at":"2016-01-13T16:44:13Z","pushed_at":"2016-07-08T12:18:38Z","git_url":"git://github.com/telefonicaid/fiware-skuld.git","ssh_url":"git@github.com:telefonicaid/fiware-skuld.git","clone_url":"https://github.com/telefonicaid/fiware-skuld.git","svn_url":"https://github.com/telefonicaid/fiware-skuld","homepage":null,"size":534,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls/94"},"html":{"href":"https://github.com/telefonicaid/fiware-skuld/pull/94"},"issue":{"href":"https://api.github.com/repos/telefonicaid/fiware-skuld/issues/94"},"comments":{"href":"https://api.github.com/repos/telefonicaid/fiware-skuld/issues/94/comments"},"review_comments":{"href":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls/94/comments"},"review_comment":{"href":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/telefonicaid/fiware-skuld/pulls/94/commits"},"statuses":{"href":"https://api.github.com/repos/telefonicaid/fiware-skuld/statuses/df25d0beabb1046101228203ee02dcfa5cb58e37"}}}}
{"actor":{"display_login":"flopezag"}}