Skip to content

Commit 7c3a611

Browse files
chore: rename CLOUD_SQL_CONNECTION_NAME to INSTANCE_CONNECTION_NAME (GoogleCloudPlatform#6897)
Co-authored-by: Charles Engelke <engelke@google.com>
1 parent 3cfcb0e commit 7c3a611

22 files changed

+52
-52
lines changed

cloud-sql/mysql/client-side-encryption/snippets/cloud_sql_connection_pool.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def init_unix_connection_engine(
4747
db_user: str,
4848
db_pass: str,
4949
db_name: str,
50-
cloud_sql_connection_name: str,
50+
instance_connection_name: str,
5151
db_socket_dir: str,
5252
) -> sqlalchemy.engine.base.Engine:
5353
# Remember - storing secrets in plaintext is potentially unsafe. Consider using
@@ -62,7 +62,7 @@ def init_unix_connection_engine(
6262
username=db_user, # e.g. "my-database-user"
6363
password=db_pass, # e.g. "my-database-password"
6464
database=db_name, # e.g. "my-database-name"
65-
query={"unix_socket": f"{db_socket_dir}/{cloud_sql_connection_name}"},
65+
query={"unix_socket": f"{db_socket_dir}/{instance_connection_name}"},
6666
),
6767
)
6868
print("Created Unix socket connection pool")
@@ -74,7 +74,7 @@ def init_db(
7474
db_pass: str,
7575
db_name: str,
7676
table_name: str,
77-
cloud_sql_connection_name: str = None,
77+
instance_connection_name: str = None,
7878
db_socket_dir: str = None,
7979
db_host: str = None,
8080
) -> sqlalchemy.engine.base.Engine:
@@ -83,7 +83,7 @@ def init_db(
8383
db = init_tcp_connection_engine(db_user, db_pass, db_name, db_host)
8484
else:
8585
db = init_unix_connection_engine(
86-
db_user, db_pass, db_name, cloud_sql_connection_name, db_socket_dir
86+
db_user, db_pass, db_name, instance_connection_name, db_socket_dir
8787
)
8888

8989
# Create tables (if they don't already exist)

cloud-sql/mysql/client-side-encryption/snippets/cloud_sql_connection_pool_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_init_unix_connection_engine(
8282
db_user=conn_vars["db_user"],
8383
db_name=conn_vars["db_name"],
8484
db_pass=conn_vars["db_pass"],
85-
cloud_sql_connection_name=conn_vars["instance_conn_name"],
85+
instance_connection_name=conn_vars["instance_conn_name"],
8686
db_socket_dir=conn_vars["db_socket_dir"],
8787
)
8888

cloud-sql/mysql/client-side-encryption/snippets/encrypt_and_insert_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def main() -> None:
3838
# Set if connecting using Unix sockets:
3939
db_socket_dir = os.environ.get("DB_SOCKET_DIR", "/cloudsql")
4040

41-
cloud_sql_connection_name = os.environ["CLOUD_SQL_CONNECTION_NAME"]
41+
instance_connection_name = os.environ["INSTANCE_CONNECTION_NAME"]
4242
# e.g. "project-name:region:instance-name"
4343

4444
credentials = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", "")
@@ -58,7 +58,7 @@ def main() -> None:
5858
db_pass,
5959
db_name,
6060
table_name,
61-
cloud_sql_connection_name,
61+
instance_connection_name,
6262
db_socket_dir,
6363
db_host,
6464
)

cloud-sql/mysql/client-side-encryption/snippets/query_and_decrypt_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def main() -> None:
3434
# Set if connecting using Unix sockets:
3535
db_socket_dir = os.environ.get("DB_SOCKET_DIR", "/cloudsql")
3636

37-
cloud_sql_connection_name = os.environ["CLOUD_SQL_CONNECTION_NAME"]
37+
instance_connection_name = os.environ["INSTANCE_CONNECTION_NAME"]
3838
# e.g. "project-name:region:instance-name"
3939

4040
credentials = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", "")
@@ -54,7 +54,7 @@ def main() -> None:
5454
db_pass,
5555
db_name,
5656
table_name,
57-
cloud_sql_connection_name,
57+
instance_connection_name,
5858
db_socket_dir,
5959
db_host,
6060
)

cloud-sql/mysql/sqlalchemy/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export DB_SOCKET_DIR=/path/to/the/new/directory
8888
Use these terminal commands to initialize other environment variables as well:
8989
```bash
9090
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account/key.json
91-
export CLOUD_SQL_CONNECTION_NAME='<MY-PROJECT>:<INSTANCE-REGION>:<INSTANCE-NAME>'
91+
export INSTANCE_CONNECTION_NAME='<MY-PROJECT>:<INSTANCE-REGION>:<INSTANCE-NAME>'
9292
export DB_USER='<DB_USER_NAME>'
9393
export DB_PASS='<DB_PASSWORD>'
9494
export DB_NAME='<DB_NAME>'
@@ -99,7 +99,7 @@ help keep secrets safe.
9999

100100
Then use this command to launch the proxy in the background:
101101
```bash
102-
./cloud_sql_proxy -dir=$DB_SOCKET_DIR --instances=$CLOUD_SQL_CONNECTION_NAME --credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
102+
./cloud_sql_proxy -dir=$DB_SOCKET_DIR --instances=$INSTANCE_CONNECTION_NAME --credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
103103
```
104104

105105
### Testing the application
@@ -168,8 +168,8 @@ Take note of the URL output at the end of the deployment process.
168168

169169
```sh
170170
gcloud run services update run-mysql \
171-
--add-cloudsql-instances [CLOUD_SQL_CONNECTION_NAME] \
172-
--set-env-vars CLOUD_SQL_CONNECTION_NAME=[CLOUD_SQL_CONNECTION_NAME],\
171+
--add-cloudsql-instances [INSTANCE_CONNECTION_NAME] \
172+
--set-env-vars INSTANCE_CONNECTION_NAME=[INSTANCE_CONNECTION_NAME],\
173173
DB_USER=[MY_DB_USER],DB_PASS=[MY_DB_PASS],DB_NAME=[MY_DB]
174174
```
175175
Replace environment variables with the correct values for your Cloud SQL
@@ -183,15 +183,15 @@ Secret Manager at runtime via an environment variable.
183183

184184
Create secrets via the command line:
185185
```sh
186-
echo -n $CLOUD_SQL_CONNECTION_NAME | \
187-
gcloud secrets create [CLOUD_SQL_CONNECTION_NAME_SECRET] --data-file=-
186+
echo -n $INSTANCE_CONNECTION_NAME | \
187+
gcloud secrets create [INSTANCE_CONNECTION_NAME_SECRET] --data-file=-
188188
```
189189

190190
Deploy the service to Cloud Run specifying the env var name and secret name:
191191
```sh
192192
gcloud beta run deploy SERVICE --image gcr.io/[YOUR_PROJECT_ID]/run-sql \
193-
--add-cloudsql-instances $CLOUD_SQL_CONNECTION_NAME \
194-
--update-secrets CLOUD_SQL_CONNECTION_NAME=[CLOUD_SQL_CONNECTION_NAME_SECRET]:latest,\
193+
--add-cloudsql-instances $INSTANCE_CONNECTION_NAME \
194+
--update-secrets INSTANCE_CONNECTION_NAME=[INSTANCE_CONNECTION_NAME_SECRET]:latest,\
195195
DB_USER=[DB_USER_SECRET]:latest, \
196196
DB_PASS=[DB_PASS_SECRET]:latest, \
197197
DB_NAME=[DB_NAME_SECRET]:latest

cloud-sql/mysql/sqlalchemy/app.flexible.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ beta_settings:
3232
# something like https://cloud.google.com/secret-manager/docs/overview to help keep
3333
# secrets secret.
3434
env_variables:
35-
CLOUD_SQL_CONNECTION_NAME: <MY-PROJECT>:<INSTANCE-REGION>:<MY-DATABASE>
35+
INSTANCE_CONNECTION_NAME: <MY-PROJECT>:<INSTANCE-REGION>:<MY-DATABASE>
3636
DB_USER: my-db-user
3737
DB_PASS: my-db-pass
3838
DB_NAME: my_db

cloud-sql/mysql/sqlalchemy/app.standard.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ runtime: python37
1818
# something like https://cloud.google.com/secret-manager/docs/overview to help keep
1919
# secrets secret.
2020
env_variables:
21-
CLOUD_SQL_CONNECTION_NAME: <MY-PROJECT>:<INSTANCE-REGION>:<MY-DATABASE>
21+
INSTANCE_CONNECTION_NAME: <MY-PROJECT>:<INSTANCE-REGION>:<MY-DATABASE>
2222
DB_USER: my-db-user
2323
DB_PASS: my-db-pass
2424
DB_NAME: my_db

cloud-sql/mysql/sqlalchemy/connection_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_get(tcp_db_connection):
5151
"MYSQL_USER": "DB_USER",
5252
"MYSQL_PASSWORD": "DB_PASS",
5353
"MYSQL_DATABASE": "DB_NAME",
54-
"MYSQL_INSTANCE": "CLOUD_SQL_CONNECTION_NAME",
54+
"MYSQL_INSTANCE": "INSTANCE_CONNECTION_NAME",
5555
}
5656

5757

cloud-sql/mysql/sqlalchemy/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def init_unix_connection_engine(db_config):
157157
db_pass = os.environ["DB_PASS"]
158158
db_name = os.environ["DB_NAME"]
159159
db_socket_dir = os.environ.get("DB_SOCKET_DIR", "/cloudsql")
160-
cloud_sql_connection_name = os.environ["CLOUD_SQL_CONNECTION_NAME"]
160+
instance_connection_name = os.environ["INSTANCE_CONNECTION_NAME"]
161161

162162
pool = sqlalchemy.create_engine(
163163
# Equivalent URL:
@@ -170,7 +170,7 @@ def init_unix_connection_engine(db_config):
170170
query={
171171
"unix_socket": "{}/{}".format(
172172
db_socket_dir, # e.g. "/cloudsql"
173-
cloud_sql_connection_name) # i.e "<PROJECT-NAME>:<INSTANCE-REGION>:<INSTANCE-NAME>"
173+
instance_connection_name) # i.e "<PROJECT-NAME>:<INSTANCE-REGION>:<INSTANCE-NAME>"
174174
}
175175
),
176176
**db_config

cloud-sql/postgres/client-side-encryption/snippets/cloud_sql_connection_pool.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def init_unix_connection_engine(
4747
db_user: str,
4848
db_pass: str,
4949
db_name: str,
50-
cloud_sql_connection_name: str,
50+
instance_connection_name: str,
5151
db_socket_dir: str,
5252
) -> sqlalchemy.engine.base.Engine:
5353
# Remember - storing secrets in plaintext is potentially unsafe. Consider using
@@ -65,7 +65,7 @@ def init_unix_connection_engine(
6565
query={
6666
"unix_sock": "{}/{}/.s.PGSQL.5432".format(
6767
db_socket_dir, # e.g. "/cloudsql"
68-
cloud_sql_connection_name) # i.e "<PROJECT-NAME>:<INSTANCE-REGION>:<INSTANCE-NAME>"
68+
instance_connection_name) # i.e "<PROJECT-NAME>:<INSTANCE-REGION>:<INSTANCE-NAME>"
6969
}
7070
),
7171
)
@@ -78,7 +78,7 @@ def init_db(
7878
db_pass: str,
7979
db_name: str,
8080
table_name: str,
81-
cloud_sql_connection_name: str = None,
81+
instance_connection_name: str = None,
8282
db_socket_dir: str = None,
8383
db_host: str = None,
8484
) -> sqlalchemy.engine.base.Engine:
@@ -87,7 +87,7 @@ def init_db(
8787
db = init_tcp_connection_engine(db_user, db_pass, db_name, db_host)
8888
else:
8989
db = init_unix_connection_engine(
90-
db_user, db_pass, db_name, cloud_sql_connection_name, db_socket_dir
90+
db_user, db_pass, db_name, instance_connection_name, db_socket_dir
9191
)
9292

9393
# Create tables (if they don't already exist)

0 commit comments

Comments
 (0)