-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
file-based: move permissions transfer mode to general with abstract I…
…dentitie stream, so file based Identity stream becomes an implementation
- Loading branch information
1 parent
a7081d3
commit 7e4d73f
Showing
6 changed files
with
117 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from airbyte_cdk.sources.file_based.stream.abstract_file_based_stream import AbstractFileBasedStream | ||
from airbyte_cdk.sources.file_based.stream.default_file_based_stream import DefaultFileBasedStream | ||
from airbyte_cdk.sources.file_based.stream.identities_stream import IdentitiesStream | ||
from airbyte_cdk.sources.file_based.stream.identities_stream import FileIdentities | ||
|
||
__all__ = ["AbstractFileBasedStream", "DefaultFileBasedStream", "IdentitiesStream"] | ||
__all__ = ["AbstractFileBasedStream", "DefaultFileBasedStream", "FileIdentities"] |
This file contains 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 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,25 @@ | ||
# | ||
# Copyright (c) 2025 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from typing import Literal | ||
|
||
from pydantic.v1 import AnyUrl, BaseModel, Field | ||
from airbyte_cdk import OneOfOptionConfig | ||
|
||
|
||
class DeliverPermissions(BaseModel): | ||
class Config(OneOfOptionConfig): | ||
title = "Replicate Permissions ACL" | ||
description = "Sends one identity stream and one for more permissions (ACL) streams to the destination. This data can be used in downstream systems to recreate permission restrictions mirroring the original source." | ||
discriminator = "delivery_type" | ||
|
||
delivery_type: Literal["use_permissions_transfer"] = Field( | ||
"use_permissions_transfer", const=True | ||
) | ||
|
||
include_identities_stream: bool = Field( | ||
title="Include Identity Stream", | ||
description="This data can be used in downstream systems to recreate permission restrictions mirroring the original source", | ||
default=True, | ||
) |
This file contains 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,81 @@ | ||
# | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
import traceback | ||
from abc import ABC, abstractmethod | ||
from typing import Any, Dict, Iterable, List, Mapping, MutableMapping, Optional | ||
|
||
from airbyte_protocol_dataclasses.models import SyncMode | ||
|
||
from airbyte_cdk.models import AirbyteLogMessage, AirbyteMessage, Level | ||
from airbyte_cdk.models import Type as MessageType | ||
from airbyte_cdk.sources.streams import Stream | ||
from airbyte_cdk.sources.streams.checkpoint import Cursor | ||
from airbyte_cdk.sources.utils.record_helper import stream_data_to_airbyte_message | ||
from airbyte_cdk.utils.traced_exception import AirbyteTracedException | ||
|
||
DEFAULT_IDENTITIES_STREAM_NAME = "identities" | ||
|
||
|
||
class Identities(Stream, ABC): | ||
""" | ||
The identities stream. A full refresh stream to sync identities from a certain domain. | ||
The load_identity_groups method manage the logic to get such data. | ||
""" | ||
|
||
IDENTITIES_STREAM_NAME = DEFAULT_IDENTITIES_STREAM_NAME | ||
|
||
is_resumable = False | ||
|
||
def __init__( | ||
self, | ||
catalog_schema: Optional[Mapping[str, Any]], | ||
): | ||
super().__init__() | ||
self.catalog_schema = catalog_schema | ||
self._cursor: MutableMapping[str, Any] = {} | ||
|
||
@property | ||
def state(self) -> MutableMapping[str, Any]: | ||
return self._cursor | ||
|
||
@state.setter | ||
def state(self, value: MutableMapping[str, Any]) -> None: | ||
"""State setter, accept state serialized by state getter.""" | ||
self._cursor = value | ||
|
||
def read_records( | ||
self, | ||
sync_mode: SyncMode, | ||
cursor_field: Optional[List[str]] = None, | ||
stream_slice: Optional[Mapping[str, Any]] = None, | ||
stream_state: Optional[Mapping[str, Any]] = None, | ||
) -> Iterable[Mapping[str, Any] | AirbyteMessage]: | ||
try: | ||
identity_groups = self.load_identity_groups() | ||
for record in identity_groups: | ||
yield stream_data_to_airbyte_message(self.name, record) | ||
except AirbyteTracedException as exc: | ||
# Re-raise the exception to stop the whole sync immediately as this is a fatal error | ||
raise exc | ||
except Exception as e: | ||
yield AirbyteMessage( | ||
type=MessageType.LOG, | ||
log=AirbyteLogMessage( | ||
level=Level.ERROR, | ||
message=f"Error trying to read identities: {e} stream={self.name}", | ||
stack_trace=traceback.format_exc(), | ||
), | ||
) | ||
|
||
@abstractmethod | ||
def load_identity_groups(self) -> Iterable[Dict[str, Any]]: | ||
raise NotImplementedError("Implement this method to read identity records") | ||
|
||
@property | ||
def name(self) -> str: | ||
return self.IDENTITIES_STREAM_NAME | ||
|
||
def get_cursor(self) -> Optional[Cursor]: | ||
return None |