Skip to content

Commit 38d535d

Browse files
authored
fix(source/cloud-sql-mssql): remove ip address field (#1822)
## Description Removing the `ipAddress` field since it is not an input for Cloud SQL SQL Server source. Kept the variable in Source's config but removed this variable from everywhere else in the code. This will PREVENT a breaking change since the validator won't flag it as an "extra field". **Will have to update the following as well:** (1) Cloud docs https://cloud.google.com/sql/docs/sqlserver/pre-built-tools-with-mcp-toolbox (2) gemini-cli-extensions https://github.com/gemini-cli-extensions/cloud-sql-sqlserver ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [x] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [x] Appropriate docs were updated (if necessary) - [x] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #1549
1 parent ef28e39 commit 38d535d

7 files changed

Lines changed: 53 additions & 41 deletions

File tree

‎docs/en/reference/prebuilt-tools.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ details on how to connect your AI tools (IDEs) to databases via Toolbox and MCP.
264264
* `CLOUD_SQL_MSSQL_REGION`: The region of your Cloud SQL instance.
265265
* `CLOUD_SQL_MSSQL_INSTANCE`: The ID of your Cloud SQL instance.
266266
* `CLOUD_SQL_MSSQL_DATABASE`: The name of the database to connect to.
267-
* `CLOUD_SQL_MSSQL_IP_ADDRESS`: The IP address of the Cloud SQL instance.
268267
* `CLOUD_SQL_MSSQL_USER`: The database username.
269268
* `CLOUD_SQL_MSSQL_PASSWORD`: The password for the database user.
270269
* `CLOUD_SQL_MSSQL_IP_TYPE`: (Optional) The IP type i.e. "Public" or

‎docs/en/resources/sources/cloud-sql-mssql.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ sources:
9494
region: my-region
9595
instance: my-instance
9696
database: my_db
97-
ipAddress: localhost
9897
user: ${USER_NAME}
9998
password: ${PASSWORD}
10099
# ipType: private
@@ -114,7 +113,6 @@ instead of hardcoding your secrets into the configuration file.
114113
| region | string | true | Name of the GCP region that the cluster was created in (e.g. "us-central1"). |
115114
| instance | string | true | Name of the Cloud SQL instance within the cluster (e.g. "my-instance"). |
116115
| database | string | true | Name of the Cloud SQL database to connect to (e.g. "my_db"). |
117-
| ipAddress | string | true | IP address of the Cloud SQL instance to connect to. |
118116
| user | string | true | Name of the SQL Server user to connect as (e.g. "my-pg-user"). |
119117
| password | string | true | Password of the SQL Server user (e.g. "my-password"). |
120118
| ipType | string | false | IP Type of the Cloud SQL instance, must be either `public`, `private`, or `psc`. Default: `public`. |

‎internal/prebuiltconfigs/tools/cloud-sql-mssql-observability.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ tools:
7373
7474
toolsets:
7575
cloud_sql_mssql_cloud_monitoring_tools:
76-
- get_system_metrics
76+
- get_system_metrics

‎internal/prebuiltconfigs/tools/cloud-sql-mssql.yaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ sources:
1919
region: ${CLOUD_SQL_MSSQL_REGION}
2020
instance: ${CLOUD_SQL_MSSQL_INSTANCE}
2121
database: ${CLOUD_SQL_MSSQL_DATABASE}
22-
ipAddress: ${CLOUD_SQL_MSSQL_IP_ADDRESS}
2322
user: ${CLOUD_SQL_MSSQL_USER}
2423
password: ${CLOUD_SQL_MSSQL_PASSWORD}
2524
ipType: ${CLOUD_SQL_MSSQL_IP_TYPE:public}

‎internal/sources/cloudsqlmssql/cloud_sql_mssql.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type Config struct {
5454
Project string `yaml:"project" validate:"required"`
5555
Region string `yaml:"region" validate:"required"`
5656
Instance string `yaml:"instance" validate:"required"`
57-
IPAddress string `yaml:"ipAddress" validate:"required"`
57+
IPAddress string `yaml:"ipAddress"` // Deprecated: kept for backwards compatibility
5858
IPType sources.IPType `yaml:"ipType" validate:"required"`
5959
User string `yaml:"user" validate:"required"`
6060
Password string `yaml:"password" validate:"required"`
@@ -68,7 +68,7 @@ func (r Config) SourceConfigKind() string {
6868

6969
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
7070
// Initializes a Cloud SQL MSSQL source
71-
db, err := initCloudSQLMssqlConnection(ctx, tracer, r.Name, r.Project, r.Region, r.Instance, r.IPAddress, r.IPType.String(), r.User, r.Password, r.Database)
71+
db, err := initCloudSQLMssqlConnection(ctx, tracer, r.Name, r.Project, r.Region, r.Instance, r.IPType.String(), r.User, r.Password, r.Database)
7272
if err != nil {
7373
return nil, fmt.Errorf("unable to create db connection: %w", err)
7474
}
@@ -106,7 +106,7 @@ func (s *Source) MSSQLDB() *sql.DB {
106106
return s.Db
107107
}
108108

109-
func initCloudSQLMssqlConnection(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ipAddress, ipType, user, pass, dbname string) (*sql.DB, error) {
109+
func initCloudSQLMssqlConnection(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ipType, user, pass, dbname string) (*sql.DB, error) {
110110
//nolint:all // Reassigned ctx
111111
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
112112
defer span.End()
@@ -125,7 +125,6 @@ func initCloudSQLMssqlConnection(ctx context.Context, tracer trace.Tracer, name,
125125
url := &url.URL{
126126
Scheme: "sqlserver",
127127
User: url.UserPassword(user, pass),
128-
Host: ipAddress,
129128
RawQuery: query.Encode(),
130129
}
131130

‎internal/sources/cloudsqlmssql/cloud_sql_mssql_test.go‎

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,20 @@ func TestParseFromYamlCloudSQLMssql(t *testing.T) {
4040
region: my-region
4141
instance: my-instance
4242
database: my_db
43-
ipAddress: localhost
4443
user: my_user
4544
password: my_pass
4645
`,
4746
want: server.SourceConfigs{
4847
"my-instance": cloudsqlmssql.Config{
49-
Name: "my-instance",
50-
Kind: cloudsqlmssql.SourceKind,
51-
Project: "my-project",
52-
Region: "my-region",
53-
Instance: "my-instance",
54-
IPAddress: "localhost",
55-
IPType: "public",
56-
Database: "my_db",
57-
User: "my_user",
58-
Password: "my_pass",
48+
Name: "my-instance",
49+
Kind: cloudsqlmssql.SourceKind,
50+
Project: "my-project",
51+
Region: "my-region",
52+
Instance: "my-instance",
53+
IPType: "public",
54+
Database: "my_db",
55+
User: "my_user",
56+
Password: "my_pass",
5957
},
6058
},
6159
},
@@ -69,20 +67,47 @@ func TestParseFromYamlCloudSQLMssql(t *testing.T) {
6967
region: my-region
7068
instance: my-instance
7169
database: my_db
72-
ipAddress: localhost
7370
user: my_user
7471
password: my_pass
7572
ipType: psc
7673
`,
74+
want: server.SourceConfigs{
75+
"my-instance": cloudsqlmssql.Config{
76+
Name: "my-instance",
77+
Kind: cloudsqlmssql.SourceKind,
78+
Project: "my-project",
79+
Region: "my-region",
80+
Instance: "my-instance",
81+
IPType: "psc",
82+
Database: "my_db",
83+
User: "my_user",
84+
Password: "my_pass",
85+
},
86+
},
87+
},
88+
{
89+
desc: "with deprecated ipAddress",
90+
in: `
91+
sources:
92+
my-instance:
93+
kind: cloud-sql-mssql
94+
project: my-project
95+
region: my-region
96+
instance: my-instance
97+
ipAddress: random
98+
database: my_db
99+
user: my_user
100+
password: my_pass
101+
`,
77102
want: server.SourceConfigs{
78103
"my-instance": cloudsqlmssql.Config{
79104
Name: "my-instance",
80105
Kind: cloudsqlmssql.SourceKind,
81106
Project: "my-project",
82107
Region: "my-region",
83108
Instance: "my-instance",
84-
IPAddress: "localhost",
85-
IPType: "psc",
109+
IPAddress: "random",
110+
IPType: "public",
86111
Database: "my_db",
87112
User: "my_user",
88113
Password: "my_pass",
@@ -125,7 +150,6 @@ func TestFailParseFromYaml(t *testing.T) {
125150
instance: my-instance
126151
ipType: fail
127152
database: my_db
128-
ipAddress: localhost
129153
user: my_user
130154
password: my_pass
131155
`,
@@ -141,12 +165,11 @@ func TestFailParseFromYaml(t *testing.T) {
141165
region: my-region
142166
instance: my-instance
143167
database: my_db
144-
ipAddress: localhost
145168
user: my_user
146169
password: my_pass
147170
foo: bar
148171
`,
149-
err: "unable to parse source \"my-instance\" as \"cloud-sql-mssql\": [2:1] unknown field \"foo\"\n 1 | database: my_db\n> 2 | foo: bar\n ^\n 3 | instance: my-instance\n 4 | ipAddress: localhost\n 5 | kind: cloud-sql-mssql\n 6 | ",
172+
err: "unable to parse source \"my-instance\" as \"cloud-sql-mssql\": [2:1] unknown field \"foo\"\n 1 | database: my_db\n> 2 | foo: bar\n ^\n 3 | instance: my-instance\n 4 | kind: cloud-sql-mssql\n 5 | password: my_pass\n 6 | ",
150173
},
151174
{
152175
desc: "missing required field",
@@ -157,7 +180,6 @@ func TestFailParseFromYaml(t *testing.T) {
157180
region: my-region
158181
instance: my-instance
159182
database: my_db
160-
ipAddress: localhost
161183
user: my_user
162184
password: my_pass
163185
`,

‎tests/cloudsqlmssql/cloud_sql_mssql_integration_test.go‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ var (
4040
CloudSQLMSSQLRegion = os.Getenv("CLOUD_SQL_MSSQL_REGION")
4141
CloudSQLMSSQLInstance = os.Getenv("CLOUD_SQL_MSSQL_INSTANCE")
4242
CloudSQLMSSQLDatabase = os.Getenv("CLOUD_SQL_MSSQL_DATABASE")
43-
CloudSQLMSSQLIp = os.Getenv("CLOUD_SQL_MSSQL_IP")
4443
CloudSQLMSSQLUser = os.Getenv("CLOUD_SQL_MSSQL_USER")
4544
CloudSQLMSSQLPass = os.Getenv("CLOUD_SQL_MSSQL_PASS")
4645
)
@@ -53,8 +52,6 @@ func getCloudSQLMSSQLVars(t *testing.T) map[string]any {
5352
t.Fatal("'CLOUD_SQL_MSSQL_REGION' not set")
5453
case CloudSQLMSSQLInstance:
5554
t.Fatal("'CLOUD_SQL_MSSQL_INSTANCE' not set")
56-
case CloudSQLMSSQLIp:
57-
t.Fatal("'CLOUD_SQL_MSSQL_IP' not set")
5855
case CloudSQLMSSQLDatabase:
5956
t.Fatal("'CLOUD_SQL_MSSQL_DATABASE' not set")
6057
case CloudSQLMSSQLUser:
@@ -64,25 +61,23 @@ func getCloudSQLMSSQLVars(t *testing.T) map[string]any {
6461
}
6562

6663
return map[string]any{
67-
"kind": CloudSQLMSSQLSourceKind,
68-
"project": CloudSQLMSSQLProject,
69-
"instance": CloudSQLMSSQLInstance,
70-
"ipAddress": CloudSQLMSSQLIp,
71-
"region": CloudSQLMSSQLRegion,
72-
"database": CloudSQLMSSQLDatabase,
73-
"user": CloudSQLMSSQLUser,
74-
"password": CloudSQLMSSQLPass,
64+
"kind": CloudSQLMSSQLSourceKind,
65+
"project": CloudSQLMSSQLProject,
66+
"instance": CloudSQLMSSQLInstance,
67+
"region": CloudSQLMSSQLRegion,
68+
"database": CloudSQLMSSQLDatabase,
69+
"user": CloudSQLMSSQLUser,
70+
"password": CloudSQLMSSQLPass,
7571
}
7672
}
7773

7874
// Copied over from cloud_sql_mssql.go
79-
func initCloudSQLMSSQLConnection(project, region, instance, ipAddress, ipType, user, pass, dbname string) (*sql.DB, error) {
75+
func initCloudSQLMSSQLConnection(project, region, instance, ipType, user, pass, dbname string) (*sql.DB, error) {
8076
// Create dsn
8177
query := fmt.Sprintf("database=%s&cloudsql=%s:%s:%s", dbname, project, region, instance)
8278
url := &url.URL{
8379
Scheme: "sqlserver",
8480
User: url.UserPassword(user, pass),
85-
Host: ipAddress,
8681
RawQuery: query,
8782
}
8883

@@ -118,7 +113,7 @@ func TestCloudSQLMSSQLToolEndpoints(t *testing.T) {
118113

119114
var args []string
120115

121-
db, err := initCloudSQLMSSQLConnection(CloudSQLMSSQLProject, CloudSQLMSSQLRegion, CloudSQLMSSQLInstance, CloudSQLMSSQLIp, "public", CloudSQLMSSQLUser, CloudSQLMSSQLPass, CloudSQLMSSQLDatabase)
116+
db, err := initCloudSQLMSSQLConnection(CloudSQLMSSQLProject, CloudSQLMSSQLRegion, CloudSQLMSSQLInstance, "public", CloudSQLMSSQLUser, CloudSQLMSSQLPass, CloudSQLMSSQLDatabase)
122117
if err != nil {
123118
t.Fatalf("unable to create Cloud SQL connection pool: %s", err)
124119
}

0 commit comments

Comments
 (0)