-
Notifications
You must be signed in to change notification settings - Fork 7
Export works with all target scopes #733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9860931
98cc196
86e63e5
ac007bc
01dc3cd
09c8fda
ff0c500
328b669
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -199,9 +199,11 @@ def build_path(self, path, tenant_specific=False, tenant=None): | |||||
| node_path = self.BasePath + path if path != '/' else self.BasePath | ||||||
|
|
||||||
| node_path = node_path.rstrip("/") | ||||||
| if node_path == "": | ||||||
| node_path = "/" | ||||||
|
|
||||||
| assert '//' not in node_path, "Directory path cannot contain double slashes (//). Example format: /library/Templates/" | ||||||
| assert node_path[0] == '/', "Directory path must start with '/'" | ||||||
| assert node_path.startswith('/'), "Directory path must start with '/'" | ||||||
|
|
||||||
| return node_path | ||||||
|
|
||||||
|
|
@@ -241,6 +243,73 @@ async def read(self, path: str) -> typing.Optional[typing.IO]: | |||||
| except (FileNotFoundError, IsADirectoryError): | ||||||
| return None | ||||||
|
|
||||||
| async def read_scoped(self, path: str, scope: str) -> typing.Optional[typing.IO]: | ||||||
| """ | ||||||
| Read from a single scope only. | ||||||
|
|
||||||
| Args: | ||||||
| path: Library file path (absolute, with extension). | ||||||
| scope: One of "global", "tenant", "personal". | ||||||
| """ | ||||||
| self._validate_read_path(path) | ||||||
|
|
||||||
| if scope == "global": | ||||||
| try: | ||||||
| global_path = self.build_path(path, tenant_specific=False) | ||||||
| return io.FileIO(global_path, "rb") | ||||||
| except (FileNotFoundError, IsADirectoryError): | ||||||
| return None | ||||||
|
|
||||||
| if scope == "tenant": | ||||||
| tenant_id = self._current_tenant_id() | ||||||
| if not tenant_id: | ||||||
| return None | ||||||
| try: | ||||||
| tenant_path = self.build_path(path, tenant_specific=True, tenant=tenant_id) | ||||||
| if os.path.isfile(tenant_path): | ||||||
| return io.FileIO(tenant_path, "rb") | ||||||
| return None | ||||||
| except Exception: | ||||||
| return None | ||||||
|
|
||||||
| if scope == "personal": | ||||||
| tenant_id = self._current_tenant_id() | ||||||
| cred_id = self._current_credentials_id() | ||||||
| personal_path = self._personal_path(path, tenant_id, cred_id) | ||||||
| if personal_path and os.path.isfile(personal_path): | ||||||
| return io.FileIO(personal_path, "rb") | ||||||
| return None | ||||||
|
|
||||||
| return None | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Unknown scope silently returns If an invalid Suggested change- return None
+ raise ValueError("Unknown scope: {!r}".format(scope))📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| async def read_personal_scopes( | ||||||
| self, | ||||||
| path: str, | ||||||
| tenant_id: typing.Optional[str] = None, | ||||||
| ) -> typing.List[typing.Tuple[str, str, typing.IO]]: | ||||||
| """ | ||||||
| Read personal variants for all credential scopes in a tenant. | ||||||
| """ | ||||||
| self._validate_read_path(path) | ||||||
|
|
||||||
| scopes = await self._get_personal_scopes() | ||||||
| results: typing.List[typing.Tuple[str, str, typing.IO]] = [] | ||||||
| try: | ||||||
| for scope_tenant, scope_cred in scopes: | ||||||
| if tenant_id is not None and scope_tenant != tenant_id: | ||||||
| continue | ||||||
| personal_path = self._personal_path(path, scope_tenant, scope_cred) | ||||||
| if personal_path and os.path.isfile(personal_path): | ||||||
| results.append((scope_tenant, scope_cred, io.FileIO(personal_path, "rb"))) | ||||||
| except Exception: | ||||||
| for _, _, file_handle in results: | ||||||
| try: | ||||||
| file_handle.close() | ||||||
| except Exception: | ||||||
| pass | ||||||
| raise | ||||||
| return results | ||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||
|
|
||||||
| async def list(self, path: str) -> list: | ||||||
| """ | ||||||
| List directory items from overlays and concatenate in precedence order: | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.