From 4a680ecf3b0177466db322ec39e232b6efa15c9f Mon Sep 17 00:00:00 2001 From: Dmitry Kropachev Date: Mon, 30 Sep 2024 16:39:26 -0400 Subject: [PATCH] Add schemagen ssl options --- cmd/schemagen/schemagen.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/cmd/schemagen/schemagen.go b/cmd/schemagen/schemagen.go index 3eb9e57..dcc5448 100644 --- a/cmd/schemagen/schemagen.go +++ b/cmd/schemagen/schemagen.go @@ -22,15 +22,19 @@ import ( ) var ( - cmd = flag.NewFlagSet(os.Args[0], flag.ExitOnError) - flagCluster = cmd.String("cluster", "127.0.0.1", "a comma-separated list of host:port tuples") - flagKeyspace = cmd.String("keyspace", "", "keyspace to inspect") - flagPkgname = cmd.String("pkgname", "models", "the name you wish to assign to your generated package") - flagOutput = cmd.String("output", "models", "the name of the folder to output to") - flagUser = cmd.String("user", "", "user for password authentication") - flagPassword = cmd.String("password", "", "password for password authentication") - flagIgnoreNames = cmd.String("ignore-names", "", "a comma-separated list of table, view or index names to ignore") - flagIgnoreIndexes = cmd.Bool("ignore-indexes", false, "don't generate types for indexes") + cmd = flag.NewFlagSet(os.Args[0], flag.ExitOnError) + flagCluster = cmd.String("cluster", "127.0.0.1", "a comma-separated list of host:port tuples") + flagKeyspace = cmd.String("keyspace", "", "keyspace to inspect") + flagPkgname = cmd.String("pkgname", "models", "the name you wish to assign to your generated package") + flagOutput = cmd.String("output", "models", "the name of the folder to output to") + flagUser = cmd.String("user", "", "user for password authentication") + flagPassword = cmd.String("password", "", "password for password authentication") + flagIgnoreNames = cmd.String("ignore-names", "", "a comma-separated list of table, view or index names to ignore") + flagIgnoreIndexes = cmd.Bool("ignore-indexes", false, "don't generate types for indexes") + 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 @@ -152,6 +156,15 @@ func createSession() (gocqlx.Session, error) { Password: *flagPassword, } } + if *flagSSLCAPath != "" || *flagSSLCertPath != "" || *flagSSLKeyPath != "" { + cluster.SslOpts = &gocql.SslOptions{ + EnableHostVerification: *flagSSLEnableHostVerification, + CaPath: *flagSSLCAPath, + CertPath: *flagSSLCertPath, + KeyPath: *flagSSLKeyPath, + } + } + return gocqlx.WrapSession(cluster.CreateSession()) }