Skip to content

Commit

Permalink
chore: use Cloud SQL Proxy v2 in READMEs
Browse files Browse the repository at this point in the history
Also remove references to service account keys in favor of application
default credentials.

Related to GoogleCloudPlatform/nodejs-docs-samples#3635
  • Loading branch information
enocom committed Apr 15, 2024
1 parent 127dc2c commit 7b1928c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
21 changes: 10 additions & 11 deletions cloudsql/mysql/database-sql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Note the connection string, database user, and database password that you create
[instructions](https://cloud.google.com/sql/docs/mysql/create-manage-databases).
Note the database name.

1. Create a service account with the 'Cloud SQL Client' permissions by following these
[instructions](https://cloud.google.com/sql/docs/mysql/connect-external-app#4_if_required_by_your_authentication_method_create_a_service_account).
Download a JSON key to use to authenticate your connection.
1. Set up [Application Default Credentials][adc]

[adc]: https://cloud.google.com/docs/authentication/provide-credentials-adc

## Running locally

Expand All @@ -34,7 +34,6 @@ To run the sample locally with a TCP connection, set environment variables and l
#### Linux / Mac OS
Use these terminal commands to initialize environment variables:
```bash
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account/key.json
export INSTANCE_HOST='127.0.0.1'
export DB_PORT='3306'
export DB_USER='<DB_USER_NAME>'
Expand All @@ -44,13 +43,12 @@ export DB_NAME='<DB_NAME>'

Then use this command to launch the proxy in the background:
```bash
./cloud_sql_proxy -instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:3306 -credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
./cloud-sql-proxy <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=3306 &
```

#### Windows/PowerShell
Use these PowerShell commands to initialize environment variables:
```powershell
$env:GOOGLE_APPLICATION_CREDENTIALS="<CREDENTIALS_JSON_FILE>"
$env:INSTANCE_HOST="127.0.0.1"
$env:DB_PORT="3306"
$env:DB_USER="<YOUR_DB_USER_NAME>"
Expand All @@ -60,7 +58,7 @@ $env:DB_NAME="<YOUR_DB_NAME>"

Then use this command to launch the proxy in a separate PowerShell session:
```powershell
Start-Process -filepath "C:\<path to proxy exe>" -ArgumentList "-instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:3306 -credential_file=<CREDENTIALS_JSON_FILE>"
Start-Process -filepath "C:\<path to proxy exe>" -ArgumentList "<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=3306"
```

### Launch proxy with Unix Domain Socket
Expand All @@ -74,7 +72,6 @@ sudo chown -R $USER ./cloudsql

Use these terminal commands to initialize environment variables:
```bash
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account/key.json
export INSTANCE_UNIX_SOCKET='./cloudsql/<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>'
export DB_USER='<YOUR_DB_USER_NAME>'
export DB_PASS='<YOUR_DB_PASSWORD>'
Expand All @@ -83,7 +80,8 @@ export DB_NAME='<YOUR_DB_NAME>'

Then use this command to launch the proxy in the background:
```bash
./cloud_sql_proxy -dir=./cloudsql --instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
./cloud-sql-proxy --unix-socket=./cloudsql \
<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> &
```

### Testing the application
Expand Down Expand Up @@ -236,8 +234,9 @@ the Cloud SQL Auth Proxy, one for a TCP connection and one for a Unix socket
connection.

```
cloud_sql_proxy -instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:3306
cloud_sql_proxy -instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> -dir /cloudsql
cloud-sql-proxy <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=3306
cloud-sql-proxy <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> \
--unix-socket=/cloudsql
```

To run integration tests, use the following command, setting environment
Expand Down
15 changes: 6 additions & 9 deletions cloudsql/postgres/database-sql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ This repo contains the Go source code for a simple web app that can be deployed
[instructions](https://cloud.google.com/sql/docs/postgres/create-manage-databases).
Note the database name.

1. Create a service account with the 'Cloud SQL Client' permissions by following these
[instructions](https://cloud.google.com/sql/docs/mysql/connect-external-app#4_if_required_by_your_authentication_method_create_a_service_account).
Download a JSON key to use to authenticate your connection.
1. Set up [Application Default Credentials][adc]

[adc]: https://cloud.google.com/docs/authentication/provide-credentials-adc

## Running locally

Expand All @@ -36,7 +36,6 @@ To run the sample locally with a TCP connection, set environment variables and l
Use these terminal commands to initialize environment variables:

```bash
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account/key.json
export INSTANCE_HOST='127.0.0.1'
export DB_PORT='5432'
export DB_USER='<YOUR_DB_USER_NAME>'
Expand All @@ -47,15 +46,14 @@ export DB_NAME='<YOUR_DB_NAME>'
Then use this command to launch the proxy in the background:

```bash
./cloud_sql_proxy -instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:5432 -credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
./cloud-sql-proxy <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=5432 &
```

#### Windows/PowerShell

Use these PowerShell commands to initialize environment variables:

```powershell
$env:GOOGLE_APPLICATION_CREDENTIALS="<CREDENTIALS_JSON_FILE>"
$env:INSTANCE_HOST="127.0.0.1"
$env:DB_PORT="5432"
$env:DB_USER="<YOUR_DB_USER_NAME>"
Expand All @@ -66,7 +64,7 @@ $env:DB_NAME="<YOUR_DB_NAME>"
Then use this command to launch the proxy in a separate PowerShell session:

```powershell
Start-Process -filepath "C:\<path to proxy exe>" -ArgumentList "-instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:5432 -credential_file=<CREDENTIALS_JSON_FILE>"
Start-Process -filepath "C:\<path to proxy exe>" -ArgumentList "<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=5432"
```

### Launch proxy with Unix Domain Socket
Expand All @@ -83,7 +81,6 @@ sudo chown -R $USER ./cloudsql
Use these terminal commands to initialize environment variables:

```bash
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account/key.json
export INSTANCE_UNIX_SOCKET='./cloudsql/<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>'
export DB_USER='<YOUR_DB_USER_NAME>'
export DB_PASS='<YOUR_DB_PASSWORD>'
Expand All @@ -93,7 +90,7 @@ export DB_NAME='<YOUR_DB_NAME>'
Then use this command to launch the proxy in the background:

```bash
./cloud_sql_proxy -dir=./cloudsql --instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
./cloud-sql-proxy --unix-socket=./cloudsql <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> &
```

### Testing the application
Expand Down
12 changes: 5 additions & 7 deletions cloudsql/sqlserver/database-sql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Note the connection string, database user, and database password that you create
[instructions](https://cloud.google.com/sql/docs/sqlserver/create-manage-databases).
Note the database name.

1. Create a service account with the 'Cloud SQL Client' permissions by following these
[instructions](https://cloud.google.com/sql/docs/mysql/connect-external-app#4_if_required_by_your_authentication_method_create_a_service_account).
Download a JSON key to use to authenticate your connection.
1. Set up [Application Default Credentials][adc]

[adc]: https://cloud.google.com/docs/authentication/provide-credentials-adc

## Running locally

Expand All @@ -34,7 +34,6 @@ To run the sample locally with a TCP connection, set environment variables and l
#### Linux / Mac OS
Use these terminal commands to initialize environment variables:
```bash
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account/key.json
export INSTANCE_HOST='127.0.0.1'
export DB_PORT='1433'
export DB_USER='<YOUR_DB_USER_NAME>'
Expand All @@ -44,13 +43,12 @@ export DB_NAME='<YOUR_DB_NAME>'

Then use this command to launch the proxy in the background:
```bash
./cloud_sql_proxy -instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:1433 -credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
./cloud-sql-proxy <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=1433 &
```

#### Windows/PowerShell
Use these PowerShell commands to initialize environment variables:
```powershell
$env:GOOGLE_APPLICATION_CREDENTIALS="<CREDENTIALS_JSON_FILE>"
$env:INSTANCE_HOST="127.0.0.1"
$env:DB_PORT="1433"
$env:DB_USER="<YOUR_DB_USER_NAME>"
Expand All @@ -60,7 +58,7 @@ $env:DB_NAME="<YOUR_DB_NAME>"

Then use this command to launch the proxy in a separate PowerShell session:
```powershell
Start-Process -filepath "C:\<path to proxy exe>" -ArgumentList "-instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:1433 -credential_file=<CREDENTIALS_JSON_FILE>"
Start-Process -filepath "C:\<path to proxy exe>" -ArgumentList "<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=1433"
```

### Testing the application
Expand Down

0 comments on commit 7b1928c

Please sign in to comment.