forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metadata: create specs secret mask (airbytehq#25201)
- Loading branch information
1 parent
c44d18b
commit bbd48e5
Showing
8 changed files
with
241 additions
and
46 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
70 changes: 70 additions & 0 deletions
70
...yte-ci/connectors/metadata_service/orchestrator/orchestrator/assets/specs_secrets_mask.py
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,70 @@ | ||
# | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# | ||
from typing import List, Set | ||
|
||
import dpath.util | ||
import yaml | ||
from dagster import MetadataValue, Output, asset | ||
|
||
GROUP_NAME = "specs_secrets_mask" | ||
|
||
# HELPERS | ||
|
||
|
||
def get_secrets_properties_from_registry_entry(registry_entry: dict) -> List[str]: | ||
"""Traverse a registry entry to spot properties in a spec that have the "airbyte_secret" field set to true. | ||
This function assumes all the properties have a "type" field that we can use to find all the nested properties in a spec. | ||
Args: | ||
registry_entry (dict): An entry in the registry with a spec field. | ||
Returns: | ||
List[str]: List of property names marked as airbyte_secret. | ||
""" | ||
secret_properties = [] | ||
spec_properties = registry_entry["spec"]["connectionSpecification"].get("properties") | ||
if spec_properties is None: | ||
return [] | ||
for type_path, _ in dpath.util.search(spec_properties, "**/type", yielded=True): | ||
absolute_path = f"/{type_path}" | ||
if "/" in type_path: | ||
property_path, _ = absolute_path.rsplit(sep="/", maxsplit=1) | ||
else: | ||
property_path = absolute_path | ||
property_definition = dpath.util.get(spec_properties, property_path) | ||
marked_as_secret = property_definition.get("airbyte_secret", False) | ||
if marked_as_secret: | ||
secret_properties.append(property_path.split("/")[-1]) | ||
return secret_properties | ||
|
||
|
||
# ASSETS | ||
|
||
|
||
@asset(group_name=GROUP_NAME) | ||
def all_specs_secrets(oss_catalog_from_metadata: dict, cloud_catalog_from_metadata: dict) -> Set[str]: | ||
all_secret_properties = [] | ||
all_entries = ( | ||
oss_catalog_from_metadata["sources"] | ||
+ cloud_catalog_from_metadata["sources"] | ||
+ oss_catalog_from_metadata["destinations"] | ||
+ cloud_catalog_from_metadata["destinations"] | ||
) | ||
for registry_entry in all_entries: | ||
all_secret_properties += get_secrets_properties_from_registry_entry(registry_entry) | ||
return set(all_secret_properties) | ||
|
||
|
||
@asset(required_resource_keys={"catalog_directory_manager"}, group_name=GROUP_NAME) | ||
def specs_secrets_mask_yaml(context, all_specs_secrets: Set[str]) -> Output: | ||
yaml_string = yaml.dump({"properties": list(all_specs_secrets)}) | ||
catalog_directory_manager = context.resources.catalog_directory_manager | ||
file_handle = catalog_directory_manager.write_data(yaml_string.encode(), ext="yaml", key="specs_secrets_mask") | ||
metadata = { | ||
"preview": yaml_string, | ||
"gcs_path": MetadataValue.url(file_handle.gcs_path), | ||
} | ||
return Output(metadata=metadata, value=file_handle) |
5 changes: 4 additions & 1 deletion
5
airbyte-ci/connectors/metadata_service/orchestrator/orchestrator/jobs/catalog.py
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,8 +1,11 @@ | ||
# | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# | ||
from dagster import define_asset_job | ||
|
||
|
||
generate_catalog = define_asset_job(name="generate_catalog", selection=["metadata_directory_report", "metadata_definitions"]) | ||
generate_catalog_markdown = define_asset_job( | ||
name="generate_catalog_markdown", selection=["connector_catalog_location_html", "connector_catalog_location_markdown"] | ||
) | ||
generate_local_metadata_files = define_asset_job(name="generate_local_metadata_files", selection=["persist_metadata_definitions"]) | ||
generate_specs_secrets_mask_file = define_asset_job(name="generate_specs_secrets_mask_file", selection=["persist_specs_secrets_mask"]) |
18 changes: 15 additions & 3 deletions
18
airbyte-ci/connectors/metadata_service/orchestrator/poetry.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.