Skip to content

Commit e069520

Browse files
authored
feat!: replace Source field ip_type with ipType for consistency (#197)
Replace `ip_type` with `ipType` to match the camel-case of the other fields. Update docs since we support both private and public IP connections.
1 parent 1fcc20a commit e069520

7 files changed

Lines changed: 41 additions & 41 deletions

File tree

‎docs/sources/alloydb-pg.md‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ IAM identity has been given the following IAM permissions:
3232

3333
### Network Path
3434

35-
Currently, this source only supports [connecting over Private
36-
IP][private-ip]. Most notably, this means
37-
you need to connect from a VPC that AlloyDB has been connected to.
35+
Currently, AlloyDB supports connection over both [private IP][private-ip] and
36+
[public IP][public-ip]. Set the `ipType` parameter in your source
37+
configuration to `public` or `private`.
3838

3939
[private-ip]: https://cloud.google.com/alloydb/docs/private-ip
40+
[public-ip]: https://cloud.google.com/alloydb/docs/connect-public-ip
4041

4142
### Database User
4243

43-
Current, this source only uses standard authentication. You will need to [create a
44+
Currently, this source only uses standard authentication. You will need to [create a
4445
PostreSQL user][alloydb-users] to login to the database with.
4546

4647
[alloydb-users]: https://cloud.google.com/alloydb/docs/database-users/about
@@ -69,9 +70,7 @@ sources:
6970
| region | string | true | Name of the GCP region that the cluster was created in (e.g. "us-central1"). |
7071
| cluster | string | true | Name of the AlloyDB cluster (e.g. "my-cluster"). |
7172
| instance | string | true | Name of the AlloyDB instance within the cluser (e.g. "my-instance"). |
72-
| ip_type | string | true | IP Type of the AlloyDB instance, must be either `public` or `private`. Default: `public`. |
73+
| ipType | string | true | IP Type of the AlloyDB instance, must be either `public` or `private`. Default: `public`. |
7374
| database | string | true | Name of the Postgres database to connect to (e.g. "my_db"). |
7475
| user | string | true | Name of the Postgres user to connect as (e.g. "my-pg-user"). |
7576
| password | string | true | Password of the Postgres user (e.g. "my-password"). |
76-
77-

‎docs/sources/cloud-sql-pg.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ IAM identity has been given the following IAM roles:
3030

3131
### Network Path
3232

33-
Currently, this source only supports [connecting over Public IP][public-ip].
34-
Because it uses the Go connector, is uses rotating client certificates to
35-
establish a secure mTLS connection with the instance.
33+
Currently, Cloud SQL supports connection over both [private IP][private-ip] and
34+
[public IP][public-ip]. Set the `ipType` parameter in your source
35+
configuration to `public` or `private`.
3636

37+
[private-ip]: https://cloud.google.com/sql/docs/postgres/configure-private-ip
3738
[public-ip]: https://cloud.google.com/sql/docs/postgres/configure-ip
3839

3940
### Database User
4041

4142
Current, this source only uses standard authentication. You will need to [create a
42-
PostreSQL user][cloud-sql-users] to login to the database with.
43+
PostreSQL user][cloud-sql-users] to login to the database with.
4344

4445
[cloud-sql-users]: https://cloud.google.com/sql/docs/postgres/create-manage-users
4546

@@ -65,7 +66,7 @@ sources:
6566
| project | string | true | Id of the GCP project that the cluster was created in (e.g. "my-project-id"). |
6667
| region | string | true | Name of the GCP region that the cluster was created in (e.g. "us-central1"). |
6768
| instance | string | true | Name of the Cloud SQL instance within the cluser (e.g. "my-instance"). |
68-
| ip_type | string | true | IP Type of the Cloud SQL instance, must be either `public` or `private`. Default: `public`. |
69+
| ipType | string | true | IP Type of the Cloud SQL instance, must be either `public` or `private`. Default: `public`. |
6970
| database | string | true | Name of the Postgres database to connect to (e.g. "my_db"). |
7071
| user | string | true | Name of the Postgres user to connect as (e.g. "my-pg-user"). |
7172
| password | string | true | Password of the Postgres user (e.g. "my-password"). |

‎internal/sources/alloydbpg/alloydb_pg.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Config struct {
3838
Region string `yaml:"region"`
3939
Cluster string `yaml:"cluster"`
4040
Instance string `yaml:"instance"`
41-
IPType sources.IPType `yaml:"ip_type"`
41+
IPType sources.IPType `yaml:"ipType"`
4242
User string `yaml:"user"`
4343
Password string `yaml:"password"`
4444
Database string `yaml:"database"`
@@ -83,18 +83,18 @@ func (s *Source) PostgresPool() *pgxpool.Pool {
8383
return s.Pool
8484
}
8585

86-
func getDialOpts(ip_type string) ([]alloydbconn.DialOption, error) {
87-
switch strings.ToLower(ip_type) {
86+
func getDialOpts(ipType string) ([]alloydbconn.DialOption, error) {
87+
switch strings.ToLower(ipType) {
8888
case "private":
8989
return []alloydbconn.DialOption{alloydbconn.WithPrivateIP()}, nil
9090
case "public":
9191
return []alloydbconn.DialOption{alloydbconn.WithPublicIP()}, nil
9292
default:
93-
return nil, fmt.Errorf("invalid ip_type %s", ip_type)
93+
return nil, fmt.Errorf("invalid ipType %s", ipType)
9494
}
9595
}
9696

97-
func initAlloyDBPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, cluster, instance, ip_type, user, pass, dbname string) (*pgxpool.Pool, error) {
97+
func initAlloyDBPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, cluster, instance, ipType, user, pass, dbname string) (*pgxpool.Pool, error) {
9898
//nolint:all // Reassigned ctx
9999
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
100100
defer span.End()
@@ -107,7 +107,7 @@ func initAlloyDBPgConnectionPool(ctx context.Context, tracer trace.Tracer, name,
107107
}
108108

109109
// Create a new dialer with options
110-
dialOpts, err := getDialOpts(ip_type)
110+
dialOpts, err := getDialOpts(ipType)
111111
if err != nil {
112112
return nil, err
113113
}

‎internal/sources/alloydbpg/alloydb_pg_test.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestParseFromYamlAlloyDBPg(t *testing.T) {
5757
},
5858
},
5959
{
60-
desc: "public ip_type",
60+
desc: "public ipType",
6161
in: `
6262
sources:
6363
my-pg-instance:
@@ -66,7 +66,7 @@ func TestParseFromYamlAlloyDBPg(t *testing.T) {
6666
region: my-region
6767
cluster: my-cluster
6868
instance: my-instance
69-
ip_type: Public
69+
ipType: Public
7070
database: my_db
7171
`,
7272
want: map[string]sources.SourceConfig{
@@ -83,7 +83,7 @@ func TestParseFromYamlAlloyDBPg(t *testing.T) {
8383
},
8484
},
8585
{
86-
desc: "private ip_type",
86+
desc: "private ipType",
8787
in: `
8888
sources:
8989
my-pg-instance:
@@ -92,7 +92,7 @@ func TestParseFromYamlAlloyDBPg(t *testing.T) {
9292
region: my-region
9393
cluster: my-cluster
9494
instance: my-instance
95-
ip_type: private
95+
ipType: private
9696
database: my_db
9797
`,
9898
want: map[string]sources.SourceConfig{
@@ -132,7 +132,7 @@ func FailParseFromYamlAlloyDBPg(t *testing.T) {
132132
in string
133133
}{
134134
{
135-
desc: "invalid ip_type",
135+
desc: "invalid ipType",
136136
in: `
137137
sources:
138138
my-pg-instance:
@@ -141,7 +141,7 @@ func FailParseFromYamlAlloyDBPg(t *testing.T) {
141141
region: my-region
142142
cluster: my-cluster
143143
instance: my-instance
144-
ip_type: fail
144+
ipType: fail
145145
database: my_db
146146
`,
147147
},

‎internal/sources/cloudsqlpg/cloud_sql_pg.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Config struct {
3737
Project string `yaml:"project"`
3838
Region string `yaml:"region"`
3939
Instance string `yaml:"instance"`
40-
IPType sources.IPType `yaml:"ip_type"`
40+
IPType sources.IPType `yaml:"ipType"`
4141
User string `yaml:"user"`
4242
Password string `yaml:"password"`
4343
Database string `yaml:"database"`
@@ -82,18 +82,18 @@ func (s *Source) PostgresPool() *pgxpool.Pool {
8282
return s.Pool
8383
}
8484

85-
func getDialOpts(ip_type string) ([]cloudsqlconn.DialOption, error) {
86-
switch strings.ToLower(ip_type) {
85+
func getDialOpts(ipType string) ([]cloudsqlconn.DialOption, error) {
86+
switch strings.ToLower(ipType) {
8787
case "private":
8888
return []cloudsqlconn.DialOption{cloudsqlconn.WithPrivateIP()}, nil
8989
case "public":
9090
return []cloudsqlconn.DialOption{cloudsqlconn.WithPublicIP()}, nil
9191
default:
92-
return nil, fmt.Errorf("invalid ip_type %s", ip_type)
92+
return nil, fmt.Errorf("invalid ipType %s", ipType)
9393
}
9494
}
9595

96-
func initCloudSQLPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ip_type, user, pass, dbname string) (*pgxpool.Pool, error) {
96+
func initCloudSQLPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ipType, user, pass, dbname string) (*pgxpool.Pool, error) {
9797
//nolint:all // Reassigned ctx
9898
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
9999
defer span.End()
@@ -106,7 +106,7 @@ func initCloudSQLPgConnectionPool(ctx context.Context, tracer trace.Tracer, name
106106
}
107107

108108
// Create a new dialer with options
109-
dialOpts, err := getDialOpts(ip_type)
109+
dialOpts, err := getDialOpts(ipType)
110110
if err != nil {
111111
return nil, err
112112
}

‎internal/sources/cloudsqlpg/cloud_sql_pg_test.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ func TestParseFromYamlCloudSQLPg(t *testing.T) {
5454
},
5555
},
5656
{
57-
desc: "public ip_type",
57+
desc: "public ipType",
5858
in: `
5959
sources:
6060
my-pg-instance:
6161
kind: cloud-sql-postgres
6262
project: my-project
6363
region: my-region
6464
instance: my-instance
65-
ip_type: Public
65+
ipType: Public
6666
database: my_db
6767
`,
6868
want: server.SourceConfigs{
@@ -78,15 +78,15 @@ func TestParseFromYamlCloudSQLPg(t *testing.T) {
7878
},
7979
},
8080
{
81-
desc: "private ip_type",
81+
desc: "private ipType",
8282
in: `
8383
sources:
8484
my-pg-instance:
8585
kind: cloud-sql-postgres
8686
project: my-project
8787
region: my-region
8888
instance: my-instance
89-
ip_type: private
89+
ipType: private
9090
database: my_db
9191
`,
9292
want: server.SourceConfigs{
@@ -126,15 +126,15 @@ func FailParseFromYamlCloudSQLPg(t *testing.T) {
126126
in string
127127
}{
128128
{
129-
desc: "invalid ip_type",
129+
desc: "invalid ipType",
130130
in: `
131131
sources:
132132
my-pg-instance:
133133
kind: cloud-sql-postgres
134134
project: my-project
135135
region: my-region
136136
instance: my-instance
137-
ip_type: fail
137+
ipType: fail
138138
database: my_db
139139
`,
140140
},

‎internal/sources/ip_type.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ func (i *IPType) String() string {
3131
}
3232

3333
func (i *IPType) UnmarshalYAML(node *yaml.Node) error {
34-
var ip_type string
35-
if err := node.Decode(&ip_type); err != nil {
34+
var ipType string
35+
if err := node.Decode(&ipType); err != nil {
3636
return err
3737
}
38-
switch strings.ToLower(ip_type) {
38+
switch strings.ToLower(ipType) {
3939
case "private", "public":
40-
*i = IPType(strings.ToLower(ip_type))
40+
*i = IPType(strings.ToLower(ipType))
4141
return nil
4242
default:
43-
return fmt.Errorf(`ip_type invalid: must be one of "public", or "private"`)
43+
return fmt.Errorf(`ipType invalid: must be one of "public", or "private"`)
4444
}
4545
}

0 commit comments

Comments
 (0)