@leverege/build-tools 2.52.0-pedro.7 → 2.52.0-pedro.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.52.0-pedro.7",
3
+ "version": "2.52.0-pedro.8",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable max-len */
3
+ /* eslint-disable security/detect-non-literal-fs-filename */
4
+ /* eslint-disable no-console */
5
+
6
+ import { execSync } from 'child_process';
7
+ import fs from 'fs';
8
+ import os from 'os';
9
+ import path from 'path';
10
+
11
+ // Execute gcloud command to get the token
12
+ const TOKEN = execSync( 'gcloud auth print-access-token' ).toString().trim();
13
+
14
+ // Write to pip.conf
15
+ const pipConfigDir = path.join( os.homedir(), '.config', 'pip' );
16
+ fs.mkdirSync( pipConfigDir, { recursive : true } );
17
+ const pipConfigContent = `
18
+ [global]
19
+ extra-index-url = https://oauth2accesstoken:${TOKEN}@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple/
20
+ `;
21
+ fs.writeFileSync( path.join( pipConfigDir, 'pip.conf' ), pipConfigContent );
22
+ console.log( 'Updated ~/.config/pip/pip.conf' );
23
+
24
+ // Write to pypirc
25
+ const pypircContent = `
26
+ [distutils]
27
+ index-servers =
28
+ leverege-python-packages
29
+
30
+ [leverege-python-packages]
31
+ repository: https://us-python.pkg.dev/leverege-registry/leverege-python-packages/
32
+ username: oauth2accesstoken
33
+ password: ${TOKEN}
34
+ `;
35
+ fs.writeFileSync( path.join( os.homedir(), '.pypirc' ), pypircContent );
36
+ console.log( 'Updated ~/.pypirc\n' );
37
+
38
+ // Escape for sed
39
+
40
+ const UV_EXTRA_INDEX_URL = `https://foo:${TOKEN}@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple`;
41
+
42
+ const SHELLS = [ 'bash', 'dash', 'zsh', 'fish' ];
43
+
44
+ SHELLS.forEach( ( shell ) => {
45
+ try {
46
+ execSync( `command -v ${shell}` );
47
+ let configFile;
48
+ switch ( shell ) {
49
+ case 'bash':
50
+ configFile = path.join( os.homedir(), '.bashrc' );
51
+ break;
52
+ case 'dash':
53
+ configFile = path.join( os.homedir(), '.profile' );
54
+ break;
55
+ case 'zsh':
56
+ configFile = path.join( os.homedir(), '.zshrc' );
57
+ break;
58
+ case 'fish':
59
+ configFile = path.join( os.homedir(), '.config', 'fish', 'config.fish' );
60
+ break;
61
+ default:
62
+ console.log( `Shell ${shell} is not supported.` );
63
+ return;
64
+ }
65
+
66
+ console.log( `Updating shell configuration in ${configFile}` );
67
+
68
+ let configContent = fs.readFileSync( configFile, 'utf8' );
69
+ const regex = /export UV_EXTRA_INDEX_URL=.*/;
70
+ const newLine = `export UV_EXTRA_INDEX_URL=${UV_EXTRA_INDEX_URL}`;
71
+
72
+ if ( regex.test( configContent ) ) {
73
+ configContent = configContent.replace( regex, newLine );
74
+ } else {
75
+ configContent += `\n${newLine}\n`;
76
+ }
77
+
78
+ fs.writeFileSync( configFile, configContent );
79
+ } catch ( error ) {
80
+ console.log( `Shell ${shell} is not installed.` );
81
+ }
82
+ } );
83
+
84
+ function getParentShell() {
85
+ let ppid = execSync( 'ps -p $$ -o ppid=' ).toString().trim();
86
+ let shell = execSync( `ps -p ${ppid} -o comm=` ).toString().trim();
87
+
88
+ while ( ppid !== '1' ) {
89
+ ppid = execSync( `ps -p ${ppid} -o ppid=` ).toString().trim();
90
+ shell = execSync( `ps -p ${ppid} -o comm=` ).toString().trim();
91
+
92
+ const shellMatch = shell.match( /bash|dash|zsh|fish/ );
93
+ if ( shellMatch ) {
94
+ return shellMatch[0];
95
+ }
96
+ }
97
+
98
+ return null
99
+ }
100
+
101
+ const shell = getParentShell();
102
+
103
+ if ( !shell ) {
104
+ console.log( '\nCould not determine parent shell. Please source your shell configuration to apply the changes.\n' );
105
+ console.log( 'Example (bash): source ~/.bashrc' );
106
+ console.log( 'Example (dash): source ~/.profile' );
107
+ console.log( 'Example (zsh): source ~/.zshrc' );
108
+ console.log( 'Example (fish): source ~/.config/fish/config.fish' );
109
+ process.exit( 1 );
110
+ }
111
+
112
+ console.log( `\nSourcing shell configuration for ${shell}` );
113
+
114
+ switch ( shell ) {
115
+ case 'bash':
116
+ case 'dash':
117
+ case 'zsh':
118
+ case 'fish':
119
+ execSync( shell, { stdio : 'inherit' } );
120
+ console.log( `Sourced shell configuration for ${shell}` );
121
+ break;
122
+ default:
123
+ console.log( `Shell ${shell} is not supported.` );
124
+ }
@@ -1,143 +0,0 @@
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
- echo $ENCODED_KEY
67
-
68
- # Write to pip.conf
69
- mkdir -p $HOME/.config/pip
70
- cat <<EOF > $HOME/.config/pip/pip.conf
71
- [global]
72
- extra-index-url = https://_json_key_base64:$ENCODED_KEY@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple/
73
- EOF
74
- echo "Updated $HOME/.config/pip/pip.conf"
75
-
76
- # Write to pypirc
77
- cat <<EOF > $HOME/.pypirc
78
- [distutils]
79
- index-servers =
80
- leverege-python-packages
81
-
82
- [leverege-python-packages]
83
- repository: https://us-python.pkg.dev/leverege-registry/leverege-python-packages/
84
- username: _json_key_base64
85
- password: $ENCODED_KEY
86
- EOF
87
- echo "Updated $HOME/.pypirc"
88
-
89
- escape_for_sed() {
90
- printf '%s\n' "$1" | sed -e 's/[\/&]/\\&/g'
91
- }
92
-
93
- UV_EXTRA_INDEX_URL="https://_json_key_base64:$ENCODED_KEY@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple"
94
- UV_EXTRA_INDEX_URL_E=$(escape_for_sed "$UV_EXTRA_INDEX_URL")
95
-
96
- SHELLS=("bash" "dash" "zsh" "fish")
97
-
98
- for SHELL in "${SHELLS[@]}"; do
99
- if command -v "$SHELL" >/dev/null 2>&1; then
100
- case "$SHELL" in
101
- bash)
102
- config_file="${HOME}/.bashrc"
103
- ;;
104
- dash)
105
- config_file="${HOME}/.profile"
106
- ;;
107
- zsh)
108
- config_file="${HOME}/.zshrc"
109
- ;;
110
- fish)
111
- config_file="${HOME}/.config/fish/config.fish"
112
- ;;
113
- *)
114
- echo "Shell $SHELL is not supported."
115
- continue
116
- ;;
117
- esac
118
-
119
- echo "Updating shell configuration in $config_file"
120
-
121
- if grep -q "UV_EXTRA_INDEX_URL" "$config_file"; then
122
- if [ "$SHELL" = "fish" ]; then
123
- sed -i '' "s|set -x UV_EXTRA_INDEX_URL .*|set -x UV_EXTRA_INDEX_URL $UV_EXTRA_INDEX_URL_E|" "$config_file"
124
- else
125
- sed -i '' "s|export UV_EXTRA_INDEX_URL=.*|export UV_EXTRA_INDEX_URL=$UV_EXTRA_INDEX_URL_E|" "$config_file"
126
- fi
127
- else
128
- if [ "$SHELL" = "fish" ]; then
129
- echo "set -x UV_EXTRA_INDEX_URL $UV_EXTRA_INDEX_URL" >> "$config_file"
130
- else
131
- echo "export UV_EXTRA_INDEX_URL=$UV_EXTRA_INDEX_URL" >> "$config_file"
132
- fi
133
- fi
134
- fi
135
- done
136
-
137
- echo ""
138
- echo "Please source your shell configuration to apply the changes."
139
- echo "Example (bash): source ~/.bashrc"
140
- echo "Example (dash): source ~/.profile"
141
- echo "Example (zsh): source ~/.zshrc"
142
- echo "Example (fish): source ~/.config/fish/config.fish"
143
- echo ""
@@ -1,102 +0,0 @@
1
- # Description: Refresh service account key using gcloud cli
2
-
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)
7
- TOKEN=$(gcloud auth print-access-token)
8
-
9
- # Write to pip.conf
10
- mkdir -p $HOME/.config/pip
11
- cat <<EOF > $HOME/.config/pip/pip.conf
12
- [global]
13
- extra-index-url = https://oauth2accesstoken:$TOKEN@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple/
14
- EOF
15
- echo "Updated ~/.config/pip/pip.conf"
16
-
17
- # Write to pypirc
18
- cat <<EOF > $HOME/.pypirc
19
- [distutils]
20
- index-servers =
21
- leverege-python-packages
22
-
23
- [leverege-python-packages]
24
- repository: https://us-python.pkg.dev/leverege-registry/leverege-python-packages/
25
- username: oauth2accesstoken
26
- password: $TOKEN
27
- EOF
28
- echo "Updated ~/.pypirc"
29
-
30
- escape_for_sed() {
31
- printf '%s\n' "$1" | sed -e 's/[\/&]/\\&/g'
32
- }
33
-
34
- UV_EXTRA_INDEX_URL="https://oauth2accesstoken:$TOKEN@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple"
35
- UV_EXTRA_INDEX_URL_E=$(escape_for_sed "$UV_EXTRA_INDEX_URL")
36
-
37
- SHELLS=("bash" "dash" "zsh" "fish")
38
-
39
- for SHELL in "${SHELLS[@]}"; do
40
- if command -v "$SHELL" >/dev/null 2>&1; then
41
- case "$SHELL" in
42
- bash)
43
- config_file="${HOME}/.bashrc"
44
- ;;
45
- dash)
46
- config_file="${HOME}/.profile"
47
- ;;
48
- zsh)
49
- config_file="${HOME}/.zshrc"
50
- ;;
51
- fish)
52
- config_file="${HOME}/.config/fish/config.fish"
53
- ;;
54
- *)
55
- echo "Shell $SHELL is not supported."
56
- continue
57
- ;;
58
- esac
59
-
60
- echo "Updating shell configuration in $config_file"
61
-
62
- if grep -q "UV_EXTRA_INDEX_URL" "$config_file"; then
63
- if [ "$SHELL" = "fish" ]; then
64
- sed -i '' "s|set -x UV_EXTRA_INDEX_URL .*|set -x UV_EXTRA_INDEX_URL $UV_EXTRA_INDEX_URL_E|" "$config_file"
65
- else
66
- sed -i '' "s|export UV_EXTRA_INDEX_URL=.*|export UV_EXTRA_INDEX_URL=$UV_EXTRA_INDEX_URL_E|" "$config_file"
67
- fi
68
- else
69
- if [ "$SHELL" = "fish" ]; then
70
- echo "set -x UV_EXTRA_INDEX_URL $UV_EXTRA_INDEX_URL" >> "$config_file"
71
- else
72
- echo "export UV_EXTRA_INDEX_URL=$UV_EXTRA_INDEX_URL" >> "$config_file"
73
- fi
74
- fi
75
- fi
76
- done
77
-
78
- # If $FISH_VERSION is set, then the user is using fish shell
79
- if [ -n "$FISH_VERSION" ]; then
80
- fish
81
- else
82
- # Use the shell name to source the configuration.
83
- SHELL_NAME=$(ps -p $$ -o comm=)
84
- case "$SHELL_NAME" in
85
- bash)
86
- source ~/.bashrc
87
- ;;
88
- dash)
89
- source ~/.profile
90
- ;;
91
- zsh)
92
- source ~/.zshrc
93
- ;;
94
- fish)
95
- source ~/.config/fish/config.fish
96
- ;;
97
- *)
98
- echo "Shell $SHELL_NAME is not supported."
99
- ;;
100
- esac
101
- fi
102
-