{"action":"created","comment":{"url":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls/comments/31114771","id":31114771,"diff_hunk":"@@ -36,47 +39,96 @@ class AuthorizationManager():\n     \"\"\"\n     myClient = None\n     client = requests\n+    session = None\n \n-    def generate_adminToken(self, username, password, url):\n-        \"\"\"This method generates an admin token.\"\"\"\n+    def generate_session(self, username, password, tenant_id, tenant_name, user_domain_name, auth_api, url):\n+        \"\"\"\n+        Init the variables related to authorization, needed to execute tests\n+        :return: The auth token retrieved\n+        \"\"\"\n+\n+        cred_kwargs = {\n+            'auth_url': url,\n+            'username': username,\n+            'password': password\n+        }\n+\n+        # Currently, both v2 and v3 Identity API versions are supported\n+        if auth_api == 'v2.0':\n+            cred_kwargs['tenant_name'] = tenant_name\n+        elif auth_api == 'v3':\n+            cred_kwargs['user_domain_name'] = user_domain_name\n+\n+        # Instantiate a Password object\n         try:\n-            admin_client = self.myClient.Client(username=username, password=password, auth_url=url)\n-            return admin_client.auth_token\n-        except AuthorizationFailure as auf:\n-            raise(auf)\n-        except Unauthorized as unauth:\n-            raise(unauth)\n+            identity_package = 'keystoneclient.auth.identity.%s' % auth_api.replace('.0', '')\n+            identity_module = __import__(identity_package, fromlist=['Password'])\n+            password_class = getattr(identity_module, 'Password')\n+            logger.debug(\"Authentication with %s\", password_class)\n+            credentials = password_class(**cred_kwargs)\n+        except (ImportError, AttributeError) as e:\n+                raise e\n+        # Get auth token\n+        logger.debug(\"Getting auth token for tenant %s...\", tenant_id)\n+        print cred_kwargs\n+        try:\n+            auth_sess = self.session.Session(auth=credentials, timeout=DEFAULT_REQUEST_TIMEOUT)\n+            auth_token = auth_sess.get_token()\n+            print(\"Admin token generated:\" + auth_token)\n \n-    def checkToken(self, admin_token, token, tenant_id, url):\n+        except (KeystoneClientException, KeystoneConnectionRefused) as e:\n+            logger.error(\"No auth token (%s)\", e.message)\n+            print e.message\n+            raise(e)\n+\n+        return auth_token\n+\n+    def checkToken(self, admin_token, token, tenant_id, url, auth_api):\n         \"\"\"checks if a token is valid against a url using an admin token.\"\"\"\n-        print(\"Starting Authentication of token %s \" % token)\n+        logger.info(\"Starting Authentication of token %s \" % token)\n         try:\n             if not token:\n                 raise Unauthorized(\"Token is empty\")\n-            auth_result = self.get_info_token(url, admin_token, token)\n+            auth_result = self.get_info_token(url, admin_token, token, auth_api)\n             if auth_result:\n                 if tenant_id == auth_result.tenant[\"id\"]:\n-                    print('The token is valid')\n+                    logger.info('The token is valid')\n                 else:\n+                    logger.error(\"TenantId %s \" % tenant_id)\n+                    logger.error(\"Token TenantId %s \" % auth_result.tenant[\"id\"])","path":"cloto/manager/AuthorizationManager.py","position":89,"original_position":89,"commit_id":"d831da338dab5eedae38f2fc78128e19c3489910","original_commit_id":"d831da338dab5eedae38f2fc78128e19c3489910","user":{"login":"pratid","id":2345596,"avatar_url":"https://avatars.githubusercontent.com/u/2345596?v=3","gravatar_id":"","url":"https://api.github.com/users/pratid","html_url":"https://github.com/pratid","followers_url":"https://api.github.com/users/pratid/followers","following_url":"https://api.github.com/users/pratid/following{/other_user}","gists_url":"https://api.github.com/users/pratid/gists{/gist_id}","starred_url":"https://api.github.com/users/pratid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pratid/subscriptions","organizations_url":"https://api.github.com/users/pratid/orgs","repos_url":"https://api.github.com/users/pratid/repos","events_url":"https://api.github.com/users/pratid/events{/privacy}","received_events_url":"https://api.github.com/users/pratid/received_events","type":"User","site_admin":false},"body":"Idem as before","created_at":"2015-05-27T09:03:17Z","updated_at":"2015-05-27T09:03:17Z","html_url":"https://github.com/telefonicaid/fiware-cloto/pull/34#discussion_r31114771","pull_request_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls/34","_links":{"self":{"href":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls/comments/31114771"},"html":{"href":"https://github.com/telefonicaid/fiware-cloto/pull/34#discussion_r31114771"},"pull_request":{"href":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls/34"}}},"pull_request":{"url":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls/34","id":36184384,"html_url":"https://github.com/telefonicaid/fiware-cloto/pull/34","diff_url":"https://github.com/telefonicaid/fiware-cloto/pull/34.diff","patch_url":"https://github.com/telefonicaid/fiware-cloto/pull/34.patch","issue_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/issues/34","number":34,"state":"open","locked":false,"title":"Implementing Connection with Keystone APIv3","user":{"login":"geonexus","id":7373366,"avatar_url":"https://avatars.githubusercontent.com/u/7373366?v=3","gravatar_id":"","url":"https://api.github.com/users/geonexus","html_url":"https://github.com/geonexus","followers_url":"https://api.github.com/users/geonexus/followers","following_url":"https://api.github.com/users/geonexus/following{/other_user}","gists_url":"https://api.github.com/users/geonexus/gists{/gist_id}","starred_url":"https://api.github.com/users/geonexus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geonexus/subscriptions","organizations_url":"https://api.github.com/users/geonexus/orgs","repos_url":"https://api.github.com/users/geonexus/repos","events_url":"https://api.github.com/users/geonexus/events{/privacy}","received_events_url":"https://api.github.com/users/geonexus/received_events","type":"User","site_admin":false},"body":"### REVIEWERS\r\n@flopezag @pratid \r\n\r\n### DESCRIPTION\r\nDevelop the functionality to connect Policy Manager with Keystone using APIv3","created_at":"2015-05-26T09:34:10Z","updated_at":"2015-05-27T09:03:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bc1720b73c361ee1169e9af8d1f1f2b2476021a6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls/34/commits","review_comments_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls/34/comments","review_comment_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls/comments{/number}","comments_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/issues/34/comments","statuses_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/statuses/d831da338dab5eedae38f2fc78128e19c3489910","head":{"label":"telefonicaid:feature/CLAUDIA-4912","ref":"feature/CLAUDIA-4912","sha":"d831da338dab5eedae38f2fc78128e19c3489910","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":18985908,"name":"fiware-cloto","full_name":"telefonicaid/fiware-cloto","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-cloto","description":"Policy Manager GEi of the FI-WARE project","fork":false,"url":"https://api.github.com/repos/telefonicaid/fiware-cloto","forks_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/forks","keys_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/teams","hooks_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/hooks","issue_events_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/issues/events{/number}","events_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/events","assignees_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/assignees{/user}","branches_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/branches{/branch}","tags_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/tags","blobs_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/git/refs{/sha}","trees_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/statuses/{sha}","languages_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/languages","stargazers_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/stargazers","contributors_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/contributors","subscribers_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/subscribers","subscription_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/subscription","commits_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/commits{/sha}","git_commits_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/git/commits{/sha}","comments_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/comments{/number}","issue_comment_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/issues/comments{/number}","contents_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/contents/{+path}","compare_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/merges","archive_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/downloads","issues_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/issues{/number}","pulls_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls{/number}","milestones_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/milestones{/number}","notifications_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/labels{/name}","releases_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/releases{/id}","created_at":"2014-04-21T07:44:02Z","updated_at":"2015-04-30T16:39:21Z","pushed_at":"2015-05-26T10:14:23Z","git_url":"git://github.com/telefonicaid/fiware-cloto.git","ssh_url":"git@github.com:telefonicaid/fiware-cloto.git","clone_url":"https://github.com/telefonicaid/fiware-cloto.git","svn_url":"https://github.com/telefonicaid/fiware-cloto","homepage":"","size":1161,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":1,"forks":5,"open_issues":1,"watchers":0,"default_branch":"develop"}},"base":{"label":"telefonicaid:develop","ref":"develop","sha":"f0f3c5859ab1b2bc906678c0eec6623a18d51e8d","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":18985908,"name":"fiware-cloto","full_name":"telefonicaid/fiware-cloto","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-cloto","description":"Policy Manager GEi of the FI-WARE project","fork":false,"url":"https://api.github.com/repos/telefonicaid/fiware-cloto","forks_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/forks","keys_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/teams","hooks_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/hooks","issue_events_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/issues/events{/number}","events_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/events","assignees_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/assignees{/user}","branches_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/branches{/branch}","tags_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/tags","blobs_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/git/refs{/sha}","trees_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/statuses/{sha}","languages_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/languages","stargazers_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/stargazers","contributors_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/contributors","subscribers_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/subscribers","subscription_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/subscription","commits_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/commits{/sha}","git_commits_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/git/commits{/sha}","comments_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/comments{/number}","issue_comment_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/issues/comments{/number}","contents_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/contents/{+path}","compare_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/merges","archive_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/downloads","issues_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/issues{/number}","pulls_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls{/number}","milestones_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/milestones{/number}","notifications_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/labels{/name}","releases_url":"https://api.github.com/repos/telefonicaid/fiware-cloto/releases{/id}","created_at":"2014-04-21T07:44:02Z","updated_at":"2015-04-30T16:39:21Z","pushed_at":"2015-05-26T10:14:23Z","git_url":"git://github.com/telefonicaid/fiware-cloto.git","ssh_url":"git@github.com:telefonicaid/fiware-cloto.git","clone_url":"https://github.com/telefonicaid/fiware-cloto.git","svn_url":"https://github.com/telefonicaid/fiware-cloto","homepage":"","size":1161,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":1,"forks":5,"open_issues":1,"watchers":0,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls/34"},"html":{"href":"https://github.com/telefonicaid/fiware-cloto/pull/34"},"issue":{"href":"https://api.github.com/repos/telefonicaid/fiware-cloto/issues/34"},"comments":{"href":"https://api.github.com/repos/telefonicaid/fiware-cloto/issues/34/comments"},"review_comments":{"href":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls/34/comments"},"review_comment":{"href":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/telefonicaid/fiware-cloto/pulls/34/commits"},"statuses":{"href":"https://api.github.com/repos/telefonicaid/fiware-cloto/statuses/d831da338dab5eedae38f2fc78128e19c3489910"}}}}