From a6266aa0a581e4d4fc15cc41c46fbc724df23581 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 24 Mar 2023 13:40:38 +1100 Subject: [PATCH 1/3] Expose public_url via geturl --- fs_gcsfs/_gcsfs.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs_gcsfs/_gcsfs.py b/fs_gcsfs/_gcsfs.py index 6c869bf..26a50f0 100644 --- a/fs_gcsfs/_gcsfs.py +++ b/fs_gcsfs/_gcsfs.py @@ -127,6 +127,10 @@ def _get_blob(self, key: str) -> Optional[Blob]: """Returns blob if exists or None otherwise""" return self.bucket.get_blob(key) + def _get_blob_from_path(self, path: str) -> Optional[Blob]: + """Returns blob if exists or None otherwise""" + return self._get_blob(self._path_to_key(path)) + def getinfo(self, path: str, namespaces: Optional[List[str]] = None, check_parent_dir: bool = True) -> Info: if check_parent_dir: self.check() @@ -143,10 +147,9 @@ def getinfo(self, path: str, namespaces: Optional[List[str]] = None, check_paren if _path == "/": return self._dir_info("") - key = self._path_to_key(_path) dir_key = self._path_to_dir_key(_path) - blob = self._get_blob(key) + self._get_blob_from_path(_path) if blob: # Check if there exists a blob at the provided path, return the corresponding object Info return self._info_from_blob(blob, namespaces) @@ -442,11 +445,14 @@ def exists(self, path: str) -> bool: return self.isdir(path) def geturl(self, path: str, purpose: str = "download"): - # TODO This does currently not have the same functionality as S3FS.geturl() (returning a public URL) which may be confusing to users _path = self.validatepath(path) _key = self._path_to_key(_path) if purpose == "download": - return "gs://" + self.DELIMITER.join([self._bucket_name, _key]) + blob = self._get_blob_from_path(_path) + if blob.public_url: + return blob.public_url + # TODO This does currently not have the ability to return a signed URL. + return None else: raise errors.NoURL(path, purpose) From 1b37ff3d42cb2dbf9eb050977cefff1163d48988 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 24 Mar 2023 13:40:50 +1100 Subject: [PATCH 2/3] Expose public_url in getinfo --- fs_gcsfs/_gcsfs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs_gcsfs/_gcsfs.py b/fs_gcsfs/_gcsfs.py index 26a50f0..3c818a1 100644 --- a/fs_gcsfs/_gcsfs.py +++ b/fs_gcsfs/_gcsfs.py @@ -179,7 +179,10 @@ def _info_from_blob(blob: Blob, namespaces: Optional[List[str]] = None) -> Info: "type": int(ResourceType.file) } # TODO more namespaces: basic, urls, gcs, ... - + if "urls" in namespaces: + info["urls"] = { + "http": blob.public_url + } return Info(info) def _dir_info(self, name: str) -> Info: From d7551eb2944443a61f476be5975622d6b1275a78 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 24 Mar 2023 14:04:06 +1100 Subject: [PATCH 3/3] Need to set local var --- fs_gcsfs/_gcsfs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs_gcsfs/_gcsfs.py b/fs_gcsfs/_gcsfs.py index 3c818a1..065392f 100644 --- a/fs_gcsfs/_gcsfs.py +++ b/fs_gcsfs/_gcsfs.py @@ -149,7 +149,7 @@ def getinfo(self, path: str, namespaces: Optional[List[str]] = None, check_paren dir_key = self._path_to_dir_key(_path) - self._get_blob_from_path(_path) + blob = self._get_blob_from_path(_path) if blob: # Check if there exists a blob at the provided path, return the corresponding object Info return self._info_from_blob(blob, namespaces)