Skip to content

Commit ab73391

Browse files
authored
Add schemagen ssl options (#294)
1 parent 1771616 commit ab73391

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

Diff for: cmd/schemagen/schemagen.go

+27-11
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,21 @@ var (
2929
)
3030

3131
var (
32-
cmd = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
33-
flagCluster = cmd.String("cluster", "127.0.0.1", "a comma-separated list of host:port tuples")
34-
flagKeyspace = cmd.String("keyspace", "", "keyspace to inspect")
35-
flagPkgname = cmd.String("pkgname", "models", "the name you wish to assign to your generated package")
36-
flagOutput = cmd.String("output", "models", "the name of the folder to output to")
37-
flagUser = cmd.String("user", "", "user for password authentication")
38-
flagPassword = cmd.String("password", "", "password for password authentication")
39-
flagIgnoreNames = cmd.String("ignore-names", "", "a comma-separated list of table, view or index names to ignore")
40-
flagIgnoreIndexes = cmd.Bool("ignore-indexes", false, "don't generate types for indexes")
41-
flagQueryTimeout = cmd.Duration("query-timeout", defaultQueryTimeout, "query timeout ( in seconds )")
42-
flagConnectionTimeout = cmd.Duration("connection-timeout", defaultConnectionTimeout, "connection timeout ( in seconds )")
32+
cmd = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
33+
flagCluster = cmd.String("cluster", "127.0.0.1", "a comma-separated list of host:port tuples")
34+
flagKeyspace = cmd.String("keyspace", "", "keyspace to inspect")
35+
flagPkgname = cmd.String("pkgname", "models", "the name you wish to assign to your generated package")
36+
flagOutput = cmd.String("output", "models", "the name of the folder to output to")
37+
flagUser = cmd.String("user", "", "user for password authentication")
38+
flagPassword = cmd.String("password", "", "password for password authentication")
39+
flagIgnoreNames = cmd.String("ignore-names", "", "a comma-separated list of table, view or index names to ignore")
40+
flagIgnoreIndexes = cmd.Bool("ignore-indexes", false, "don't generate types for indexes")
41+
flagQueryTimeout = cmd.Duration("query-timeout", defaultQueryTimeout, "query timeout ( in seconds )")
42+
flagConnectionTimeout = cmd.Duration("connection-timeout", defaultConnectionTimeout, "connection timeout ( in seconds )")
43+
flagSSLEnableHostVerification = cmd.Bool("ssl-enable-host-verification", false, "don't check server ssl certificate")
44+
flagSSLCAPath = cmd.String("ssl-ca-path", "", "path to ssl CA certificates")
45+
flagSSLCertPath = cmd.String("ssl-cert-path", "", "path to ssl certificate")
46+
flagSSLKeyPath = cmd.String("ssl-key-path", "", "path to ssl key")
4347
)
4448

4549
//go:embed keyspace.tmpl
@@ -155,18 +159,30 @@ func renderTemplate(md *gocql.KeyspaceMetadata) ([]byte, error) {
155159

156160
func createSession() (gocqlx.Session, error) {
157161
cluster := gocql.NewCluster(clusterHosts()...)
162+
158163
if *flagUser != "" {
159164
cluster.Authenticator = gocql.PasswordAuthenticator{
160165
Username: *flagUser,
161166
Password: *flagPassword,
162167
}
163168
}
169+
164170
if *flagQueryTimeout >= 0 {
165171
cluster.Timeout = *flagQueryTimeout
166172
}
167173
if *flagConnectionTimeout >= 0 {
168174
cluster.ConnectTimeout = *flagConnectionTimeout
169175
}
176+
177+
if *flagSSLCAPath != "" || *flagSSLCertPath != "" || *flagSSLKeyPath != "" {
178+
cluster.SslOpts = &gocql.SslOptions{
179+
EnableHostVerification: *flagSSLEnableHostVerification,
180+
CaPath: *flagSSLCAPath,
181+
CertPath: *flagSSLCertPath,
182+
KeyPath: *flagSSLKeyPath,
183+
}
184+
}
185+
170186
return gocqlx.WrapSession(cluster.CreateSession())
171187
}
172188

0 commit comments

Comments
 (0)