Skip to content

Commit

Permalink
Merge branch 'folder-endpoint-access' into cluster-folder-methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jlewitt1 committed Aug 12, 2024
2 parents 667f5a5 + fbe82a6 commit 95046a0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
3 changes: 3 additions & 0 deletions runhouse/resources/hardware/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1840,3 +1840,6 @@ def _folder_mv(
return self.client.folder_mv(
path=path, dest_path=dest_path, overwrite=overwrite
)

def _folder_exists(self, path: Union[str, Path]):
return self.client.folder_exists(path=path)
6 changes: 6 additions & 0 deletions runhouse/servers/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ def folder_rm(self, path: Union[str, Path], contents: List, recursive: bool):
"/folder/method/rm", req_type="post", json_dict=folder_params
)

def folder_exists(self, path: str):
folder_params = FolderParams(path=path).dict()
return self.request_json(
"/folder/method/exists", req_type="post", json_dict=folder_params
)

def get_certificate(self):
cert: bytes = self.request(
"cert",
Expand Down
14 changes: 2 additions & 12 deletions runhouse/servers/http/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,9 @@ async def wrapper(*args, **kwargs):

func_call: bool = func.__name__ in ["post_call", "get_call"]

# restrict access for folder APIs
# restrict access for folder specific APIs
access_level_required = (
ResourceAccess.WRITE
if func.__name__
in [
"folder_ls_cmd",
"folder_mkdir_cmd",
"folder_get_cmd",
"folder_put_cmd",
"folder_rm_cmd",
"folder_mv_cmd",
]
else None
ResourceAccess.WRITE if func.__name__.startswith("folder") else None
)
token = get_token_from_request(request)

Expand Down
15 changes: 8 additions & 7 deletions tests/test_resources/test_clusters/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,13 +938,14 @@ def test_cluster_mkdir_mv_and_rm(self, cluster):

assert "new-folder" in [os.path.basename(f) for f in file_contents]

# Should not be able to mv to an existing directory unless `overwrite=True`
with pytest.raises(FileExistsError):
cluster._folder_mv(path="~/.rh/new-folder", dest_path="~/new-folder")

cluster._folder_mv(
path="~/.rh/new-folder", dest_path="~/new-folder", overwrite=True
)
# Should not be able to mv to an existing directory if `overwrite=False`
cluster._folder_mkdir(path="~/.rh/another-new-folder")
with pytest.raises(Exception):
cluster._folder_mv(
path="~/.rh/another-new-folder",
dest_path="~/new-folder",
overwrite=False,
)

# Delete folder contents and directory itself
cluster._folder_rm(path="~/new-folder", recursive=True)
Expand Down

0 comments on commit 95046a0

Please sign in to comment.