-
Notifications
You must be signed in to change notification settings - Fork 798
[anaconda]-auto install vuln pkgs from conda / pip #1079
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
Merged
samruddhikhandale
merged 13 commits into
devcontainers:main
from
gauravsaini04:anaconda_compare_install_vuln_pkgs
Jun 11, 2024
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
99d0dd7
[anaconda]-auto install vuln pkgs from conda / pip
gauravsaini04 6df631e
Misc change
gauravsaini04 ed3b7c5
for test runs fails
gauravsaini04 b315f49
misc change
gauravsaini04 68971ba
Merge branch 'devcontainers:main' into anaconda_compare_install_vuln_…
gauravsaini04 1a5780a
changes requested
gauravsaini04 11ece68
minor change
gauravsaini04 3143cef
MSG CHANGE
gauravsaini04 9033c15
Merge branch 'devcontainers:main' into anaconda_compare_install_vuln_…
gauravsaini04 fd53e10
Merge branch 'devcontainers:main' into anaconda_compare_install_vuln_…
gauravsaini04 ab8e1d9
changes suggested
gauravsaini04 13aac29
changes acc. to review comments..
gauravsaini04 0b913dd
[anaconda] - changes as requested
gauravsaini04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
[anaconda]-auto install vuln pkgs from conda / pip
- Loading branch information
commit 99d0dd7b9175ef5f4a4e5e3671fd63db8bd78e06
There are no files selected for viewing
This file contains hidden or 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
127 changes: 127 additions & 0 deletions
127
src/anaconda/.devcontainer/install_vulnerable_packages.sh
This file contains hidden or 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,127 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Find and install packages, if required, using conda channel or using pip package manager | ||
| vulnerable_packages=( "pydantic=2.5.3" "joblib=1.3.1" "mistune=3.0.1" "werkzeug=3.0.3" "transformers=4.36.0" "pillow=10.3.0" "aiohttp=3.9.4" \ | ||
gauravsaini04 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "cryptography=42.0.4" "gitpython=3.1.41" "jupyter-lsp=2.2.2" "idna=3.7" "jinja2=3.1.4" "scrapy=2.11.2" ) | ||
|
|
||
| # Define the number of rows (based on the length of vulnerable_packages) | ||
| rows=${#vulnerable_packages[@]} | ||
|
|
||
| # Define the number of columns | ||
| cols=4 | ||
|
|
||
| # Define the 2D array | ||
| declare -A packages_array | ||
|
|
||
| # Fill the 2D array | ||
| for ((i=0; i<rows; i++)); do | ||
| # Split each element of vulnerable_packages by the '=' sign | ||
| IFS='=' read -ra parts <<< "${vulnerable_packages[$i]}" | ||
| # Assign the parts to the 2D array | ||
| packages_array[$i,0]=${parts[0]} | ||
| packages_array[$i,1]=${parts[1]} | ||
| done | ||
|
|
||
| value=0 | ||
| insert_in_2D_array() { | ||
| local package_name=$1 | ||
| local channel_name="anaconda" | ||
|
|
||
| echo "Running conda search for package '$package_name' in channel '$channel_name'..." | ||
|
|
||
| # Capture the conda search output and process it | ||
| latest_version=$(conda search "$package_name" -c "$channel_name" | \ | ||
| grep -E '^[[:alnum:]]' | \ | ||
| awk '{print $2}' | \ | ||
| sort -V | \ | ||
| uniq | \ | ||
| tail -n 2 | \ | ||
| head -n 1) | ||
|
|
||
| found_version=$(pip show $package_name | grep '^Version:' | awk '{print $2}') | ||
| if [[ -z "$latest_version" ]]; then | ||
| echo "No version found in anaconda channel." | ||
| latest_version="0" | ||
| fi | ||
| if [[ -z "$found_version" ]]; then | ||
| echo "No package version found in upstream." | ||
| found_version="0" | ||
| fi | ||
| echo "Latest version of $package_name: $latest_version" | ||
| packages_array[$i,2]="$found_version" | ||
| packages_array[$i,3]="$latest_version" | ||
| ((value++)) | ||
| } | ||
|
|
||
| # store found package versions in upstream as 3rd column element in 2D array | ||
| check_packages_anaconda_channel() { | ||
| for ((i=0; i<rows; i++)); do | ||
| PACKAGE_NAME=${packages_array[$i,0]} | ||
| echo "Package Name $i: $PACKAGE_NAME" | ||
| insert_in_2D_array $PACKAGE_NAME | ||
| done | ||
| } | ||
|
|
||
| compare_and_install_packages() { | ||
| check_packages_anaconda_channel | ||
| printf "%-10s %-10s %-10s %-10s\n" "Package Name," "Version needed," "Version Present," "Conda channel version" | ||
| echo "---------------------------------------------------------------------------------" | ||
| for ((i=0; i<rows; i++)); do | ||
| for ((j=0; j<cols; j++)); do | ||
| echo -n "${packages_array[$i,$j]} " | ||
| done | ||
| echo | ||
| done | ||
| for ((i=0; i<rows; i++)); do | ||
| echo -e "\nComparing semver versions between required and present currently for ${packages_array[$i,0]}" | ||
| comparison_result=$(compare_semver "${packages_array[$i,1]}" "${packages_array[$i,2]}") | ||
| if [[ $comparison_result == "greater" ]]; then | ||
| echo -e "\nComparing semver versions between required and available through conda channel for $1" | ||
| comparison_result2=$(compare_semver "${packages_array[$i,1]}" "${packages_array[$i,3]}") | ||
| if [[ $comparison_result2 == "greater" ]]; then | ||
| echo -e "\nInstalling ${packages_array[$i,0]} using pip" | ||
| python3 -m pip install --upgrade "${packages_array[$i,0]}==${packages_array[$i,1]}" | ||
| else | ||
| echo -e "\nInstalling ${packages_array[$i,0]} using conda channel" | ||
| conda install "${packages_array[$i,0]}==${packages_array[$i,3]}" | ||
| fi | ||
| else | ||
| echo -e "No need to update ${packages_array[$i,0]}"; | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| # Function to compare semver versions | ||
| compare_semver() { | ||
| # Split versions into arrays | ||
| IFS='.' read -r -a version1 <<< "$1" | ||
| IFS='.' read -r -a version2 <<< "$2" | ||
|
|
||
| comparison="" | ||
| # Compare MAJOR version | ||
| if (( ${version1[0]} > ${version2[0]} )); then | ||
gauravsaini04 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| comparison="greater" | ||
| elif (( ${version1[0]} < ${version2[0]} )); then | ||
| comparison="lesser" | ||
| else | ||
| # Compare MINOR version | ||
| if (( ${version1[1]} > ${version2[1]} )); then | ||
| comparison="greater" | ||
| elif (( ${version1[1]} < ${version2[1]} )); then | ||
| comparison="lesser" | ||
| else | ||
| # Compare PATCH version | ||
| if (( ${version1[2]} > ${version2[2]} )); then | ||
| comparison="greater" | ||
| elif (( ${version1[2]} < ${version2[2]} )); then | ||
| comparison="lesser" | ||
| else | ||
| comparison="equal" | ||
| fi | ||
| fi | ||
| fi | ||
gauravsaini04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| echo $comparison | ||
| } | ||
|
|
||
| compare_and_install_packages | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.