Skip to content

Commit b778952

Browse files
committed
Added
1 parent 638abe2 commit b778952

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

scripts/insert_proxy_config.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
# insert_proxy_config.sh - run this after openapi-generator release.sh
3+
CONFIG_PATH="../python_kubernetes/kubernetes/client"
4+
5+
# Compute the full file path
6+
CONFIG_FILE="$CONFIG_PATH/configuration.py"
7+
8+
# --- Normalize Windows-style backslashes to Unix forward slashes ---
9+
CONFIG_FILE="$(echo "$CONFIG_FILE" | sed 's|\\|/|g')"
10+
11+
# --- Ensure the target file exists and is writable ---
12+
if [ ! -f "$CONFIG_FILE" ] || [ ! -w "$CONFIG_FILE" ]; then
13+
echo "Error: $CONFIG_FILE does not exist or is not writable." >&2
14+
exit 1
15+
fi
16+
17+
# --- Step 1: Ensure 'import os' follows existing imports (idempotent) ---
18+
if ! grep -qE '^import os$' "$CONFIG_FILE"; then
19+
LAST_IMPORT=$(grep -nE '^(import |from )' "$CONFIG_FILE" | tail -n1 | cut -d: -f1)
20+
if [ -n "$LAST_IMPORT" ]; then
21+
sed -i "$((LAST_IMPORT+1))i import os" "$CONFIG_FILE"
22+
else
23+
if head -n1 "$CONFIG_FILE" | grep -q '^#!'; then
24+
sed -i '2i import os' "$CONFIG_FILE"
25+
else
26+
sed -i '1i import os' "$CONFIG_FILE"
27+
fi
28+
fi
29+
echo "Inserted 'import os' after existing imports in $CONFIG_FILE."
30+
else
31+
echo "'import os' already present; no changes made."
32+
fi
33+
34+
# --- Step 2: Insert proxy & no_proxy environment code (idempotent) ---
35+
if ! grep -q 'os.getenv("HTTPS_PROXY"' "$CONFIG_FILE"; then
36+
LINE=$(grep -n "self.proxy = None" "$CONFIG_FILE" | cut -d: -f1)
37+
if [ -n "$LINE" ]; then
38+
INDENT=$(sed -n "${LINE}s/^\( *\).*/\1/p" "$CONFIG_FILE")
39+
40+
# Build the insertion block with correct indentation
41+
42+
BLOCK+="${INDENT}# Load proxy from environment variables (if set)\n"
43+
BLOCK+="${INDENT}if os.getenv(\"HTTPS_PROXY\"): self.proxy = os.getenv(\"HTTPS_PROXY\")\n"
44+
BLOCK+="${INDENT}if os.getenv(\"https_proxy\"): self.proxy = os.getenv(\"https_proxy\")\n"
45+
BLOCK+="${INDENT}if os.getenv(\"HTTP_PROXY\"): self.proxy = os.getenv(\"HTTP_PROXY\")\n"
46+
BLOCK+="${INDENT}if os.getenv(\"http_proxy\"): self.proxy = os.getenv(\"http_proxy\")\n"
47+
BLOCK+="${INDENT}self.no_proxy = None\n"
48+
BLOCK+="${INDENT}# Load no_proxy from environment variables (if set)\n"
49+
BLOCK+="${INDENT}if os.getenv(\"NO_PROXY\"): self.no_proxy = os.getenv(\"NO_PROXY\")\n"
50+
BLOCK+="${INDENT}if os.getenv(\"no_proxy\"): self.no_proxy = os.getenv(\"no_proxy\")"
51+
52+
# Insert the block after the proxy default line
53+
sed -i "${LINE}a $BLOCK" "$CONFIG_FILE"
54+
echo "Proxy and no_proxy environment code inserted into $CONFIG_FILE."
55+
else
56+
echo "Warning: 'self.proxy = None' not found in $CONFIG_FILE. No proxy code inserted."
57+
fi
58+
else
59+
echo "Proxy environment code already present; no changes made."
60+
fi

scripts/release.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ git diff-index --quiet --cached HEAD || git commit -am "update changelog"
207207

208208
# Re-generate the client
209209
scripts/update-client.sh
210-
210+
#edit comfiguration.py files
211+
scripts/insert_proxy_config.sh
211212
# Apply hotfixes
212213
rm -r kubernetes/test/
213214
git add .

0 commit comments

Comments
 (0)