Skip to content

Commit b1b3e59

Browse files
[miniconda] - remove applied patch on cryptography as available from upstream higher version (devcontainers#1292)
1 parent df1e443 commit b1b3e59

File tree

1 file changed

+46
-47
lines changed

1 file changed

+46
-47
lines changed

src/miniconda/.devcontainer/apply_security_patches.sh

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,54 @@
55

66
# define array of packages for pinning to the patched versions
77
# vulnerable_packages=( "package1=version1" "package2=version2" "package3=version3" )
8-
vulnerable_packages=( "cryptography=43.0.1" )
8+
vulnerable_packages=()
99

1010
# Define the number of rows (based on the length of vulnerable_packages)
1111
rows=${#vulnerable_packages[@]}
1212

13-
# Define the number of columns
14-
cols=2
15-
16-
# Define the 2D array
17-
declare -A packages_array
18-
19-
# Fill the 2D array
20-
for ((i=0; i<rows; i++)); do
21-
# Split each element of vulnerable_packages by the '=' sign
22-
IFS='=' read -ra parts <<< "${vulnerable_packages[$i]}"
23-
# Assign the parts to the 2D array
24-
packages_array[$i,0]=${parts[0]}
25-
packages_array[$i,1]=${parts[1]}
26-
done
27-
28-
for ((i=0; i<rows; i++)); do
29-
CURRENT_VERSION=$(pip show "${packages_array[$i,0]}" --disable-pip-version-check | grep '^Version:' | awk '{print $2}')
30-
REQUIRED_VERSION="${packages_array[$i,1]}"
31-
GREATER_VERSION_A=$((echo ${REQUIRED_VERSION}; echo ${CURRENT_VERSION}) | sort -V | tail -1)
32-
# Check if the required_version is greater than current_version
33-
if [[ $CURRENT_VERSION != $GREATER_VERSION_A ]]; then
34-
echo "${packages_array[$i,0]} version v${CURRENT_VERSION} installed by the base image is not greater or equal to the required: v${REQUIRED_VERSION}"
35-
# Check whether conda channel has a greater or equal version available, so install from conda, otherwise use pip package manager
36-
channel_name="anaconda"
37-
CONDA_VERSION=$(conda search "${packages_array[$i,0]}" -c "$channel_name" | \
38-
grep -E '^[[:alnum:]]' | \
39-
awk '{print $2}' | \
40-
sort -V | \
41-
uniq | \
42-
tail -n 2 | \
43-
head -n 1)
44-
if [[ -z "$CONDA_VERSION" ]]; then
45-
echo "No version for ${packages_array[$i,0]} found in conda channel."
46-
CONDA_VERSION="0"
47-
fi
48-
GREATER_VERSION_B=$((echo ${REQUIRED_VERSION}; echo ${CONDA_VERSION}) | sort -V | tail -1)
49-
if [[ $CONDA_VERSION == $GREATER_VERSION_B ]]; then
50-
echo -e "Found Version v${CONDA_VERSION} in the Conda channel which is greater than or equal to the required version: v${REQUIRED_VERSION}. \n";
51-
echo "Installing ${packages_array[$i,0]} from source from conda channel for v${REQUIRED_VERSION}..."
52-
conda install "${packages_array[$i,0]}==${CONDA_VERSION}"
53-
elif [[ $REQUIRED_VERSION == $GREATER_VERSION_B ]]; then
54-
echo -e "Required version: v${REQUIRED_VERSION} is greater than the version found in the Conda channel v${CONDA_VERSION}. \n";
55-
echo "Installing ${packages_array[$i,0]} from source from pip package manager for v${REQUIRED_VERSION}..."
56-
python3 -m pip install --upgrade --no-cache-dir "${packages_array[$i,0]}==${REQUIRED_VERSION}"
13+
if [ $rows -gt 0 ]; then
14+
# Define the number of columns
15+
cols=2
16+
# Define the 2D array
17+
declare -A packages_array
18+
# Fill the 2D array
19+
for ((i=0; i<rows; i++)); do
20+
# Split each element of vulnerable_packages by the '=' sign
21+
IFS='=' read -ra parts <<< "${vulnerable_packages[$i]}"
22+
# Assign the parts to the 2D array
23+
packages_array[$i,0]=${parts[0]}
24+
packages_array[$i,1]=${parts[1]}
25+
done
26+
for ((i=0; i<rows; i++)); do
27+
CURRENT_VERSION=$(pip show "${packages_array[$i,0]}" --disable-pip-version-check | grep '^Version:' | awk '{print $2}')
28+
REQUIRED_VERSION="${packages_array[$i,1]}"
29+
GREATER_VERSION_A=$((echo ${REQUIRED_VERSION}; echo ${CURRENT_VERSION}) | sort -V | tail -1)
30+
# Check if the required_version is greater than current_version
31+
if [[ $CURRENT_VERSION != $GREATER_VERSION_A ]]; then
32+
echo "${packages_array[$i,0]} version v${CURRENT_VERSION} installed by the base image is not greater or equal to the required: v${REQUIRED_VERSION}"
33+
# Check whether conda channel has a greater or equal version available, so install from conda, otherwise use pip package manager
34+
channel_name="anaconda"
35+
CONDA_VERSION=$(conda search "${packages_array[$i,0]}" -c "$channel_name" | \
36+
grep -E '^[[:alnum:]]' | \
37+
awk '{print $2}' | \
38+
sort -V | \
39+
uniq | \
40+
tail -n 2 | \
41+
head -n 1)
42+
if [[ -z "$CONDA_VERSION" ]]; then
43+
echo "No version for ${packages_array[$i,0]} found in conda channel."
44+
CONDA_VERSION="0"
45+
fi
46+
GREATER_VERSION_B=$((echo ${REQUIRED_VERSION}; echo ${CONDA_VERSION}) | sort -V | tail -1)
47+
if [[ $CONDA_VERSION == $GREATER_VERSION_B ]]; then
48+
echo -e "Found Version v${CONDA_VERSION} in the Conda channel which is greater than or equal to the required version: v${REQUIRED_VERSION}. \n";
49+
echo "Installing ${packages_array[$i,0]} from source from conda channel for v${REQUIRED_VERSION}..."
50+
conda install "${packages_array[$i,0]}==${CONDA_VERSION}"
51+
elif [[ $REQUIRED_VERSION == $GREATER_VERSION_B ]]; then
52+
echo -e "Required version: v${REQUIRED_VERSION} is greater than the version found in the Conda channel v${CONDA_VERSION}. \n";
53+
echo "Installing ${packages_array[$i,0]} from source from pip package manager for v${REQUIRED_VERSION}..."
54+
python3 -m pip install --upgrade --no-cache-dir "${packages_array[$i,0]}==${REQUIRED_VERSION}"
55+
fi
5756
fi
58-
fi
59-
done
57+
done
58+
fi

0 commit comments

Comments
 (0)