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

Add script to automate RS org settings updates for local testing #1489

Merged
merged 6 commits into from
Oct 28, 2024

Conversation

basiliskus
Copy link
Contributor

@basiliskus basiliskus commented Oct 25, 2024

Script to automate the RS Setup step to edit the organization YAML files in RS

The script uses yq to update the organization settings YAML files in RS to:

  • use local REST transport settings for Flexion's etor-service-receiver receivers
  • use local SFTP transport settings for Flexion's simulated-hospital and simulated-lab receivers
  • use local SFTP transport settings for partner organizations

Issue

#1488

Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

1488 - Fully compliant

Fully compliant requirements:

  • Add script to automate updating RS org settings for local testing
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Hardcoded URLs
The script contains hardcoded URLs for token and report endpoints, which might not be suitable for all environments.

Hardcoded File Paths
The script uses hardcoded file paths for SFTP uploads, which could lead to issues if the directory structure changes or is different in other environments.

Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Score
Best practice
Add a check to ensure the 'yq' command is available before running the script

Ensure that the yq command is installed and available in the script's environment to
avoid runtime errors. You can add a check at the beginning of the script to verify
this and provide a clear error message if yq is not found.

scripts/rs/update_org_yaml.sh [1]

 #!/bin/bash
+if ! command -v yq &> /dev/null
+then
+    echo "yq could not be found. Please install yq to run this script."
+    exit 1
+fi
 ...
Suggestion importance[1-10]: 8

Why: This suggestion is crucial for ensuring the script runs successfully in environments where 'yq' might not be installed, preventing runtime errors and improving user experience.

8
Implement error handling for the 'yq' command to manage failures gracefully

Add error handling for the yq command to manage any failures during the YAML file
updates, such as permission issues or malformed YAML content.

scripts/rs/update_org_yaml.sh [4-20]

-yq eval '.[0].receivers[] |= (
+if ! yq eval '.[0].receivers[] |= (
 ...
-)' -i settings/STLTs/Flexion/flexion.yml
+)' -i settings/STLTs/Flexion/flexion.yml; then
+    echo "Failed to update YAML file."
+    exit 1
+fi
Suggestion importance[1-10]: 7

Why: Adding error handling for the 'yq' command is important to manage potential failures like permission issues or malformed YAML, which enhances the robustness of the script.

7
Use absolute paths for file operations to avoid path-related errors

Consider using absolute paths for the YAML files being modified or ensure the script
is always run from a consistent directory to prevent path-related errors.

scripts/rs/update_org_yaml.sh [4-20]

 yq eval '.[0].receivers[] |= (
 ...
-)' -i settings/STLTs/Flexion/flexion.yml
+)' -i /absolute/path/to/settings/STLTs/Flexion/flexion.yml
Suggestion importance[1-10]: 6

Why: Using absolute paths can indeed prevent errors related to the current working directory, which is a good practice, especially for scripts that might be run from different locations.

6
Maintainability
Encapsulate the loop body in a function for better readability and maintainability

Wrap the loop body in a function to improve readability and maintainability of the
script, especially if the loop or its body grows in complexity.

scripts/rs/update_org_yaml.sh [23-30]

-for file in settings/STLTs/CA/ucsd.yml settings/STLTs/LA/la-ochsner.yml settings/STLTs/LA/la-phl.yml; do
+update_yaml() {
     yq eval '.[0].receivers[] |= select(.name == "etor-nbs-results" or .name == "etor-nbs-orders").transport = {
     ...
-    }' -i "$file"
+    }' -i "$1"
+}
+for file in settings/STLTs/CA/ucsd.yml settings/STLTs/LA/la-ochsner.yml settings/STLTs/LA/la-phl.yml; do
+    update_yaml "$file"
 done
Suggestion importance[1-10]: 5

Why: Wrapping the loop body in a function can improve readability and maintainability, especially if the script grows in complexity, although the current complexity does not make this critical.

5

@basiliskus basiliskus marked this pull request as ready for review October 28, 2024 19:56
Copy link

Copy link
Member

@halprin halprin left a comment

Choose a reason for hiding this comment

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

Wow, that's for sure some yq dark magic.

@basiliskus basiliskus merged commit 2b1b01d into main Oct 28, 2024
17 checks passed
@basiliskus basiliskus deleted the story/1488/automate-org-settings-update branch October 28, 2024 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants