def create_doc_client(access_token): services = bsc.get_services() # get clients from bbp python packages oidc_client = BBPOIDCClient.bearer_auth( services['oidc_service']['prod']['url'], access_token) bearer_client = BBPOIDCClient.bearer_auth('prod', access_token) doc_client = DocClient(services['document_service']['prod']['url'], oidc_client) return doc_client
def copy_datafiles_to_collab_storage(request, job, local_dir, relative_paths): # upload local files to collab storage from bbp_client.oidc.client import BBPOIDCClient from bbp_client.document_service.client import Client as DocClient import bbp_services.client as bsc services = bsc.get_services() access_token = get_access_token(request.user.social_auth.get()) oidc_client = BBPOIDCClient.bearer_auth( services['oidc_service']['prod']['url'], access_token) doc_client = DocClient(services['document_service']['prod']['url'], oidc_client) project = doc_client.get_project_by_collab_id(job.collab_id) root = doc_client.get_path_by_id(project["_uuid"]) collab_folder = root + "/job_{}".format(job.pk) folder_id = doc_client.mkdir(collab_folder) collab_paths = [] for relative_path in relative_paths: collab_path = os.path.join(collab_folder, relative_path) if os.path.dirname(relative_path): # if there are subdirectories... doc_client.makedirs(os.path.dirname(collab_path)) local_path = os.path.join(local_dir, relative_path) id = doc_client.upload_file(local_path, collab_path) collab_paths.append(collab_path) content_type = mimetypes.guess_type(local_path)[0] if content_type: doc_client.set_standard_attr(collab_path, {'_contentType': content_type}) return collab_paths
def get_related_data(self, user): # assume for now that data is in collab from bbp_client.oidc.client import BBPOIDCClient from bbp_client.document_service.client import Client as DocClient import bbp_services.client as bsc services = bsc.get_services() access_token = get_access_token(user.social_auth.get()) oidc_client = BBPOIDCClient.bearer_auth( services['oidc_service']['prod']['url'], access_token) doc_client = DocClient(services['document_service']['prod']['url'], oidc_client) parse_result = urlparse(self.object.results_storage) if parse_result.scheme == "collab": collab_folder = parse_result.path #return doc_client.listdir(collab_folder) folder_uuid = doc_client.get_standard_attr(collab_folder)['_uuid'] data = { "folder": { "path": collab_folder, } } if self.object.project: data["folder"]["url"] = self.get_collab_storage_url( ) + "?state=uuid={}".format(folder_uuid) return data else: print("Storage not yet supported") return {}
def upload_zip_file_to_storage(request): access_token = get_access_token(request.user.social_auth.get()) # retrieve data from request.session headers = request.session['headers'] collab_id = request.session['collab_id'] st_rel_user_results_folder = request.session['st_rel_user_results_folder'] st_rel_user_uploaded_folder = request.session[ 'st_rel_user_uploaded_folder'] crr_user_folder = request.session['time_info'] output_path = request.session['result_file_zip'] context = request.session['context'] services = bsc.get_services() # get clients from bbp python packages oidc_client = BBPOIDCClient.bearer_auth(\ services['oidc_service']['prod']['url'], access_token) bearer_client = BBPOIDCClient.bearer_auth('prod', access_token) doc_client = DocClient(\ services['document_service']['prod']['url'], oidc_client) context = request.session['context'] #logout(request) nextUrl = urllib.quote('%s?ctx=%s' % (request.path, context)) # extract project from collab_id project = doc_client.get_project_by_collab_id(collab_id) # extract collab storage root path storage_root = doc_client.get_path_by_id(project["_uuid"]) crr_collab_storage_folder = os.path.join(storage_root, \ st_rel_user_results_folder) if not doc_client.exists(crr_collab_storage_folder): doc_client.makedirs(crr_collab_storage_folder) # final zip collab storage path zip_collab_storage_path = os.path.join(crr_collab_storage_folder, \ crr_user_folder + '_results.zip') # bypassing uploading data to collab storage if not doc_client.exists(zip_collab_storage_path): doc_client.upload_file(output_path, zip_collab_storage_path) # render to html page return HttpResponse("")
def new(cls, environment='prod', user=None, password=None, token=None): '''create new documentservice client''' services = get_services() oauth_url = services['oidc_service'][environment]['url'] ds_url = services['document_service'][environment]['url'] if token: oauth_client = BBPOIDCClient.bearer_auth(oauth_url, token) else: oauth_client = BBPOIDCClient.implicit_auth(user, password, oauth_url) return cls(ds_url, oauth_client)
def new(cls, environment='prod', user=None, password=None, token=None): '''create new collab service client''' services = get_services() oauth_url = services['oidc_service'][environment]['url'] service_url = services['stream_service'][environment]['url'] if token: oauth_client = BBPOIDCClient.bearer_auth(oauth_url, token) else: oauth_client = BBPOIDCClient.implicit_auth(user, password, oauth_url) return cls(service_url, oauth_client, environment)