@leverege/build-tools 2.52.0-pedro.10 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.52.0-pedro.10",
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,7 +47,8 @@
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": "src/refresh-py-idx.mjs",
50
+ "refresh-py-idx-sa": "src/refresh-py-idx-sa.sh",
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",
53
54
  "unleash": "src/unleash.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"
@@ -0,0 +1,32 @@
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 $HOME/.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 $HOME/.pypirc"
29
+
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"
@@ -1,123 +0,0 @@
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( `\nReloading ${shell} shell with new configuration.\n` );
113
-
114
- switch ( shell ) {
115
- case 'bash':
116
- case 'dash':
117
- case 'zsh':
118
- case 'fish':
119
- execSync( shell, { stdio : 'inherit' } );
120
- break;
121
- default:
122
- console.log( `Shell ${shell} is not supported.\n` );
123
- }