Skip to content

Commit 403a41f

Browse files
author
Oleksandr Bazarnov
committed
formatted
1 parent fd5d696 commit 403a41f

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

airbyte_cdk/sources/declarative/migrations/manifest/manifest_migration.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ def migrate(self, manifest: ManifestType) -> None:
3434
:param kwargs: Additional arguments for migration
3535
"""
3636

37+
def _is_component(self, obj: Dict[str, Any]) -> bool:
38+
"""
39+
Check if the object is a component.
40+
41+
:param obj: The object to check
42+
:return: True if the object is a component, False otherwise
43+
"""
44+
return TYPE_TAG in obj.keys()
45+
46+
def _is_migratable(self, obj: Dict[str, Any]) -> bool:
47+
"""
48+
Check if the object is a migratable component.
49+
50+
:param obj: The object to check
51+
:return: True if the object is a migratable component, False otherwise
52+
"""
53+
return obj[TYPE_TAG] not in NON_MIGRATABLE_TYPES
54+
3755
def _process_manifest(self, obj: Any) -> None:
3856
"""
3957
Recursively processes a manifest object, migrating components that match the migration criteria.
@@ -54,21 +72,21 @@ def _process_manifest(self, obj: Any) -> None:
5472
None, since we process the manifest in place.
5573
"""
5674
if isinstance(obj, dict):
57-
obj_keys = obj.keys()
58-
# check for component type match the designed migration
59-
if TYPE_TAG in obj_keys:
60-
obj_type = obj[TYPE_TAG]
61-
62-
# do not migrate if the particular type is in the list of non-migratable types
63-
if obj_type in NON_MIGRATABLE_TYPES:
75+
# Check if the object is a component
76+
if self._is_component(obj):
77+
# Check if the object is allowed to be migrated
78+
if not self._is_migratable(obj):
6479
return
6580

81+
# Check if the object should be migrated
6682
if self.should_migrate(obj):
83+
# Perform the migration, if needed
6784
self.migrate(obj)
6885

6986
# Process all values in the dictionary
70-
for v in list(obj.values()):
71-
self._process_manifest(v)
87+
for value in list(obj.values()):
88+
self._process_manifest(value)
89+
7290
elif isinstance(obj, list):
7391
# Process all items in the list
7492
for item in obj:

airbyte_cdk/sources/declarative/migrations/manifest/migrations/http_requester_path_to_url_migration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010

1111
class HttpRequesterPathToUrlMigration(ManifestMigration):
12+
"""
13+
This migration is responsible for migrating the `path` key to `url` in the HttpRequester component.
14+
The `path` key is expected to be a relative path, and the `url` key is expected to be a full URL.
15+
The migration will concatenate the `url_base` and `path` to form a full URL.
16+
"""
17+
1218
component_type = "HttpRequester"
1319
original_key = "path"
1420
replacement_key = "url"

airbyte_cdk/sources/declarative/migrations/manifest/migrations/http_requester_url_base_to_url_migration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77

88
class HttpRequesterUrlBaseToUrlMigration(ManifestMigration):
9+
"""
10+
This migration is responsible for migrating the `url_base` key to `url` in the HttpRequester component.
11+
The `url_base` key is expected to be a base URL, and the `url` key is expected to be a full URL.
12+
The migration will copy the value of `url_base` to `url`.
13+
"""
14+
915
component_type = "HttpRequester"
1016
original_key = "url_base"
1117
replacement_key = "url"

0 commit comments

Comments
 (0)