From 3e151149a0a2240fca1b1e5d173214a029b25c99 Mon Sep 17 00:00:00 2001 From: Niklas Semmler Date: Thu, 30 Jun 2022 13:07:15 +0200 Subject: [PATCH] add user password authentication to schemagen --- cmd/schemagen/schemagen.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/schemagen/schemagen.go b/cmd/schemagen/schemagen.go index d54b747..27266fd 100644 --- a/cmd/schemagen/schemagen.go +++ b/cmd/schemagen/schemagen.go @@ -24,6 +24,8 @@ var ( 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") ) var ( @@ -92,6 +94,12 @@ func renderTemplate(md *gocql.KeyspaceMetadata) ([]byte, error) { func createSession() (gocqlx.Session, error) { cluster := gocql.NewCluster(clusterHosts()...) + if *flagUser != "" { + cluster.Authenticator = gocql.PasswordAuthenticator{ + Username: *flagUser, + Password: *flagPassword, + } + } return gocqlx.WrapSession(cluster.CreateSession()) }