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