mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-02-17 18:41:28 -05:00
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.
This commit is contained in:
@@ -38,7 +38,7 @@ type Config struct {
|
||||
Region string `yaml:"region"`
|
||||
Cluster string `yaml:"cluster"`
|
||||
Instance string `yaml:"instance"`
|
||||
IPType sources.IPType `yaml:"ip_type"`
|
||||
IPType sources.IPType `yaml:"ipType"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
Database string `yaml:"database"`
|
||||
@@ -83,18 +83,18 @@ func (s *Source) PostgresPool() *pgxpool.Pool {
|
||||
return s.Pool
|
||||
}
|
||||
|
||||
func getDialOpts(ip_type string) ([]alloydbconn.DialOption, error) {
|
||||
switch strings.ToLower(ip_type) {
|
||||
func getDialOpts(ipType string) ([]alloydbconn.DialOption, error) {
|
||||
switch strings.ToLower(ipType) {
|
||||
case "private":
|
||||
return []alloydbconn.DialOption{alloydbconn.WithPrivateIP()}, nil
|
||||
case "public":
|
||||
return []alloydbconn.DialOption{alloydbconn.WithPublicIP()}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid ip_type %s", ip_type)
|
||||
return nil, fmt.Errorf("invalid ipType %s", ipType)
|
||||
}
|
||||
}
|
||||
|
||||
func initAlloyDBPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, cluster, instance, ip_type, user, pass, dbname string) (*pgxpool.Pool, error) {
|
||||
func initAlloyDBPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, cluster, instance, ipType, user, pass, dbname string) (*pgxpool.Pool, error) {
|
||||
//nolint:all // Reassigned ctx
|
||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
||||
defer span.End()
|
||||
@@ -107,7 +107,7 @@ func initAlloyDBPgConnectionPool(ctx context.Context, tracer trace.Tracer, name,
|
||||
}
|
||||
|
||||
// Create a new dialer with options
|
||||
dialOpts, err := getDialOpts(ip_type)
|
||||
dialOpts, err := getDialOpts(ipType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func TestParseFromYamlAlloyDBPg(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "public ip_type",
|
||||
desc: "public ipType",
|
||||
in: `
|
||||
sources:
|
||||
my-pg-instance:
|
||||
@@ -66,7 +66,7 @@ func TestParseFromYamlAlloyDBPg(t *testing.T) {
|
||||
region: my-region
|
||||
cluster: my-cluster
|
||||
instance: my-instance
|
||||
ip_type: Public
|
||||
ipType: Public
|
||||
database: my_db
|
||||
`,
|
||||
want: map[string]sources.SourceConfig{
|
||||
@@ -83,7 +83,7 @@ func TestParseFromYamlAlloyDBPg(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "private ip_type",
|
||||
desc: "private ipType",
|
||||
in: `
|
||||
sources:
|
||||
my-pg-instance:
|
||||
@@ -92,7 +92,7 @@ func TestParseFromYamlAlloyDBPg(t *testing.T) {
|
||||
region: my-region
|
||||
cluster: my-cluster
|
||||
instance: my-instance
|
||||
ip_type: private
|
||||
ipType: private
|
||||
database: my_db
|
||||
`,
|
||||
want: map[string]sources.SourceConfig{
|
||||
@@ -132,7 +132,7 @@ func FailParseFromYamlAlloyDBPg(t *testing.T) {
|
||||
in string
|
||||
}{
|
||||
{
|
||||
desc: "invalid ip_type",
|
||||
desc: "invalid ipType",
|
||||
in: `
|
||||
sources:
|
||||
my-pg-instance:
|
||||
@@ -141,7 +141,7 @@ func FailParseFromYamlAlloyDBPg(t *testing.T) {
|
||||
region: my-region
|
||||
cluster: my-cluster
|
||||
instance: my-instance
|
||||
ip_type: fail
|
||||
ipType: fail
|
||||
database: my_db
|
||||
`,
|
||||
},
|
||||
|
||||
@@ -37,7 +37,7 @@ type Config struct {
|
||||
Project string `yaml:"project"`
|
||||
Region string `yaml:"region"`
|
||||
Instance string `yaml:"instance"`
|
||||
IPType sources.IPType `yaml:"ip_type"`
|
||||
IPType sources.IPType `yaml:"ipType"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
Database string `yaml:"database"`
|
||||
@@ -82,18 +82,18 @@ func (s *Source) PostgresPool() *pgxpool.Pool {
|
||||
return s.Pool
|
||||
}
|
||||
|
||||
func getDialOpts(ip_type string) ([]cloudsqlconn.DialOption, error) {
|
||||
switch strings.ToLower(ip_type) {
|
||||
func getDialOpts(ipType string) ([]cloudsqlconn.DialOption, error) {
|
||||
switch strings.ToLower(ipType) {
|
||||
case "private":
|
||||
return []cloudsqlconn.DialOption{cloudsqlconn.WithPrivateIP()}, nil
|
||||
case "public":
|
||||
return []cloudsqlconn.DialOption{cloudsqlconn.WithPublicIP()}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid ip_type %s", ip_type)
|
||||
return nil, fmt.Errorf("invalid ipType %s", ipType)
|
||||
}
|
||||
}
|
||||
|
||||
func initCloudSQLPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ip_type, user, pass, dbname string) (*pgxpool.Pool, error) {
|
||||
func initCloudSQLPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ipType, user, pass, dbname string) (*pgxpool.Pool, error) {
|
||||
//nolint:all // Reassigned ctx
|
||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
||||
defer span.End()
|
||||
@@ -106,7 +106,7 @@ func initCloudSQLPgConnectionPool(ctx context.Context, tracer trace.Tracer, name
|
||||
}
|
||||
|
||||
// Create a new dialer with options
|
||||
dialOpts, err := getDialOpts(ip_type)
|
||||
dialOpts, err := getDialOpts(ipType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func TestParseFromYamlCloudSQLPg(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "public ip_type",
|
||||
desc: "public ipType",
|
||||
in: `
|
||||
sources:
|
||||
my-pg-instance:
|
||||
@@ -62,7 +62,7 @@ func TestParseFromYamlCloudSQLPg(t *testing.T) {
|
||||
project: my-project
|
||||
region: my-region
|
||||
instance: my-instance
|
||||
ip_type: Public
|
||||
ipType: Public
|
||||
database: my_db
|
||||
`,
|
||||
want: server.SourceConfigs{
|
||||
@@ -78,7 +78,7 @@ func TestParseFromYamlCloudSQLPg(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "private ip_type",
|
||||
desc: "private ipType",
|
||||
in: `
|
||||
sources:
|
||||
my-pg-instance:
|
||||
@@ -86,7 +86,7 @@ func TestParseFromYamlCloudSQLPg(t *testing.T) {
|
||||
project: my-project
|
||||
region: my-region
|
||||
instance: my-instance
|
||||
ip_type: private
|
||||
ipType: private
|
||||
database: my_db
|
||||
`,
|
||||
want: server.SourceConfigs{
|
||||
@@ -126,7 +126,7 @@ func FailParseFromYamlCloudSQLPg(t *testing.T) {
|
||||
in string
|
||||
}{
|
||||
{
|
||||
desc: "invalid ip_type",
|
||||
desc: "invalid ipType",
|
||||
in: `
|
||||
sources:
|
||||
my-pg-instance:
|
||||
@@ -134,7 +134,7 @@ func FailParseFromYamlCloudSQLPg(t *testing.T) {
|
||||
project: my-project
|
||||
region: my-region
|
||||
instance: my-instance
|
||||
ip_type: fail
|
||||
ipType: fail
|
||||
database: my_db
|
||||
`,
|
||||
},
|
||||
|
||||
@@ -31,15 +31,15 @@ func (i *IPType) String() string {
|
||||
}
|
||||
|
||||
func (i *IPType) UnmarshalYAML(node *yaml.Node) error {
|
||||
var ip_type string
|
||||
if err := node.Decode(&ip_type); err != nil {
|
||||
var ipType string
|
||||
if err := node.Decode(&ipType); err != nil {
|
||||
return err
|
||||
}
|
||||
switch strings.ToLower(ip_type) {
|
||||
switch strings.ToLower(ipType) {
|
||||
case "private", "public":
|
||||
*i = IPType(strings.ToLower(ip_type))
|
||||
*i = IPType(strings.ToLower(ipType))
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf(`ip_type invalid: must be one of "public", or "private"`)
|
||||
return fmt.Errorf(`ipType invalid: must be one of "public", or "private"`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user