def create_auth_token(): # get server token from header (convert to str to fix weird encoding issue on production) server_token = request.headers.get('X-Server-Token', type=str) json_data = request.get_json() try: user = str(json_data.get('user')) except AttributeError: return return_message('Error: missing user', 400) name = str(json_data.get('name', '')) email = str(json_data.get('email', '')) duration = int(json_data.get('duration', 1)) if not all([server_token, user]): return return_message('Error: missing parameter', 400) if user.find('/') != -1: return return_message('Error: invalid username, must not contain "/"', 400) try: auth_token, expiry_date = generate_auth_token(server_token, user, name, email, duration) return return_data({'user': user, 'transferCode': auth_token, 'expiresAt': expiry_date.strftime("%Y-%m-%dT%H:%M:%SZ")}) except InvalidServerToken: return return_message('Error: Unauthorized', 401)
def get_db_files(): # get server token from header (convert to str to fix weird encoding issue on production) server_token = request.headers.get('X-Server-Token', type=str) json_data = request.get_json() try: if json_data: data = get_files(server_token, json_data) else: data = get_files(server_token) return return_data(data) except InvalidServerToken: return return_message('Error: Unauthorized', 401) except InvalidColumnName: return return_message('Error: Column name does not exist', 400)
def get_samples(auth_token): auth_token = str(auth_token) # The status argument can be used to retrieve files that are complete, corrupt, or ongoing status = request.args.get('status', type=str) user_id = get_user_by_auth_token(auth_token) return return_data(get_user_files(user_id, status))