Add comments to connection and credential producers

This commit is contained in:
Brian Kassouf 2017-03-28 13:08:11 -07:00
parent b09526e1c9
commit 50729a4528
2 changed files with 12 additions and 3 deletions

View file

@ -23,6 +23,9 @@ var (
errNotInitalized = errors.New("connection has not been initalized")
)
// ConnectionProducer can be used as an embeded interface in the DatabaseType
// definition. It implements the methods dealing with individual database
// connections and is used in all the builtin database types.
type ConnectionProducer interface {
Close() error
Initialize(map[string]interface{}) error
@ -31,7 +34,7 @@ type ConnectionProducer interface {
connection() (interface{}, error)
}
// sqlConnectionProducer impliments ConnectionProducer and provides a generic producer for most sql databases
// sqlConnectionProducer implements ConnectionProducer and provides a generic producer for most sql databases
type sqlConnectionProducer struct {
ConnectionURL string `json:"connection_url" structs:"connection_url" mapstructure:"connection_url"`
@ -111,6 +114,8 @@ func (c *sqlConnectionProducer) Close() error {
return nil
}
// cassandraConnectionProducer implements ConnectionProducer and provides an
// interface for cassandra databases to make connections.
type cassandraConnectionProducer struct {
Hosts string `json:"hosts" structs:"hosts" mapstructure:"hosts"`
Username string `json:"username" structs:"username" mapstructure:"username"`

View file

@ -8,20 +8,22 @@ import (
uuid "github.com/hashicorp/go-uuid"
)
// CredentialsProducer can be used as an embeded interface in the DatabaseType
// definition. It implements the methods for generating user information for a
// particular database type and is used in all the builtin database types.
type CredentialsProducer interface {
GenerateUsername(displayName string) (string, error)
GeneratePassword() (string, error)
GenerateExpiration(ttl time.Duration) (string, error)
}
// sqlCredentialsProducer impliments CredentialsProducer and provides a generic credentials producer for most sql database types.
// sqlCredentialsProducer implements CredentialsProducer and provides a generic credentials producer for most sql database types.
type sqlCredentialsProducer struct {
displayNameLen int
usernameLen int
}
func (scp *sqlCredentialsProducer) GenerateUsername(displayName string) (string, error) {
// Generate the username, password and expiration. PG limits user to 63 characters
if scp.displayNameLen > 0 && len(displayName) > scp.displayNameLen {
displayName = displayName[:scp.displayNameLen]
}
@ -52,6 +54,8 @@ func (scp *sqlCredentialsProducer) GenerateExpiration(ttl time.Duration) (string
Format("2006-01-02 15:04:05-0700"), nil
}
// cassandraCredentialsProducer implements CredentialsProducer and provides an
// interface for cassandra databases to generate user information.
type cassandraCredentialsProducer struct{}
func (ccp *cassandraCredentialsProducer) GenerateUsername(displayName string) (string, error) {