Add schemagen ssl options (#294)

This commit is contained in:
Dmitry Kropachev
2024-10-01 06:54:15 -04:00
committed by GitHub
parent 177161646e
commit ab73391f35

View File

@@ -40,6 +40,10 @@ var (
flagIgnoreIndexes = cmd.Bool("ignore-indexes", false, "don't generate types for indexes") flagIgnoreIndexes = cmd.Bool("ignore-indexes", false, "don't generate types for indexes")
flagQueryTimeout = cmd.Duration("query-timeout", defaultQueryTimeout, "query timeout ( in seconds )") flagQueryTimeout = cmd.Duration("query-timeout", defaultQueryTimeout, "query timeout ( in seconds )")
flagConnectionTimeout = cmd.Duration("connection-timeout", defaultConnectionTimeout, "connection timeout ( in seconds )") flagConnectionTimeout = cmd.Duration("connection-timeout", defaultConnectionTimeout, "connection timeout ( in seconds )")
flagSSLEnableHostVerification = cmd.Bool("ssl-enable-host-verification", false, "don't check server ssl certificate")
flagSSLCAPath = cmd.String("ssl-ca-path", "", "path to ssl CA certificates")
flagSSLCertPath = cmd.String("ssl-cert-path", "", "path to ssl certificate")
flagSSLKeyPath = cmd.String("ssl-key-path", "", "path to ssl key")
) )
//go:embed keyspace.tmpl //go:embed keyspace.tmpl
@@ -155,18 +159,30 @@ func renderTemplate(md *gocql.KeyspaceMetadata) ([]byte, error) {
func createSession() (gocqlx.Session, error) { func createSession() (gocqlx.Session, error) {
cluster := gocql.NewCluster(clusterHosts()...) cluster := gocql.NewCluster(clusterHosts()...)
if *flagUser != "" { if *flagUser != "" {
cluster.Authenticator = gocql.PasswordAuthenticator{ cluster.Authenticator = gocql.PasswordAuthenticator{
Username: *flagUser, Username: *flagUser,
Password: *flagPassword, Password: *flagPassword,
} }
} }
if *flagQueryTimeout >= 0 { if *flagQueryTimeout >= 0 {
cluster.Timeout = *flagQueryTimeout cluster.Timeout = *flagQueryTimeout
} }
if *flagConnectionTimeout >= 0 { if *flagConnectionTimeout >= 0 {
cluster.ConnectTimeout = *flagConnectionTimeout cluster.ConnectTimeout = *flagConnectionTimeout
} }
if *flagSSLCAPath != "" || *flagSSLCertPath != "" || *flagSSLKeyPath != "" {
cluster.SslOpts = &gocql.SslOptions{
EnableHostVerification: *flagSSLEnableHostVerification,
CaPath: *flagSSLCAPath,
CertPath: *flagSSLCertPath,
KeyPath: *flagSSLKeyPath,
}
}
return gocqlx.WrapSession(cluster.CreateSession()) return gocqlx.WrapSession(cluster.CreateSession())
} }