Skip to content

Commit b295c2d

Browse files
committed
Added insert_proxy_config.sh to edit configuration.py in client
1 parent b778952 commit b295c2d

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

scripts/insert_proxy_config.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
#!/usr/bin/env bash
2-
# insert_proxy_config.sh - run this after openapi-generator release.sh
2+
33
CONFIG_PATH="../python_kubernetes/kubernetes/client"
44

5-
# Compute the full file path
65
CONFIG_FILE="$CONFIG_PATH/configuration.py"
76

8-
# --- Normalize Windows-style backslashes to Unix forward slashes ---
7+
# Normalize
98
CONFIG_FILE="$(echo "$CONFIG_FILE" | sed 's|\\|/|g')"
109

11-
# --- Ensure the target file exists and is writable ---
10+
1211
if [ ! -f "$CONFIG_FILE" ] || [ ! -w "$CONFIG_FILE" ]; then
1312
echo "Error: $CONFIG_FILE does not exist or is not writable." >&2
1413
exit 1
1514
fi
1615

17-
# --- Step 1: Ensure 'import os' follows existing imports (idempotent) ---
16+
# Import OS
1817
if ! grep -qE '^import os$' "$CONFIG_FILE"; then
1918
LAST_IMPORT=$(grep -nE '^(import |from )' "$CONFIG_FILE" | tail -n1 | cut -d: -f1)
2019
if [ -n "$LAST_IMPORT" ]; then
@@ -31,13 +30,12 @@ else
3130
echo "'import os' already present; no changes made."
3231
fi
3332

34-
# --- Step 2: Insert proxy & no_proxy environment code (idempotent) ---
33+
# Ensure proxy and no_proxy
3534
if ! grep -q 'os.getenv("HTTPS_PROXY"' "$CONFIG_FILE"; then
3635
LINE=$(grep -n "self.proxy = None" "$CONFIG_FILE" | cut -d: -f1)
3736
if [ -n "$LINE" ]; then
3837
INDENT=$(sed -n "${LINE}s/^\( *\).*/\1/p" "$CONFIG_FILE")
3938

40-
# Build the insertion block with correct indentation
4139

4240
BLOCK+="${INDENT}# Load proxy from environment variables (if set)\n"
4341
BLOCK+="${INDENT}if os.getenv(\"HTTPS_PROXY\"): self.proxy = os.getenv(\"HTTPS_PROXY\")\n"
@@ -49,7 +47,6 @@ if ! grep -q 'os.getenv("HTTPS_PROXY"' "$CONFIG_FILE"; then
4947
BLOCK+="${INDENT}if os.getenv(\"NO_PROXY\"): self.no_proxy = os.getenv(\"NO_PROXY\")\n"
5048
BLOCK+="${INDENT}if os.getenv(\"no_proxy\"): self.no_proxy = os.getenv(\"no_proxy\")"
5149

52-
# Insert the block after the proxy default line
5350
sed -i "${LINE}a $BLOCK" "$CONFIG_FILE"
5451
echo "Proxy and no_proxy environment code inserted into $CONFIG_FILE."
5552
else

0 commit comments

Comments
 (0)