-
Notifications
You must be signed in to change notification settings - Fork 30
feat(file-based): new AbstractFileBasedStreamPermissionsReader #402
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
Merged
aldogonzalez8
merged 6 commits into
main
from
aldogonzalez8/file-based/decouple-permissions-with-new-class
Mar 12, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4bf8d8e
file-based: new Permissions Reader Class to handle specific tasks of …
aldogonzalez8 03dc23e
file-based: fix lint comments
aldogonzalez8 0a2b4d6
file-based: ensure reader is available
aldogonzalez8 8b6212a
file-based: add config attribute for stream permissions reader
aldogonzalez8 87e407e
file-based: fix wrong typos
aldogonzalez8 c084c2c
file-based: remove unnecesary raise for non-impemented execption for …
aldogonzalez8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
airbyte_cdk/sources/file_based/file_based_stream_permissions_reader.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # | ||
| # Copyright (c) 2025 Airbyte, Inc., all rights reserved. | ||
| # | ||
|
|
||
| import logging | ||
| from abc import ABC, abstractmethod | ||
| from typing import Any, Dict, Iterable, Optional | ||
|
|
||
| from airbyte_cdk.sources.file_based import AbstractFileBasedSpec | ||
| from airbyte_cdk.sources.file_based.remote_file import RemoteFile | ||
|
|
||
|
|
||
| class AbstractFileBasedStreamPermissionsReader(ABC): | ||
| """ | ||
| This class is responsible for reading file permissions and Identities from a source. | ||
| """ | ||
|
|
||
| def __init__(self) -> None: | ||
| self._config = None | ||
|
|
||
| @property | ||
| def config(self) -> Optional[AbstractFileBasedSpec]: | ||
| return self._config | ||
|
|
||
| @config.setter | ||
| @abstractmethod | ||
| def config(self, value: AbstractFileBasedSpec) -> None: | ||
| """ | ||
| FileBasedSource reads the config from disk and parses it, and once parsed, the source sets the config on its StreamReader. | ||
|
|
||
| Note: FileBasedSource only requires the keys defined in the abstract config, whereas concrete implementations of StreamReader | ||
| will require keys that (for example) allow it to authenticate with the 3rd party. | ||
|
|
||
| Therefore, concrete implementations of AbstractFileBasedStreamPermissionsReader's's config setter should assert that `value` is of the correct | ||
| config type for that type of StreamReader. | ||
| """ | ||
| ... | ||
|
|
||
| @abstractmethod | ||
| def get_file_acl_permissions(self, file: RemoteFile, logger: logging.Logger) -> Dict[str, Any]: | ||
| """ | ||
| This function should return the allow list for a given file, i.e. the list of all identities and their permission levels associated with it | ||
|
|
||
| e.g. | ||
| def get_file_acl_permissions(self, file: RemoteFile, logger: logging.Logger): | ||
| api_conn = some_api.conn(credentials=SOME_CREDENTIALS) | ||
| result = api_conn.get_file_permissions_info(file.id) | ||
| return MyPermissionsModel( | ||
| id=result["id"], | ||
| access_control_list = result["access_control_list"], | ||
| is_public = result["is_public"], | ||
| ).dict() | ||
| """ | ||
| ... | ||
|
|
||
| @abstractmethod | ||
| def load_identity_groups(self, logger: logging.Logger) -> Iterable[Dict[str, Any]]: | ||
| """ | ||
| This function should return the Identities in a determined "space" or "domain" where the file metadata (ACLs) are fetched and ACLs items (Identities) exists. | ||
|
|
||
| e.g. | ||
| def load_identity_groups(self, logger: logging.Logger) -> Iterable[Dict[str, Any]]: | ||
| api_conn = some_api.conn(credentials=SOME_CREDENTIALS) | ||
| users_api = api_conn.users() | ||
| groups_api = api_conn.groups() | ||
| members_api = self.google_directory_service.members() | ||
| for user in users_api.list(): | ||
| yield my_identity_model(id=user.id, name=user.name, email_address=user.email, type="user").dict() | ||
| for group in groups_api.list(): | ||
| group_obj = my_identity_model(id=group.id, name=groups.name, email_address=user.email, type="group").dict() | ||
| for member in members_api.list(group=group): | ||
| group_obj.member_email_addresses = group_obj.member_email_addresses or [] | ||
| group_obj.member_email_addresses.append(member.email) | ||
| yield group_obj.dict() | ||
| """ | ||
| ... | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def file_permissions_schema(self) -> Dict[str, Any]: | ||
| """ | ||
| This function should return the permissions schema for file permissions stream. | ||
|
|
||
| e.g. | ||
| def file_permissions_schema(self) -> Dict[str, Any]: | ||
| # you can also follow the pattern we have for python connectors and have a json file and read from there e.g. schemas/identities.json | ||
| return { | ||
| "type": "object", | ||
| "properties": { | ||
| "id": { "type": "string" }, | ||
| "file_path": { "type": "string" }, | ||
| "access_control_list": { | ||
| "type": "array", | ||
| "items": { "type": "string" } | ||
| }, | ||
| "publicly_accessible": { "type": "boolean" } | ||
| } | ||
| } | ||
| """ | ||
| ... | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def identities_schema(self) -> Dict[str, Any]: | ||
| """ | ||
| This function should return the identities schema for file identity stream. | ||
|
|
||
| e.g. | ||
| def identities_schema(self) -> Dict[str, Any]: | ||
| # you can also follow the pattern we have for python connectors and have a json file and read from there e.g. schemas/identities.json | ||
| return { | ||
| "type": "object", | ||
| "properties": { | ||
| "id": { "type": "string" }, | ||
| "remote_id": { "type": "string" }, | ||
| "name": { "type": ["null", "string"] }, | ||
| "email_address": { "type": ["null", "string"] }, | ||
| "member_email_addresses": { "type": ["null", "array"] }, | ||
| "type": { "type": "string" }, | ||
| } | ||
| } | ||
| """ | ||
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.