Esempio n. 1
0
    def get(self, tracking_id):

        logger.debug("get tracking details")
        self.check_token()
        tracking_id = utils.decrypt_value(tracking_id)
        tracking = utils.encrypt_ids(db.get_export_tracking(tracking_id))
        self.send_response(data=tracking)
Esempio n. 2
0
    def post(self, tracking_id):

        logger.debug("requeue import tracking")
        self.check_token()

        values = self.post_values()
        self.require_arguments(values, ['state'])
        state = values['state']
        try:
            tracking_id = utils.decrypt_value(tracking_id)
            tracking = db.get_import_tracking(tracking_id)
            print(tracking)
            tracking['state'] = state

            for k in ['id', 'create_time', 'update_time']:
                del tracking[k]

            tracking[
                'log'] = f"requeue import tracker {tracking_id} and changed state to {state}"
            tracking_id = db.add_import_tracking(tracking)
            tracking_id = utils.encrypt_value(tracking_id)
            submit_mq_job(tracking_id, "import")

            self.send_response_200()
        except Exception as e:
            logger.error(f"Request import tracking error {e}")
            import stacktrace
            self.send_response_404()
Esempio n. 3
0
    def patch(self, tracking_id):
        logger.debug("patch tracking details")
        self.check_token()
        data = self.post_values()
        self.valid_arguments(data, ['state', 'export_id', 'tmpfile', 'show'])
        # need to decrypt the id otherwise things blow up!
        tracking_id = utils.decrypt_value(tracking_id)

        db.update_export_tracking(tracking_id, data)
        return self.send_response_204()
Esempio n. 4
0
    def get_session_key(self):
        if DEV:
            session_key = 'ed42604e029aab1a5b1644a93288a9fa'
        else:
            cookie = self.get_cookie("galaxysession")
            if cookie is None or cookie == '':
                return None

            session_key = utils.decrypt_value(cookie)

        return session_key
Esempio n. 5
0
    def get(self, import_id=None):
        logger.debug("get history imports")
        self.check_token()

        if import_id is None:
            logger.debug('getting by history_id')
            filter = self.arguments()

            self.require_arguments(filter, [
                'history_id',
            ])
            history_id = utils.decrypt_value(filter['history_id'])
            imp = db.get_latest_import_for_history(history_id)
        else:
            logger.debug('getting by export_id')
            import_id = utils.decrypt_value(import_id)
            imp = db.get_import(import_id)

        if len(imp):
            imp = imp[0]
            imp = utils.encrypt_ids(imp)
            return self.send_response(data=imp)
        else:
            return self.send_response_404()
Esempio n. 6
0
    def get(self, export_id=None):
        logger.debug("get history exports")
        self.check_token()

        if export_id is None:
            logger.debug('getting by history_id')
            filter = self.arguments()

            self.require_arguments(filter, [
                'history_id',
            ])
            history_id = utils.decrypt_value(filter['history_id'])
            export = db.get_latest_export_for_history(history_id)
        else:
            logger.debug('getting by export_id')
            export_id = utils.decrypt_value(export_id)
            export = db.get_export(export_id)

        if len(export):
            export = export[0]
            export = utils.encrypt_ids(export)
            return self.send_response(data=export)
        else:
            return self.send_response_404()
Esempio n. 7
0
    def get(self, ):
        logger.debug("get jobs list")
        self.check_token()
        filter = self.arguments()
        logger.debug(f'arguments {filter}')
        self.valid_arguments(filter, ['time_delta', 'user_id'])

        time_delta = filter.get('time_delta', "60m")  #default 1 hour
        time_delta = utils.timedelta_to_sec(time_delta)

        user_id = filter.get('user_id', None)
        if user_id is not None:
            user_id = utils.decrypt_value(user_id)

        jobs = db.get_jobs(time_delta=time_delta, user_id=user_id)
        return self.send_response(data=utils.list_encrypt_ids(jobs))
Esempio n. 8
0
    def patch(self, tracking_id):
        logger.debug("patch tracking details")
        user = self.get_user()
        if user is None:
            self.send_response_404()
        data = self.arguments()
        self.require_arguments(data, ['show'])
        # need to decrypt the id otherwise things blow up!
        tracking_id = utils.decrypt_value(tracking_id)
        tracking = db.get_export_tracking(tracking_id)
        logger.debug(tracking)
        if user['email'] != tracking['user_email']:
            self.send_response_401()

        db.update_export_tracking(tracking_id, data)
        return self.send_response_204()
Esempio n. 9
0
    async def get(self, export_id=None):
        logger.debug("get history download")
        self.check_token()

        # chunk size to read
        chunk_size = 1024 * 1024 * 1  # 1 MiB

        export_id = utils.decrypt_value(export_id)
        export = db.get_export(export_id)[0]

        try:

            dataset = db.get_dataset(export['dataset_id'])
            filename = utils.construct_file_path(obj_id=dataset['id'],
                                                 file_dir=galaxy_file_path)
            logger.debug("start the download")

            with open(filename, 'rb') as f:
                while True:
                    chunk = f.read(chunk_size)
                    if not chunk:
                        break
                    try:
                        self.write(chunk)  # write the cunk to response
                        await self.flush()  # flush the current chunk to socket
                    except iostream.StreamClosedError:
                        # this means the client has closed the connection
                        # so break the loop
                        break
                    finally:
                        # deleting the chunk is very important because
                        # if many clients are downloading files at the
                        # same time, the chunks in memory will keep
                        # increasing and will eat up the RAM
                        del chunk
                    time.sleep(0)

        except Exception as e:
            logger.error(e)
            self.send_response_400(data={'error': str(e)})

        logger.debug("download completed")
Esempio n. 10
0
    def get(self):
        logger.debug("proxy export list")
        # Will not check token here as relying on the session id instead
        #        self.check_token()
        user = self.get_user()
        if user is None:
            self.send_response_404()

        # cannot proxy to it-self, read directly from the database
        if no_proxy:
            logger.debug('accessing the data directly')
            #            print( user )
            trackings = db.get_export_trackings(
                user_email=user['email'],
                instance=instances[instance_id]['name'])
        else:
            logger.debug('accessing the data using the proxy')
            trackings, _ = api_requests.get_user_instance_exports(
                master_url, user['email'], instance_id)

        results = []
        for tracking in trackings:
            history_id = utils.decrypt_value(tracking['history_id'])
            history = db.get_history(history_id)[0]

            results.append({
                'name': history['name'],
                'id': tracking['id'],
                'state': tracking['state'],
                'create_time': tracking['create_time'],
                'destination': tracking['destination'],
                'update_time': tracking['update_time'],
                'show': tracking['show'],
            })

        results = utils.list_encrypt_ids(results)
        return self.send_response(data=results)
Esempio n. 11
0
    def get(self, user_id):
        logger.debug("get user")
        self.check_token()
        user_id = utils.decrypt_value(user_id)

        user = db.get_user(id=user_id)
        if user is None or user == []:
            return self.send_response_404()

        user = user[0]

        api_key = db.get_api_key(user['id'])

        if api_key is None or api_key == []:
            new_key = utils.create_uuid(32)
            db.add_api_key(user['id'], new_key)
            user['api_key'] = new_key
        else:
            user['api_key'] = api_key['key']

        print(user)

        user = utils.encrypt_ids(user)
        return self.send_response(data=user)
Esempio n. 12
0
 def get(self, value):
     logger.debug("decrypt value")
     self.check_token()
     return self.send_response(data={'value': utils.decrypt_value(value)})
Esempio n. 13
0
def test_decrypt_str():
    utils.init('Secret_key')
    d = utils.decrypt_value('bc729496af0697be')
    assert d == '42'