Skip to content
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

chore: limiting dynamic config in zendesk #1796

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 52 additions & 29 deletions scripts/schemaGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from constants import CONFIG_DIR

EXCLUDED_DEST = ["postgres", "bq", "azure_synapse", "clickhouse", "deltalake", "kafka"]
defaultSubPattern = "(^\\{\\{.*\\|\\|(.*)\\}\\}$)"
defaultEnvPattern = "(^env[.].+)"


class FieldTypeEnum(Enum):
Expand Down Expand Up @@ -56,6 +58,54 @@ def get_options_list_for_enum(field):
return options_list


def is_field_purpose(field):
"""Checks if a field is a purpose field by looking for 'purpose' in either the 'value' or 'configKey' property.

Args:
field (object): Individual field in ui-config, containing properties like value or configKey.

Returns:
bool: True if field is a purpose field, False otherwise.
"""
return (
"value" in field and field["value"] == "purpose"
or
"configKey" in field and field["configKey"] == "purpose"
)

def generate_for_regexed_field(field) -> str:
pattern = field["regex"]
if not is_field_purpose(field):
if "dynamicConfigSupported" in field and field["dynamicConfigSupported"]:
if defaultSubPattern not in pattern:
pattern = "|".join([defaultSubPattern, pattern])
if defaultEnvPattern not in pattern:
indexToPlace = pattern.find(defaultSubPattern) + len(defaultSubPattern)
pattern = (
pattern[:indexToPlace]
+ "|"
+ defaultEnvPattern
+ pattern[indexToPlace:]
)
else:
if defaultEnvPattern not in pattern:
pattern = "|".join([defaultEnvPattern, pattern])

return pattern

def generate_for_non_regexed_field(field) -> str:
# TODO: we should not use a case here for the individual properties. Just pass the desired pattern as regex property
# in ketch purpose fields and delete next case
pattern = "^(.{0,100})$"
if is_field_purpose(field):
return pattern
# non purpose field & regex is not present in the field
if field["dynamicConfigSupported"]:
pattern = "|".join([defaultSubPattern, pattern])
if defaultEnvPattern not in pattern:
pattern = "|".join([defaultEnvPattern, pattern])
return pattern

def generalize_regex_pattern(field):
"""Generates the pattern for schema based on the type of field.
- For type : singleSelect and dynamicSelectForm, the pattern is generated by iterating over options.
Expand All @@ -69,36 +119,9 @@ def generalize_regex_pattern(field):
Returns:
string: generated pattern for the field.
"""
defaultSubPattern = "(^\\{\\{.*\\|\\|(.*)\\}\\}$)"
defaultEnvPattern = "(^env[.].+)"
pattern = ""
if "regex" in field:
pattern = field["regex"]
if defaultSubPattern not in pattern and (
("value" not in field or field["value"] != "purpose")
and ("configKey" not in field or field["configKey"] != "purpose")
):
pattern = "|".join([defaultSubPattern, pattern])
if defaultEnvPattern not in pattern and (
("value" not in field or field["value"] != "purpose")
and ("configKey" not in field or field["configKey"] != "purpose")
):
indexToPlace = pattern.find(defaultSubPattern) + len(defaultSubPattern)
pattern = (
pattern[:indexToPlace]
+ "|"
+ defaultEnvPattern
+ pattern[indexToPlace:]
)
# TODO: we should not use a case here for the individual properties. Just pass the desired pattern as regex property
# in ketch purpose fields and delete next case
elif ("value" in field and field["value"] == "purpose") or (
"configKey" in field and field["configKey"] == "purpose"
):
pattern = "^(.{0,100})$"
else:
pattern = "|".join([defaultSubPattern, defaultEnvPattern, "^(.{0,100})$"])
return pattern
return generate_for_regexed_field(field)
return generate_for_non_regexed_field(field)


def is_dest_field_dependent_on_source(field, dbConfig, schema_field_name):
Expand Down
Loading
Loading