Add defaults to the cassandra databse type

This commit is contained in:
Brian Kassouf 2017-03-07 17:00:52 -08:00
parent 3976a2a0a6
commit b7c3b4b0d7
2 changed files with 13 additions and 2 deletions

View File

@ -45,8 +45,17 @@ func (c *Cassandra) CreateUser(statements Statements, username, password, expira
return err
}
creationCQL := statements.CreationStatements
if creationCQL == "" {
creationCQL = defaultCreationCQL
}
rollbackCQL := statements.RollbackStatements
if rollbackCQL == "" {
rollbackCQL = defaultRollbackCQL
}
// Execute each query
for _, query := range strutil.ParseArbitraryStringSlice(statements.CreationStatements, ";") {
for _, query := range strutil.ParseArbitraryStringSlice(creationCQL, ";") {
query = strings.TrimSpace(query)
if len(query) == 0 {
continue
@ -57,7 +66,7 @@ func (c *Cassandra) CreateUser(statements Statements, username, password, expira
"password": password,
})).Exec()
if err != nil {
for _, query := range strutil.ParseArbitraryStringSlice(statements.RollbackStatements, ";") {
for _, query := range strutil.ParseArbitraryStringSlice(rollbackCQL, ";") {
query = strings.TrimSpace(query)
if len(query) == 0 {
continue

View File

@ -94,6 +94,8 @@ type DatabaseConfig struct {
MaxConnectionLifetime time.Duration `json:"max_connection_lifetime" structs:"max_connection_lifetime" mapstructure:"max_connection_lifetime"`
}
// Statments set in role creation and passed into the database type's functions.
// TODO: Add a way of setting defaults here.
type Statements struct {
CreationStatements string `json:"creation_statments" mapstructure:"creation_statements" structs:"creation_statments"`
RevocationStatements string `json:"revocation_statements" mapstructure:"revocation_statements" structs:"revocation_statements"`