def setUp(self): self.token = 'TESTINGOAUTHSTUFF' self.header = {'Authorization': 'Bearer ' + self.token} r_client.hset(self.token, 'timestamp', '12/12/12 12:12:00') r_client.hset(self.token, 'grant_type', 'client') r_client.expire(self.token, 20) super(OauthTestingBase, self).setUp()
def post(self, analysis_id): analysis_id = int(analysis_id) rarefaction_depth = self.get_argument('rarefaction-depth') mdsi = self.get_argument('merge-duplicated-sample-ids', default=False) if mdsi == 'on': mdsi = True # convert to integer if rarefaction level given if rarefaction_depth: rarefaction_depth = int(rarefaction_depth) else: rarefaction_depth = None analysis = Analysis(analysis_id) check_analysis_access(self.current_user, analysis) command_args = self.get_arguments("commands") cmd_split = [x.split("#") for x in command_args] moi_user_id = get_id_from_user(self.current_user.id) moi_group = create_info(analysis_id, 'group', url='/analysis/', parent=moi_user_id, store=True) moi_name = ("Creating %s... When finished, please click the 'Success' " "link to the right" % analysis.name) moi_result_url = '/analysis/results/%d' % analysis_id submit(ctx_default, moi_group['id'], moi_name, moi_result_url, run_analysis, analysis_id, cmd_split, rarefaction_depth=rarefaction_depth, merge_duplicated_sample_ids=mdsi) r_client.hset('analyis-map', analysis_id, moi_group['id']) self.render("analysis_waiting.html", group_id=moi_group['id'], aname=analysis.name)
def post(self, analysis_id): analysis_id = int(analysis_id) rarefaction_depth = self.get_argument('rarefaction-depth') # convert to integer if rarefaction level given if rarefaction_depth: rarefaction_depth = int(rarefaction_depth) else: rarefaction_depth = None analysis = Analysis(analysis_id) check_analysis_access(self.current_user, analysis) command_args = self.get_arguments("commands") split = [x.split("#") for x in command_args] moi_user_id = get_id_from_user(self.current_user.id) moi_group = create_info(analysis_id, 'group', url='/analysis/', parent=moi_user_id, store=True) moi_name = 'Creating %s' % analysis.name moi_result_url = '/analysis/results/%d' % analysis_id submit(ctx_default, moi_group['id'], moi_name, moi_result_url, run_analysis, analysis_id, split, rarefaction_depth=rarefaction_depth) r_client.hset('analyis-map', analysis_id, moi_group['id']) self.render("analysis_waiting.html", group_id=moi_group['id'], aname=analysis.name)
def get_id_from_user(user): """Get an ID from a user, creates if necessary""" id = r_client.hget('user-id-map', user) if id is None: id = str(uuid4()) r_client.hset('user-id-map', user, id) r_client.hset('user-id-map', id, user) return id
def setUp(self): r_client.hset('user-id-map', 'testing', 'testing') r_client.sadd('testing:children', 'a') r_client.sadd('testing:children', 'b') r_client.sadd('testing:children', 'c') r_client.set('a', '{"type": "job", "id": "a", "name": "a"}') r_client.set('b', '{"type": "job", "id": "b", "name": "b"}') r_client.set('c', '{"type": "job", "id": "c", "name": "c"}') r_client.set('d', '{"type": "job", "id": "d", "name": "other job"}') r_client.set('e', '{"type": "job", "id": "e", "name": "other job e"}') self.obj = Group('testing')
def setUp(self): r_client.hset('user-id-map', 'testing', 'testing') r_client.sadd('testing:children', 'a') r_client.sadd('testing:children', 'b') r_client.sadd('testing:children', 'c') r_client.set('a', '{"type": "job", "id": "a", "name": "a"}') r_client.set('b', '{"type": "job", "id": "b", "name": "b"}') r_client.set('c', '{"type": "job", "id": "c", "name": "c"}') r_client.set('d', '{"type": "job", "id": "d", "name": "other job"}') r_client.set('e', '{"type": "job", "id": "e", "name": "other job e"}') self.obj = Group('testing') self.to_delete = ['testing', 'testing:jobs', 'testing:children', 'user-id-map', 'a', 'b', 'c', 'd', 'e']
def post(self, analysis_id): analysis_id = int(analysis_id) rarefaction_depth = self.get_argument('rarefaction-depth') mdsi = self.get_argument('merge-duplicated-sample-ids', default=False) if mdsi == 'on': mdsi = True # convert to integer if rarefaction level given if rarefaction_depth: rarefaction_depth = int(rarefaction_depth) else: rarefaction_depth = None analysis = Analysis(analysis_id) check_analysis_access(self.current_user, analysis) command_args = self.get_arguments("commands") cmd_split = [x.split("#") for x in command_args] moi_user_id = get_id_from_user(self.current_user.id) moi_group = create_info(analysis_id, 'group', url='%s/analysis/' % qiita_config.portal_dir, parent=moi_user_id, store=True) moi_name = ("Creating %s... When finished, please click the 'Success' " "link to the right" % analysis.name) moi_result_url = '%s/analysis/results/%d' % (qiita_config.portal_dir, analysis_id) submit(ctx_default, moi_group['id'], moi_name, moi_result_url, run_analysis, analysis_id, cmd_split, rarefaction_depth=rarefaction_depth, merge_duplicated_sample_ids=mdsi) r_client.hset('analyis-map', analysis_id, moi_group['id']) self.render("analysis_waiting.html", group_id=moi_group['id'], aname=analysis.name)
def post(self, analysis_id): analysis_id = int(analysis_id) rarefaction_depth = self.get_argument('rarefaction-depth') # convert to integer if rarefaction level given if rarefaction_depth: rarefaction_depth = int(rarefaction_depth) else: rarefaction_depth = None analysis = Analysis(analysis_id) check_analysis_access(self.current_user, analysis) command_args = self.get_arguments("commands") split = [x.split("#") for x in command_args] moi_user_id = get_id_from_user(self.current_user.id) moi_group = create_info(analysis_id, 'group', url='/analysis/', parent=moi_user_id, store=True) moi_name = ("Creating %s... When finished, please click the 'Success' " "link to the right" % analysis.name) moi_result_url = '/analysis/results/%d' % analysis_id submit(ctx_default, moi_group['id'], moi_name, moi_result_url, run_analysis, analysis_id, split, rarefaction_depth=rarefaction_depth) r_client.hset('analyis-map', analysis_id, moi_group['id']) self.render("analysis_waiting.html", group_id=moi_group['id'], aname=analysis.name)
def set_token(self, client_id, grant_type, user=None, timeout=3600): """Create access token for the client on redis and send json response Parameters ---------- client_id : str Client that requested the token grant_type : str Type of key being requested user : str, optional If password grant type requested, the user requesting the key. timeout : int, optional The timeout, in seconds, for the token. Default 3600 Returns ------- Writes token information JSON in the form expected by RFC6750: {'access_token': token, 'token_type': 'Bearer', 'expires_in': timeout} access_token: the actual token to use token_type: 'Bearer', which is the expected token type for Oauth2 expires_in: time to token expiration, in seconds. """ token = self.generate_access_token() r_client.hset(token, 'timestamp', datetime.datetime.now()) r_client.hset(token, 'client_id', client_id) r_client.hset(token, 'grant_type', grant_type) r_client.expire(token, timeout) if user: r_client.hset(token, 'user', user) if grant_type == 'password': # Check if client has access limit key, and if not, create it limit_key = '%s_%s_daily_limit' % (client_id, user) limiter = r_client.get(limit_key) if limiter is None: # Set limit to 5,000 requests per day r_client.setex(limit_key, 5000, 86400) self.write({ 'access_token': token, 'token_type': 'Bearer', 'expires_in': timeout }) self.finish()
def setUp(self): self.client_token = 'SOMEAUTHTESTINGTOKENHERE2122' r_client.hset(self.client_token, 'timestamp', '12/12/12 12:12:00') r_client.hset(self.client_token, 'client_id', 'test123123123') r_client.hset(self.client_token, 'grant_type', 'client') r_client.expire(self.client_token, 5) self.headers = {'Authorization': 'Bearer ' + self.client_token} super(RESTHandlerTestCase, self).setUp()
def set_token(self, client_id, grant_type, user=None, timeout=3600): """Create access token for the client on redis and send json response Parameters ---------- client_id : str Client that requested the token grant_type : str Type of key being requested user : str, optional If password grant type requested, the user requesting the key. timeout : int, optional The timeout, in seconds, for the token. Default 3600 Returns ------- Writes token information JSON in the form expected by RFC6750: {'access_token': token, 'token_type': 'Bearer', 'expires_in': timeout} access_token: the actual token to use token_type: 'Bearer', which is the expected token type for Oauth2 expires_in: time to token expiration, in seconds. """ token = self.generate_access_token() r_client.hset(token, 'timestamp', datetime.datetime.now()) r_client.hset(token, 'client_id', client_id) r_client.hset(token, 'grant_type', grant_type) r_client.expire(token, timeout) if user: r_client.hset(token, 'user', user) if grant_type == 'password': # Check if client has access limit key, and if not, create it limit_key = '%s_%s_daily_limit' % (client_id, user) limiter = r_client.get(limit_key) if limiter is None: # Set limit to 5,000 requests per day r_client.setex(limit_key, 5000, 86400) self.write({'access_token': token, 'token_type': 'Bearer', 'expires_in': timeout}) self.finish()
def setUp(self): # Create client test authentication token self.client_token = 'SOMEAUTHTESTINGTOKENHERE2122' r_client.hset(self.client_token, 'timestamp', '12/12/12 12:12:00') r_client.hset(self.client_token, 'client_id', 'test123123123') r_client.hset(self.client_token, 'grant_type', 'client') r_client.expire(self.client_token, 5) # Create username test authentication token self.user_token = 'SOMEAUTHTESTINGTOKENHEREUSERNAME' r_client.hset(self.user_token, 'timestamp', '12/12/12 12:12:00') r_client.hset(self.user_token, 'client_id', 'testuser') r_client.hset(self.user_token, 'grant_type', 'password') r_client.hset(self.user_token, 'user', '*****@*****.**') r_client.expire(self.user_token, 5) # Create test access limit token self.user_rate_key = '[email protected]_daily_limit' r_client.setex(self.user_rate_key, 2, 5) super(OAuth2BaseHandlerTests, self).setUp()