Skip to content

Commit a7081d3

Browse files
committed
file-based: allow connector to provide permissions and identities schemas
1 parent a6d1b62 commit a7081d3

File tree

4 files changed

+8
-32
lines changed

4 files changed

+8
-32
lines changed

airbyte_cdk/sources/file_based/file_based_stream_reader.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use_file_transfer,
2020
)
2121
from airbyte_cdk.sources.file_based.remote_file import RemoteFile
22+
from airbyte_cdk.sources.file_based.schema_helpers import schemaless_schema
2223

2324

2425
class FileReadMode(Enum):
@@ -28,6 +29,8 @@ class FileReadMode(Enum):
2829

2930
class AbstractFileBasedStreamReader(ABC):
3031
DATE_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
32+
REMOTE_FILE_PERMISSIONS_SCHEMA = schemaless_schema
33+
REMOTE_FILE_IDENTITY_SCHEMA = schemaless_schema
3134

3235
def __init__(self) -> None:
3336
self._config = None
@@ -192,7 +195,7 @@ def get_file_acl_permissions(self, file: RemoteFile, logger: logging.Logger) ->
192195
ACL Permissions from files.
193196
"""
194197
raise NotImplementedError(
195-
f"{self.__class__.__name__} required to support get_file_acl_permissions()"
198+
f"{self.__class__.__name__} required to support get_file_acl_permissions(), please update REMOTE_FILE_PERMISSIONS_SCHEMA accordingly"
196199
)
197200

198201
@abstractmethod
@@ -202,5 +205,5 @@ def load_identity_groups(self, logger: logging.Logger) -> Iterable[Dict[str, Any
202205
identities.
203206
"""
204207
raise NotImplementedError(
205-
f"{self.__class__.__name__} required to support load_identity_groups()"
208+
f"{self.__class__.__name__} required to support load_identity_groups(), please update REMOTE_FILE_IDENTITY_SCHEMA accordingly"
206209
)

airbyte_cdk/sources/file_based/schema_helpers.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,6 @@
2323
"properties": {"data": {"type": "object"}, "file": {"type": "object"}},
2424
}
2525

26-
remote_file_permissions_schema = {
27-
"type": "object",
28-
"properties": {
29-
"id": {"type": "string"},
30-
"file_path": {"type": "string"},
31-
"allowed_identity_remote_ids": {"type": "array", "items": {"type": "string"}},
32-
"publicly_accessible": {"type": "boolean"},
33-
},
34-
}
35-
36-
remote_file_identity_schema = {
37-
"type": "object",
38-
"properties": {
39-
"id": {"type": "string"},
40-
"remote_id": {"type": "string"},
41-
"parent_id": {"type": ["null", "string"]},
42-
"name": {"type": ["null", "string"]},
43-
"description": {"type": ["null", "string"]},
44-
"email_address": {"type": ["null", "string"]},
45-
"member_email_addresses": {"type": ["null", "array"]},
46-
"type": {"type": "string"},
47-
"modified_at": {"type": "string"},
48-
},
49-
}
50-
5126

5227
@total_ordering
5328
class ComparableType(Enum):

airbyte_cdk/sources/file_based/stream/default_file_based_stream.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
SchemaType,
3030
file_transfer_schema,
3131
merge_schemas,
32-
remote_file_permissions_schema,
3332
schemaless_schema,
3433
)
3534
from airbyte_cdk.sources.file_based.stream import AbstractFileBasedStream
@@ -111,7 +110,7 @@ def _filter_schema_invalid_properties(
111110
},
112111
}
113112
elif self.use_permissions_transfer:
114-
return remote_file_permissions_schema
113+
return self.stream_reader.REMOTE_FILE_PERMISSIONS_SCHEMA
115114
else:
116115
return super()._filter_schema_invalid_properties(configured_catalog_json_schema)
117116

@@ -315,7 +314,7 @@ def _get_raw_json_schema(self) -> JsonSchema:
315314
if self.use_file_transfer:
316315
return file_transfer_schema
317316
elif self.use_permissions_transfer:
318-
return remote_file_permissions_schema
317+
return self.stream_reader.REMOTE_FILE_PERMISSIONS_SCHEMA
319318
elif self.config.input_schema:
320319
return self.config.get_input_schema() # type: ignore
321320
elif self.config.schemaless:

airbyte_cdk/sources/file_based/stream/identities_stream.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from airbyte_cdk.sources.file_based.discovery_policy import AbstractDiscoveryPolicy
1515
from airbyte_cdk.sources.file_based.exceptions import FileBasedErrorsCollector, FileBasedSourceError
1616
from airbyte_cdk.sources.file_based.file_based_stream_reader import AbstractFileBasedStreamReader
17-
from airbyte_cdk.sources.file_based.schema_helpers import remote_file_identity_schema
1817
from airbyte_cdk.sources.file_based.types import StreamSlice
1918
from airbyte_cdk.sources.streams import Stream
2019
from airbyte_cdk.sources.streams.checkpoint import Cursor
@@ -89,7 +88,7 @@ def load_identity_groups(self) -> Iterable[Dict[str, Any]]:
8988

9089
@cache
9190
def get_json_schema(self) -> JsonSchema:
92-
return remote_file_identity_schema
91+
return self.stream_reader.REMOTE_FILE_IDENTITY_SCHEMA
9392

9493
@property
9594
def name(self) -> str:

0 commit comments

Comments
 (0)