@leverege/build-tools 2.52.0-pedro.11 → 2.52.0-pedro.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/refresh-py-idx-sa.sh +89 -0
- package/src/refresh-py-idx.sh +17 -103
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leverege/build-tools",
|
|
3
|
-
"version": "2.52.0-pedro.
|
|
3
|
+
"version": "2.52.0-pedro.2",
|
|
4
4
|
"description": "A collection of build / support tools for Leverege developers",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"pull-git": "src/pull-git.sh",
|
|
48
48
|
"push-my-chart": "src/push-my-chart.mjs",
|
|
49
49
|
"refresh-npm-token": "src/refresh-npm-token.mjs",
|
|
50
|
+
"refresh-py-idx-sa": "src/refresh-py-idx-sa.sh",
|
|
50
51
|
"refresh-py-idx": "src/refresh-py-idx.sh",
|
|
51
52
|
"send-to-slack": "src/send-to-slack.mjs",
|
|
52
53
|
"tag-release": "src/tag-release.mjs",
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Description: Refreshes the service account key for the leverege-python-packages artifact registry repository and updates current configuration.
|
|
3
|
+
|
|
4
|
+
GCP_ORGANIZATION_ID=741866105355
|
|
5
|
+
GCP_PROJECT_ID=leverege-registry
|
|
6
|
+
GCP_LOCATION=us
|
|
7
|
+
|
|
8
|
+
echo "GCP Organization ID: $GCP_ORGANIZATION_ID"
|
|
9
|
+
echo "GCP Project ID: $GCP_PROJECT_ID"
|
|
10
|
+
echo "GCP Location: $GCP_LOCATION"
|
|
11
|
+
|
|
12
|
+
# Get account from gcloud core config and set everything before the @ as the name variable and replace . with -.
|
|
13
|
+
NAME=$(gcloud config get-value account | cut -d'@' -f1 | sed 's/\./-/g')
|
|
14
|
+
SERVICE_ACCOUNT_NAME="$NAME-py"
|
|
15
|
+
|
|
16
|
+
echo "GCP Service Account Name: $SERVICE_ACCOUNT_NAME"
|
|
17
|
+
echo ""
|
|
18
|
+
|
|
19
|
+
# Fetch or create service account
|
|
20
|
+
SERVICE_ACCOUNTS=$(gcloud iam service-accounts list --format="value(email)" --filter="email:$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com" 2>/dev/null)
|
|
21
|
+
|
|
22
|
+
# If service account does not exist, create it
|
|
23
|
+
if [ -z "$SERVICE_ACCOUNTS" ]; then
|
|
24
|
+
gcloud iam service-accounts create $SERVICE_ACCOUNT_NAME --display-name "$SERVICE_ACCOUNT_NAME"
|
|
25
|
+
echo "Service Account Created: $SERVICE_ACCOUNT_NAME"
|
|
26
|
+
echo ""
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
# Enable service account
|
|
30
|
+
gcloud iam service-accounts enable $SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com
|
|
31
|
+
echo "Service Account Enabled: $SERVICE_ACCOUNT_NAME"
|
|
32
|
+
echo ""
|
|
33
|
+
|
|
34
|
+
# Permission key against the leverege-python-packages artifact registry repository
|
|
35
|
+
gcloud artifacts repositories add-iam-policy-binding leverege-python-packages \
|
|
36
|
+
--location=$GCP_LOCATION \
|
|
37
|
+
--member="serviceAccount:$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com" \
|
|
38
|
+
--role="organizations/$GCP_ORGANIZATION_ID/roles/leveregeRegistryAccess" >/dev/null
|
|
39
|
+
echo "Service Account Permission Granted: $SERVICE_ACCOUNT_NAME"
|
|
40
|
+
echo ""
|
|
41
|
+
|
|
42
|
+
# List service account keys
|
|
43
|
+
SERVICE_ACCOUNT_KEYS=$(gcloud iam service-accounts keys list --iam-account=$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com --format="value(name)")
|
|
44
|
+
|
|
45
|
+
# If service account keys exist, delete them
|
|
46
|
+
if [ ! -z "$SERVICE_ACCOUNT_KEYS" ]; then
|
|
47
|
+
for key in $SERVICE_ACCOUNT_KEYS; do
|
|
48
|
+
echo ""
|
|
49
|
+
gcloud iam service-accounts keys delete $key --iam-account=$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com --quiet
|
|
50
|
+
echo "Service Account Key Deleted: $key"
|
|
51
|
+
done
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
echo ""
|
|
55
|
+
|
|
56
|
+
SERVICE_ACCOUNT_KEY_PATH=$HOME/.config/gcloud/$SERVICE_ACCOUNT_NAME.json
|
|
57
|
+
|
|
58
|
+
# Silence the command
|
|
59
|
+
gcloud iam service-accounts keys create $SERVICE_ACCOUNT_KEY_PATH --iam-account=$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com
|
|
60
|
+
echo "Service Account Key Created and Saved: $SERVICE_ACCOUNT_KEY_PATH"
|
|
61
|
+
echo ""
|
|
62
|
+
|
|
63
|
+
# Encode key to base64
|
|
64
|
+
ENCODED_KEY=$(base64 -i $SERVICE_ACCOUNT_KEY_PATH -o -)
|
|
65
|
+
|
|
66
|
+
# Write to pip.conf
|
|
67
|
+
mkdir -p $HOME/.config/pip
|
|
68
|
+
cat <<EOF > $HOME/.config/pip/pip.conf
|
|
69
|
+
[global]
|
|
70
|
+
extra-index-url = https://_json_key_base64:$ENCODED_KEY@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple/
|
|
71
|
+
EOF
|
|
72
|
+
echo "Updated $HOME/.config/pip/pip.conf"
|
|
73
|
+
|
|
74
|
+
# Write to pypirc
|
|
75
|
+
cat <<EOF > $HOME/.pypirc
|
|
76
|
+
[distutils]
|
|
77
|
+
index-servers =
|
|
78
|
+
leverege-python-packages
|
|
79
|
+
|
|
80
|
+
[leverege-python-packages]
|
|
81
|
+
repository: https://us-python.pkg.dev/leverege-registry/leverege-python-packages/
|
|
82
|
+
username: _json_key_base64
|
|
83
|
+
password: $ENCODED_KEY
|
|
84
|
+
EOF
|
|
85
|
+
echo "Updated $HOME/.pypirc"
|
|
86
|
+
|
|
87
|
+
# Set UV_EXTRA_INDEX_URL env var
|
|
88
|
+
export UV_EXTRA_INDEX_URL="https://_json_key_base64:$ENCODED_KEY@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple"
|
|
89
|
+
echo "Updated UV_EXTRA_INDEX_URL"
|
package/src/refresh-py-idx.sh
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
# Description: Refresh service account key using gcloud cli
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# SERVICE_ACCOUNT_NAME="leverege-py-index"
|
|
4
|
+
# GCP_PROJECT_ID="leverege-registry"
|
|
5
|
+
|
|
6
|
+
# TOKEN=$(gcloud auth print-access-token --impersonate-service-account $SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com --lifetime=12h)
|
|
4
7
|
TOKEN=$(gcloud auth print-access-token)
|
|
5
8
|
|
|
6
9
|
# Write to pip.conf
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
PIP_CONFIG_CONTENT="
|
|
10
|
+
mkdir -p $HOME/.config/pip
|
|
11
|
+
cat <<EOF > $HOME/.config/pip/pip.conf
|
|
10
12
|
[global]
|
|
11
|
-
extra-index-url = https://oauth2accesstoken:$
|
|
12
|
-
|
|
13
|
-
echo "
|
|
14
|
-
echo "Updated ~/.config/pip/pip.conf"
|
|
13
|
+
extra-index-url = https://oauth2accesstoken:$TOKEN@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple/
|
|
14
|
+
EOF
|
|
15
|
+
echo "Updated $HOME/.config/pip/pip.conf"
|
|
15
16
|
|
|
16
17
|
# Write to pypirc
|
|
17
|
-
|
|
18
|
+
cat <<EOF > $HOME/.pypirc
|
|
18
19
|
[distutils]
|
|
19
20
|
index-servers =
|
|
20
21
|
leverege-python-packages
|
|
@@ -22,97 +23,10 @@ index-servers =
|
|
|
22
23
|
[leverege-python-packages]
|
|
23
24
|
repository: https://us-python.pkg.dev/leverege-registry/leverege-python-packages/
|
|
24
25
|
username: oauth2accesstoken
|
|
25
|
-
password: $
|
|
26
|
-
|
|
27
|
-
echo "
|
|
28
|
-
echo "Updated ~/.pypirc"
|
|
29
|
-
|
|
30
|
-
# Escape for sed
|
|
31
|
-
UV_EXTRA_INDEX_URL="https://foo:${TOKEN}@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple"
|
|
32
|
-
|
|
33
|
-
SHELLS=("bash" "dash" "zsh" "fish")
|
|
34
|
-
|
|
35
|
-
for shell in "${SHELLS[@]}"; do
|
|
36
|
-
if command -v "$shell" > /dev/null 2>&1; then
|
|
37
|
-
case "$shell" in
|
|
38
|
-
bash)
|
|
39
|
-
CONFIG_FILE="$HOME/.bashrc"
|
|
40
|
-
;;
|
|
41
|
-
dash)
|
|
42
|
-
CONFIG_FILE="$HOME/.profile"
|
|
43
|
-
;;
|
|
44
|
-
zsh)
|
|
45
|
-
CONFIG_FILE="$HOME/.zshrc"
|
|
46
|
-
;;
|
|
47
|
-
fish)
|
|
48
|
-
CONFIG_FILE="$HOME/.config/fish/config.fish"
|
|
49
|
-
;;
|
|
50
|
-
*)
|
|
51
|
-
echo "Shell $shell is not supported."
|
|
52
|
-
continue
|
|
53
|
-
;;
|
|
54
|
-
esac
|
|
55
|
-
|
|
56
|
-
echo "Updating shell configuration in $CONFIG_FILE"
|
|
57
|
-
|
|
58
|
-
if [ -f "$CONFIG_FILE" ]; then
|
|
59
|
-
if grep -q "export UV_EXTRA_INDEX_URL=" "$CONFIG_FILE"; then
|
|
60
|
-
sed -i "s|export UV_EXTRA_INDEX_URL=.*|export UV_EXTRA_INDEX_URL=${UV_EXTRA_INDEX_URL}|" "$CONFIG_FILE"
|
|
61
|
-
else
|
|
62
|
-
echo -e "\nexport UV_EXTRA_INDEX_URL=${UV_EXTRA_INDEX_URL}\n" >> "$CONFIG_FILE"
|
|
63
|
-
fi
|
|
64
|
-
else
|
|
65
|
-
echo -e "\nexport UV_EXTRA_INDEX_URL=${UV_EXTRA_INDEX_URL}\n" >> "$CONFIG_FILE"
|
|
66
|
-
fi
|
|
67
|
-
else
|
|
68
|
-
echo "Shell $shell is not installed."
|
|
69
|
-
fi
|
|
70
|
-
done
|
|
71
|
-
|
|
72
|
-
function get_parent_shell() {
|
|
73
|
-
local ppid=$(ps -p $$ -o ppid= | tr -d ' ')
|
|
74
|
-
local shell=$(ps -p $ppid -o comm= | tr -d ' ')
|
|
75
|
-
|
|
76
|
-
while [ "$ppid" != "1" ]; do
|
|
77
|
-
ppid=$(ps -p $ppid -o ppid= | tr -d ' ')
|
|
78
|
-
shell=$(ps -p $ppid -o comm= | tr -d ' ')
|
|
79
|
-
|
|
80
|
-
if [[ "$shell" =~ bash|dash|zsh|fish ]]; then
|
|
81
|
-
echo "$shell"
|
|
82
|
-
return
|
|
83
|
-
fi
|
|
84
|
-
done
|
|
85
|
-
|
|
86
|
-
echo ""
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
shell=$(get_parent_shell)
|
|
90
|
-
|
|
91
|
-
if [ -z "$shell" ]; then
|
|
92
|
-
echo -e "\nCould not determine parent shell. Please source your shell configuration to apply the changes.\n"
|
|
93
|
-
echo "Example (bash): source ~/.bashrc"
|
|
94
|
-
echo "Example (dash): source ~/.profile"
|
|
95
|
-
echo "Example (zsh): source ~/.zshrc"
|
|
96
|
-
echo "Example (fish): source ~/.config/fish/config.fish"
|
|
97
|
-
exit 1
|
|
98
|
-
fi
|
|
99
|
-
|
|
100
|
-
echo -e "\nReloading $shell shell with new configuration.\n"
|
|
26
|
+
password: $TOKEN
|
|
27
|
+
EOF
|
|
28
|
+
echo "Updated $HOME/.pypirc"
|
|
101
29
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
;;
|
|
106
|
-
dash)
|
|
107
|
-
source "$HOME/.profile"
|
|
108
|
-
;;
|
|
109
|
-
zsh)
|
|
110
|
-
source "$HOME/.zshrc"
|
|
111
|
-
;;
|
|
112
|
-
fish)
|
|
113
|
-
source "$HOME/.config/fish/config.fish"
|
|
114
|
-
;;
|
|
115
|
-
*)
|
|
116
|
-
echo "Shell $shell is not supported."
|
|
117
|
-
;;
|
|
118
|
-
esac
|
|
30
|
+
# Set UV_EXTRA_INDEX_URL env var
|
|
31
|
+
export UV_EXTRA_INDEX_URL="https://oauth2accesstoken:$TOKEN@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple"
|
|
32
|
+
echo "Updated UV_EXTRA_INDEX_URL"
|