def post(self, *args, **kwargs): checkpoint_obj = self.get_json_body() try: if not self.storage_client: self.storage_client = create_storage_client() if checkpoint_obj['action'] == 'createCheckpoint': checkpoint = create_checkpoint(checkpoint_obj['localPath'], self.storage_client) self.finish(checkpoint) if checkpoint_obj['action'] == 'listCheckpoints': checkpoints = list_checkpoints(checkpoint_obj['localPath'], self.storage_client) self.finish(checkpoints) if checkpoint_obj['action'] == 'restoreCheckpoint': checkpoint = restore_checkpoint(checkpoint_obj['localPath'], checkpoint_obj['checkpointID'], self.storage_client) self.finish(checkpoint) if checkpoint_obj['action'] == 'deleteCheckpoint': checkpoint = delete_checkpoint(checkpoint_obj['localPath'], checkpoint_obj['checkpointID'], self.storage_client) self.finish({}) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
def get(self): try: self.finish({'project': AuthProvider.get().project}) except GoogleAuthError: msg = 'Unable to determine Google Cloud Project' app_log.exception(msg) self.set_status(403, msg)
async def get(self): try: metadata = await get_metadata() instance = metadata.get('instance', {}) instance_custom_metadata = instance.get('attributes', {}) response = { 'project': metadata.get('project', {}).get('projectId'), 'numericProjectId': metadata.get('project', {}).get('numericProjectId'), 'framework': instance_custom_metadata.get('framework'), 'id': instance.get('id'), 'name': instance.get('name'), 'frameworkTitle': instance_custom_metadata.get('title'), 'dlvmImageVersion': instance_custom_metadata.get('version'), 'machineType': instance.get('machineType'), 'zone': instance.get('zone'), } self.finish(response) except: msg = 'Unexpected error obtaining instance metadata' app_log.exception(msg) self.set_status(500, msg)
def get(self, *args, **kwargs): try: self.finish(json.dumps(load_data())) except Exception as e: # pylint: disable=broad-except app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
def post(self, path=''): move_obj = self.get_json_body() try: if not self.storage_client: self.storage_client = create_storage_client() blob = move(move_obj['oldLocalPath'], move_obj['newLocalPath'], self.storage_client) file_bytes = BytesIO() blob.download_to_file(file_bytes) self.finish({ 'type': 'file', 'content': { 'path': ('%s/%s' % (blob.bucket.name, blob.name)), 'name': blob.name, 'mimetype': blob.content_type, 'content': base64.encodebytes(file_bytes.getvalue()).decode('ascii'), 'last_modified': blob_last_modified(blob), }, }) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
def get(self, *args, **kwargs): try: if not self.storage_client: self.storage_client = create_storage_client() nb = getPathContents(args[1], self.storage_client) gcs_notebook = nbformat.reads(base64.b64decode( nb['content']['content']).decode('utf-8'), as_version=4) exporter = notebook.nbconvert.handlers.get_exporter(args[0]) (output, resources) = exporter.from_notebook_node(gcs_notebook) # Force download if requested if self.get_argument('download', 'false').lower() == 'true': filename = os.path.splitext( args[1])[0] + resources['output_extension'] self.set_header('Content-Disposition', 'attachment; filename="%s"' % filename) if exporter.output_mimetype: self.set_header('Content-Type', '%s; charset=utf-8' % exporter.output_mimetype) self.finish(output) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
async def get(self): try: pricelist = await get_pricelist() self.finish(pricelist) except: msg = 'Unexpected error obtaining pricelist' app_log.exception(msg) self.set_status(500, msg)
def refresh(self): if not self._auth.valid: app_log.info('Refreshing Google Cloud Credential') try: self._auth.refresh(Request()) except GoogleAuthError: msg = 'Unable to refresh Google Cloud Credential' app_log.exception(msg) raise
def post(self, *args, **kwargs): try: self.bigquery_client = create_bigquery_client() self.finish(list_projects(self.bigquery_client)) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
def post(self, *args, **kwargs): try: post_body = self.get_json_body() self.finish(make_query(post_body)) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
def post(self, *args, **kwargs): try: post_body = self.get_json_body() self.finish(generate_data(post_body['num_items'])) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
def delete(self, path=''): try: if not self.storage_client: self.storage_client = storage.Client() self.finish(json.dumps(delete(path, self.storage_client))) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e))
def post(self, *args, **kwargs): try: self.bigquery_client = create_bigquery_client() post_body = self.get_json_body() self.finish(list_jobs(self.bigquery_client, post_body['projectId'])) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
def post(self, input=""): modelId = self.get_json_body()["modelId"] try: if not self.automl_client: self.automl_client = create_automl_client() self.automl_client.delete_model(modelId) self.finish({"success": {"message": "model deleted"}}) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({"error": {"message": str(e)}})
def post(self, *args, **kwargs): try: self.finish(list_projects()) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({ 'error': { 'message': str(e) } })
def post(self, *args, **kwargs): try: post_body = self.get_json_body() self.finish( get_job_details(GetQueryDetailsHandler.bigquery_client, post_body['jobId'])) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
def delete(self, path=''): try: if not self.storage_client: self.storage_client = create_storage_client() self.finish(json.dumps(delete(path, self.storage_client))) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
def get(self, input=""): datasetId = self.get_argument("datasetId") try: if not self.automl_client: self.automl_client = create_automl_client() self.finish( json.dumps(get_table_specs(self.automl_client, datasetId))) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({"error": {"message": str(e)}})
def get(self, input=""): try: if not self.automl_client: self.automl_client = create_automl_client() if not self.parent: self.parent = create_automl_parent(self.automl_client) self.finish(json.dumps(get_models(self.automl_client, self.parent))) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({"error": {"message": str(e)}})
def post(self, *args, **kwargs): try: if not self.storage_client: self.storage_client = create_storage_client() model = self.get_json_body() upload(model, self.storage_client) self.finish({}) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
def post(self, *args, **kwargs): try: post_body = self.get_json_body() self.finish(get_table_details(post_body['table_id'])) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({ 'error': { 'message': str(e) } })
def post(self, path=''): new_obj = self.get_json_body() try: if not self.storage_client: self.storage_client = create_storage_client() self.finish( new_file(new_obj['type'], new_obj.get('ext', None), new_obj['path'], self.storage_client)) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
async def _make_request(self, base64_url, method='GET', body=None): try: url = b64decode(base64_url).decode() if not (url.startswith('https://') and 'googleapis.com' in url): raise ValueError('URL is not a valid Google API service') except ValueError as e: app_log.exception(e) self.set_status(400) self.finish({ 'error': { 'code': 400, 'status': 'BAD_REQUEST', 'message': str(e) } }) return try: headers = AuthProvider.get().get_header() except: self.set_status(403) self.finish({ 'error': { 'code': 403, 'status': 'UNAUTHORIZED', 'message': 'Unable to obtain authentication token' } }) return headers['Content-Type'] = 'application/json' user_agent = 'jupyterlab_gcpextension/{}'.format(VERSION) request = HTTPRequest(url, method, headers, body, user_agent=user_agent) client = AsyncHTTPClient() try: app_log.info('Proxying GCP %s request to %s', method, url) response = await client.fetch(request) self.finish(response.body) except HTTPClientError as e: app_log.error('GCP %s request to %s returned %s: %s', method, url, e.code, e.message) self.set_status(e.code) self.finish(e.response.body)
def post(self, *args, **kwargs): try: post_body = self.get_json_body() if 'lastFetchTime' in post_body: self.finish( list_jobs(QueryHistoryHandler.bigquery_client, post_body['projectId'], post_body['lastFetchTime'])) else: self.finish( list_jobs(QueryHistoryHandler.bigquery_client, post_body['projectId'])) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
def post(self, path=''): copy_obj = self.get_json_body() try: if not self.storage_client: self.storage_client = create_storage_client() blob = copy(copy_obj['localPath'], copy_obj['toLocalDir'], self.storage_client) self.finish({ 'type': 'file', 'path': ('%s/%s' % (blob.bucket.name, blob.name)), 'name': blob.name }) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
def get(self, path=''): try: if not self.storage_client: self.storage_client = create_storage_client() self.finish(json.dumps(getPathContents(path, self.storage_client))) except FileNotFound as e: app_log.exception(str(e)) self.set_status(404, str(e)) self.finish({ 'error': { 'message': str(e), 'response': { 'status': 404, }, } }) except Exception as e: app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({'error': {'message': str(e)}})
def _handle_exception(self, e): app_log.exception(str(e)) self.set_status(500, str(e)) self.finish({"error": {"message": str(e)}})