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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

sanpj2292
Copy link
Contributor

@sanpj2292 sanpj2292 commented Nov 13, 2024

What are the changes introduced in this PR?

Limit dynamic config to specific fields for Zendesk destination

What is the related Linear task?

Resolves INT-2902

Please explain the objectives of your changes below

Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here

Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

N/A

Any new dependencies introduced with this change?

N/A

Any new checks got introduced or modified in test suites. Please explain the changes.

N/A


Developer checklist

  • My code follows the style guidelines of this project

  • No breaking changes are being introduced.

  • All related docs linked with the PR?

  • All changes manually tested?

  • Any documentation changes needed with this change?

  • I have executed schemaGenerator tests and updated schema if needed

  • Are sensitive fields marked as secret in definition config?

  • My test cases and placeholders use only masked/sample values for sensitive fields

  • Is the PR limited to 10 file changes & one task?

Reviewer checklist

  • Is the type of change in the PR title appropriate as per the changes?

  • Verified that there are no credentials or confidential data exposed with the changes.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced support for dynamic configuration in user input fields.
    • Enhanced handling of regex patterns for various fields to simplify validation.
    • Added new functions for better processing of fields based on purpose and regex patterns.
  • Bug Fixes

    • Improved input validation by streamlining regex patterns for fields like API Token and Consent.
  • Documentation

    • Updated documentation strings for new functions to clarify their purpose and usage.

Copy link

coderabbitai bot commented Nov 13, 2024

Walkthrough

The changes involve significant updates to the schemaGenerator.py script, introducing new functions for handling field purposes and regex patterns. The JSON schema for Zendesk configurations has been modified to simplify regex patterns for various fields, enhancing input validation. Additionally, the ui-config.json file has been updated to support dynamic configurations and streamline regex patterns for user input fields. Overall, these modifications improve the clarity and maintainability of the code and configuration files.

Changes

File Path Change Summary
scripts/schemaGenerator.py Added functions: is_field_purpose, generate_for_regexed_field, generate_for_non_regexed_field. Refactored generalize_regex_pattern. Defined default patterns at the module level.
src/configurations/destinations/zendesk/schema.json Updated regex patterns for apiToken, oneTrustCookieCategory, consent, and purpose fields to simplify validation rules.
src/configurations/destinations/zendesk/ui-config.json Enhanced user input fields with dynamicConfigSupported. Simplified regex patterns for "Email," "API Token," "OneTrust Consent Category IDs," "Ketch Consent Purpose IDs," and "Consent management settings."

Suggested reviewers

  • lvrach
  • am6010
  • AchuthaSourabhC
  • ssbeefeater
  • debanjan97
  • cisse21
  • ruchiramoitra
  • 1abhishekpandey
  • ItsSudip
  • sandeepdsvs
  • krishna2020
  • shrouti1507

🐇 In the code, a hop, a skip,
New functions added, let them rip!
Patterns simplified, oh what a treat,
Dynamic configs make it neat!
With every change, our work's refined,
In the schema, clarity we find! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (5)
src/configurations/destinations/zendesk/ui-config.json (1)

Line range hint 1-211: Consider a consistent strategy for dynamic configuration

The current changes show mixed approaches to dynamic configuration:

  1. Some fields are getting expanded dynamic config support (email, subdomain, source name)
  2. Other fields are getting limited through regex simplification (API token, consent fields)

Consider:

  1. Documenting the criteria for determining which fields should support dynamic configuration
  2. Maintaining consistent regex patterns across similar field types
  3. Adding validation rules in the schema to ensure proper value resolution when dynamic config is used
scripts/schemaGenerator.py (4)

27-28: Add comments to explain default regex patterns

Consider adding comments to describe the purpose and usage of defaultSubPattern and defaultEnvPattern for better code readability.


61-75: Clarify logical conditions in is_field_purpose function

To improve readability and ensure correct logic evaluation, add parentheses to make the precedence of and and or operations explicit.

Apply this diff:

 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"
+        ("value" in field and field["value"] == "purpose")
         or
-        "configKey" in field and field["configKey"] == "purpose"
+        ("configKey" in field and field["configKey"] == "purpose")
     )

76-95: Reduce code duplication in generate_for_regexed_field

The checks for defaultSubPattern and defaultEnvPattern are similar in both branches of the if statement. Consider refactoring to reduce repetition and improve maintainability.

You could combine the logic to handle defaultSubPattern and defaultEnvPattern in a single place.


96-108: Simplify pattern concatenation in generate_for_non_regexed_field

The logic for appending patterns can be streamlined for better readability.

Apply this diff:

 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])
+    pattern = "|".join([defaultEnvPattern, pattern]) if defaultEnvPattern not in pattern else pattern
     return pattern
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2e64eca and 356d15b.

📒 Files selected for processing (3)
  • scripts/schemaGenerator.py (3 hunks)
  • src/configurations/destinations/zendesk/schema.json (34 hunks)
  • src/configurations/destinations/zendesk/ui-config.json (6 hunks)
🔇 Additional comments (9)
src/configurations/destinations/zendesk/ui-config.json (3)

20-20: LGTM! Security improvement in API token configuration

The simplified regex pattern that only allows environment variables improves security by restricting how API tokens can be configured. This is a positive change that aligns with best practices for handling sensitive credentials.


87-87: LGTM! Consistent regex pattern simplification

The regex pattern simplification across consent-related fields:

  • Improves consistency in validation rules
  • Properly limits configuration options to environment variables
  • Aligns with the PR objective of limiting dynamic configuration

Also applies to: 115-115, 196-196


33-34: Review dynamic configuration strategy for subdomain and source name

Similar to the email field, adding dynamicConfigSupported: true to these fields appears to expand rather than limit dynamic configuration capabilities. Please clarify:

  1. Why are we enabling dynamic configuration for these fields?
  2. How does this align with the PR objective of limiting dynamic config?
  3. Should we maintain consistency in regex patterns across all fields?
#!/bin/bash
# Check the evolution of dynamic config support in this destination
git log -p src/configurations/destinations/zendesk/ui-config.json | rg -A 5 -B 5 "dynamicConfigSupported"

Also applies to: 44-45

src/configurations/destinations/zendesk/schema.json (5)

50-50: Consistent pattern updates across OneTrust cookie categories

The regex pattern changes for oneTrustCookieCategory fields across all platforms (android, ios, web, unity, amp, cloud, warehouse, reactnative, flutter, cordova, shopify) maintain consistency in the validation rules. This is a good practice for maintainability.

Also applies to: 62-62, 74-74, 86-86, 98-98, 110-110, 122-122, 134-134, 146-146, 158-158, 170-170


197-197: Consistent pattern updates for consent management

The regex pattern changes for consent fields in the consent management section maintain consistency across all platforms. This aligns with the PR objective of limiting dynamic configuration.

Also applies to: 243-243, 289-289, 335-335, 381-381, 427-427, 473-473, 519-519, 565-565, 611-611, 657-657


747-747: Consistent pattern updates for Ketch consent purposes

The regex pattern changes for purpose fields in the Ketch consent purposes section maintain consistency across all platforms. This aligns with the PR objective of limiting dynamic configuration.

Also applies to: 759-759, 771-771, 783-783, 795-795, 807-807, 819-819, 831-831, 843-843, 855-855, 867-867


Line range hint 1-875: Verify impact on existing configurations

While the pattern changes are consistent and align with the PR objective, we should verify the impact on existing configurations and ensure proper migration documentation.

Let's analyze the usage patterns:

#!/bin/bash
# Description: Analyze current configuration patterns
# Expected results: Overview of current configuration usage patterns

# Check for environment variable usage
echo "Checking environment variable usage..."
rg -l '^env\.' | grep -i zendesk

# Check for direct value usage
echo "Checking direct value usage..."
rg -l '^\w{1,100}$' | grep -i zendesk

# Generate statistics for different patterns
echo "Generating pattern statistics..."
for pattern in 'env\.' '^\w{1,100}$' '\{\{.*\|\|.*\}\}'; do
  echo "Pattern: $pattern"
  rg -c "$pattern" | grep -i zendesk
done

14-14: ⚠️ Potential issue

Breaking Change: API Token pattern modification

The regex pattern for apiToken has been simplified to only allow environment variables or direct values, removing support for template variables with fallbacks ({{var||fallback}}). This change could break existing configurations that use template variables.

Let's verify if any existing configurations would be affected:

✅ Verification successful

Verification Successful: No existing Zendesk configurations use template variables.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for existing Zendesk configurations using template variables
# Expected results: List of configurations that might break with the new pattern

# Search for template variable pattern in JSON files
rg -l '\{\{.*\|\|.*\}\}' | grep -i zendesk

Length of output: 849

scripts/schemaGenerator.py (1)

123-124: Ensure consistent handling in generalize_regex_pattern

Verify that calling generate_for_regexed_field(field) when "regex" is in field aligns with the intended behavior, and that fields without "regex" are correctly processed by generate_for_non_regexed_field(field).

Comment on lines +13 to +14
"placeholder": "e.g: [email protected]",
"dynamicConfigSupported": true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Dynamic configuration support contradicts PR objectives

Adding "dynamicConfigSupported": true to multiple fields expands dynamic configuration contrary to the goal of limiting it in the Zendesk destination.

🔗 Analysis chain

Verify if email field should support dynamic configuration

Adding dynamicConfigSupported: true appears to expand rather than limit dynamic configuration capabilities. This seems to contradict the PR objective of "limiting dynamic config in zendesk". Additionally, the regex pattern above still includes template placeholders ({{..||..}}), which is inconsistent with other regex simplifications in this PR.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if other destination configs have similar dynamic config support for email
rg -l '"dynamicConfigSupported":\s*true' src/configurations/destinations/*/ui-config.json

Length of output: 1463

koladilip
koladilip previously approved these changes Nov 14, 2024
- we are considering these scenarios {{a.v.c||laksdn}}skiv, skiv{{a.v.c||laksdn}}
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (4)
src/configurations/destinations/zendesk/ui-config.json (1)

Line range hint 1-211: Architectural inconsistency in dynamic configuration approach

There appears to be a fundamental inconsistency in how dynamic configuration is being handled:

  1. Connection Settings fields (email, subdomain, source name) are being made more dynamic by adding dynamicConfigSupported: true
  2. Consent Settings fields are being made less dynamic through regex restrictions

This mixed approach seems to contradict the PR's objective of "limiting dynamic config in zendesk". Consider:

  1. Removing the new dynamicConfigSupported flags to align with the PR objective
  2. Applying consistent regex restrictions across all fields that should have limited dynamic configuration
src/configurations/destinations/zendesk/schema.json (3)

50-50: Pattern Update: OneTrust Cookie Categories across platforms

The pattern changes for oneTrustCookieCategory fields across all platforms follow the same security improvement as the API token, preventing template variables with fallbacks.

This consistent pattern application across platforms ensures uniform behavior and security constraints.

Also applies to: 62-62, 74-74, 86-86, 98-98, 110-110, 122-122, 134-134, 146-146, 158-158, 170-170


197-197: Pattern Update: Consent Management fields across platforms

The pattern changes for consent fields across all platforms align with the security improvements, maintaining consistency with other field updates.

The uniform pattern application ensures consistent validation across all platforms and integration points.

Also applies to: 243-243, 289-289, 335-335, 381-381, 427-427, 473-473, 519-519, 565-565, 611-611, 657-657


Line range hint 1-875: Overall Schema Structure Assessment

The schema maintains a consistent structure and validation patterns across all platforms and field types. The changes effectively implement the PR objective of limiting dynamic configuration while preserving environment variable support.

Consider documenting these validation changes in the migration guide to help users transition from template variables to environment variables.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 356d15b and f7df0a6.

📒 Files selected for processing (2)
  • src/configurations/destinations/zendesk/schema.json (34 hunks)
  • src/configurations/destinations/zendesk/ui-config.json (6 hunks)
🔇 Additional comments (5)
src/configurations/destinations/zendesk/ui-config.json (3)

20-20: Appropriate restriction of template placeholders

The updated regex pattern correctly limits dynamic configuration by preventing template placeholders while still allowing environment variables. This aligns well with the PR objectives.


87-87: Consistent and appropriate regex restrictions

The regex pattern updates across consent-related fields (oneTrustCookieCategory, purpose, and consent) consistently prevent template placeholders while maintaining support for environment variables. This implementation aligns well with the goal of limiting dynamic configuration.

Also applies to: 115-115, 196-196


10-14: ⚠️ Potential issue

Dynamic configuration support contradicts PR objectives

Adding "dynamicConfigSupported": true appears to expand rather than limit dynamic configuration capabilities. This seems to contradict the PR objective of "limiting dynamic config in zendesk".

src/configurations/destinations/zendesk/schema.json (2)

747-747: Pattern Update: Ketch Consent Purposes across platforms

The pattern changes for purpose fields in Ketch consent management follow the same security improvements as other fields.

Also applies to: 759-759, 771-771, 783-783, 795-795, 807-807, 819-819, 831-831, 843-843, 855-855, 867-867

✅ Verification successful

Based on the search results, I can see that the pattern change for purpose fields is consistent with test data across multiple destination configurations. All test files show the same template variable usage pattern: "purpose": "{{ event.properties.prop1 || 'val' }}". Let me verify the actual schema change in the Zendesk configuration.


Let me try a different approach to verify the pattern change in the Zendesk schema file.


Let me try one more time with a simpler pattern to check the schema file.


Pattern Update for Ketch Consent Purposes is Consistent

The pattern change "(^env[.].+)|^(?!.*\\{\\{.*\\|\\|(.*)\\}\\}).{0,100}$" is consistently applied across all purpose fields in the Zendesk schema, matching the security improvements. This pattern:

  • Allows environment variables (env. prefix)
  • Prevents template variables with fallback syntax ({{...||...}})
  • Limits string length to 100 characters
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any existing configurations using template variables in purpose fields
rg -l '"purpose":\s*".*\{\{.*\|\|.*\}\}"' | while read -r file; do
  echo "Found template variable usage in $file:"
  rg -A 1 '"purpose":\s*".*\{\{.*\|\|.*\}\}"' "$file"
done

Length of output: 82846


Script:

#!/bin/bash
# Check the pattern in the Zendesk schema file
rg -A 1 '"pattern":\s*".*env.*\|\|.*"' src/configurations/destinations/zendesk/schema.json

Length of output: 92


Script:

#!/bin/bash
# Check the specific line and surrounding context in the Zendesk schema file
rg -C 5 '(^env[.].+)|^(?!.*\{\{.*\|\|(.*)}}' src/configurations/destinations/zendesk/schema.json

Length of output: 349


Script:

#!/bin/bash
# Get the content around line 747 in the Zendesk schema file
rg -C 5 -n '"pattern":' src/configurations/destinations/zendesk/schema.json

Length of output: 13522


14-14: ⚠️ Potential issue

Breaking Change: API Token pattern restricts template variables

The new pattern prevents the use of template variables with fallbacks ({{var||fallback}}), while still allowing environment variables. This is a breaking change that improves security by limiting dynamic configuration.

✅ Verification successful

Based on the test data content, I can now generate the final response:

Pattern change improves security without breaking existing configurations

The new pattern (^env[.].+)|^(?!.*\{\{.*\|\|(.*)}}}).{1,100}$ correctly allows environment variables while preventing template variables with fallbacks. The test data shows that:

  • All test cases use direct string values or environment variables for apiToken
  • No test cases rely on template variables with fallbacks for apiToken
  • The only template variables with fallbacks appear in optional consent fields, not in critical authentication fields
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for existing configurations using template variables in apiToken
rg -l '"apiToken":\s*".*\{\{.*\|\|.*\}\}"' | while read -r file; do
  echo "Found template variable usage in $file:"
  rg -A 1 '"apiToken":\s*".*\{\{.*\|\|.*\}\}"' "$file"
done

Length of output: 59


Script:

#!/bin/bash
# Let's try a broader search for any configuration files that might use template variables
# First, find all JSON files that might contain Zendesk configurations
fd -e json | while read -r file; do
  if grep -q "zendesk" "$file"; then
    echo "=== $file ==="
    # Look for any template variable pattern in the file
    grep -A 1 '\{\{.*||.*\}\}' "$file" || true
  fi
done

# Also search for any documentation or example files that might show template usage
rg -l --type md --type txt '\{\{.*\|\|.*\}\}' || true

Length of output: 100382


Script:

#!/bin/bash
# Let's also check if there are any tests that might be using template variables
fd -e test.js -e spec.js | while read -r file; do
  if grep -q "zendesk" "$file"; then
    echo "=== $file ==="
    # Look for template variable patterns in test files
    grep -A 1 '\{\{.*||.*\}\}' "$file" || true
  fi
done

Length of output: 41


Script:

#!/bin/bash
# Let's check the git history for any recent changes related to template variables in Zendesk configs
git log -n 5 --oneline --grep="zendesk" --grep="template" || true

Length of output: 0


Script:

#!/bin/bash
# Let's check for any existing configurations in the test data that might be affected
rg -l "apiToken.*{{" test/data/validation/destinations/zendesk.json || true

# Also check for any documentation of template variables usage
rg -l "{{.*\|\|.*}}" "**/*.md" || true

# Let's also look at the schema history specifically
git log -p -n 1 src/configurations/destinations/zendesk/schema.json || true

Length of output: 310


Script:

#!/bin/bash
# Let's check the actual test data content
if [ -f "test/data/validation/destinations/zendesk.json" ]; then
    echo "=== test/data/validation/destinations/zendesk.json ==="
    cat test/data/validation/destinations/zendesk.json
fi

Length of output: 11448

Comment on lines +33 to +34
"placeholder": "Subdomain only not including .zendesk.com",
"dynamicConfigSupported": true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Inconsistent with dynamic config limitation goal

Adding dynamicConfigSupported: true to both Subdomain and Source Name fields continues the pattern of expanding rather than limiting dynamic configuration. This appears to be inconsistent with the PR's stated objective.

Also applies to: 44-45

@devops-github-rudderstack
Copy link
Contributor

This PR is considered to be stale. It has been open for 20 days with no further activity thus it is going to be closed in 7 days. To avoid such a case please consider removing the stale label manually or add a comment to the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants