Skip to content

Commit ad1a843

Browse files
committed
WIP: Document current approach to permissions
1 parent 7f4a681 commit ad1a843

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Permissions in Zarr Python
2+
3+
Write/delete permissions in Zarr Python are confusing. This document aims to describe how they currently work.
4+
5+
# Data models
6+
7+
Zarr Python has two data models (`Array` and `Group`) and one storage model (`Store`). Only the store has a concept of write/delete permissions. Both `write` and `delete` permissions on `Store` instances are controlled by the `read_only` immutable property. Permissions on Store `classes` (implementation) are also influenced by the `supports_writes` and `supports_deletes` property, which should be the same for all instances of a class.
8+
9+
`Array` and `Group` do not have any permissions, instead they store a reference to a store that has permissions.
10+
11+
## Store properties related to permissions
12+
13+
### `supports_writes`
14+
15+
This is a property of the *class* that should indicate whether the store implements the following methods:
16+
17+
- `async def set(self, key: str, value: Buffer) -> None:`
18+
- `async def set_if_not_exists(self, key: str, value: Buffer) -> None:`
19+
20+
`supports_writes` is primarily used by tests to determine the expected result of write operations. It is not used by the library to enforce permissions.
21+
22+
### `supports_deletes`
23+
24+
This is a property of the *class* that should indicate whether the store implements the following methods:
25+
26+
- `async def delete(self, key: str) -> None:`
27+
28+
The `supports_deletes` property is used by the `Store` abstract base class to determine whether it should delete all keys under a given prefix using `store.delete_dir(prefix)`.
29+
30+
The `supports_deletes` property is used by the `Array` and `Group` classes before calling `store.delete_dir(prefix)` to determine whether the store supports deleting keys when those data classes are opened with `overwrite=True`. If a store does not support deletes, the `Array` and `Group` classes check if an array or group is identified in that location via a `.zarray`, `.zgroup`, or `zarr.json` key. If such a key exists, the `Array` or `Group` will raise an error without trying to delete it. If a store does support deletes, the `Array` and `Group` classes will attempt to recursively delete the keys in the store using `store.delete_dir(prefix)`.
31+
32+
The `supports_deletes` property is also used by the testing framework to determine the expected result of delete operations.
33+
34+
!!! note
35+
Store implementations are agnostic to the Zarr data model. They will delete everything under the given prefix, regardless of whether it is an array, group, or unrelated to the Zarr store.
36+
37+
### `supports_listing`
38+
39+
This is a property of the *class* that should indicate whether the store implements the following method:
40+
41+
- `async def list(self, prefix: str = '', delimiter: str = '') -> List[str]:`

0 commit comments

Comments
 (0)