Added allow native passwords mysql option.
This commit is contained in:
parent
10a836a08d
commit
6c5933c346
10
README.md
10
README.md
|
@ -450,7 +450,7 @@ rw int not null);
|
|||
|
||||
### Mysql
|
||||
|
||||
The `mysql` backend works almost exactly as the `postgres` one, except for a couple of configurations and that options start with `mysql_` instead of `pg_`. One change has to do with the connection protocol, either a Unix socket or tcp (options are unix or tcp). If `unix` socket is the selected protocol, then a socket path must be given:
|
||||
The `mysql` backend works almost exactly as the `postgres` one, except for a few configurations and that options start with `mysql_` instead of `pg_`. One change has to do with the connection protocol, either a Unix socket or tcp (options are unix or tcp). If `unix` socket is the selected protocol, then a socket path must be given:
|
||||
|
||||
```
|
||||
auth_opt_mysql_protocol unix
|
||||
|
@ -461,7 +461,13 @@ The default protocol when the option is missing will be `tcp`, even if a socket
|
|||
|
||||
Another change has to do with sslmode options, with options being true, false, skip-verify or custom. When custom mode is given, sslcert, sslkey and sslrootcert paths are expected. If the option is not set or one or more required paths are missing, it will default to false.
|
||||
|
||||
Also, default host `localhost` and port 3306 will be used if none are given.
|
||||
Also, default host `localhost` and port 3306 will be used if none are given.
|
||||
|
||||
To allow native passwords, set the option to true:
|
||||
|
||||
```
|
||||
auth_opt_mysql_allow_native_passwords true
|
||||
```
|
||||
|
||||
Finally, placeholders for mysql differ from those of postgres, changing from $1, $2, etc., to simply ?. So, following the postgres examples, same queries for mysql would look like these:
|
||||
|
||||
|
|
|
@ -214,6 +214,7 @@ func TestLocalMysqlJWT(t *testing.T) {
|
|||
authOpts["mysql_dbname"] = "go_auth_test"
|
||||
authOpts["mysql_user"] = "go_auth_test"
|
||||
authOpts["mysql_password"] = "go_auth_test"
|
||||
authOpts["mysql_allow_native_passwords"] = "true"
|
||||
|
||||
Convey("Given correct option NewJWT returns an instance of jwt backend", func() {
|
||||
jwt, err := NewJWT(authOpts, log.DebugLevel)
|
||||
|
|
|
@ -20,21 +20,22 @@ import (
|
|||
|
||||
//Mysql holds all fields of the Mysql db connection.
|
||||
type Mysql struct {
|
||||
DB *sqlx.DB
|
||||
Host string
|
||||
Port string
|
||||
DBName string
|
||||
User string
|
||||
Password string
|
||||
UserQuery string
|
||||
SuperuserQuery string
|
||||
AclQuery string
|
||||
SSLMode string
|
||||
SSLCert string
|
||||
SSLKey string
|
||||
SSLRootCert string
|
||||
Protocol string
|
||||
SocketPath string
|
||||
DB *sqlx.DB
|
||||
Host string
|
||||
Port string
|
||||
DBName string
|
||||
User string
|
||||
Password string
|
||||
UserQuery string
|
||||
SuperuserQuery string
|
||||
AclQuery string
|
||||
SSLMode string
|
||||
SSLCert string
|
||||
SSLKey string
|
||||
SSLRootCert string
|
||||
Protocol string
|
||||
SocketPath string
|
||||
AllowNativePasswords bool
|
||||
}
|
||||
|
||||
func NewMysql(authOpts map[string]string, logLevel log.Level) (Mysql, error) {
|
||||
|
@ -103,6 +104,10 @@ func NewMysql(authOpts map[string]string, logLevel log.Level) (Mysql, error) {
|
|||
mysql.AclQuery = aclQuery
|
||||
}
|
||||
|
||||
if allowNativePasswords, ok := authOpts["mysql_allow_native_passwords"]; ok && allowNativePasswords == "true" {
|
||||
mysql.AllowNativePasswords = true
|
||||
}
|
||||
|
||||
customSSL := false
|
||||
|
||||
if sslmode, ok := authOpts["mysql_sslmode"]; ok {
|
||||
|
@ -136,12 +141,13 @@ func NewMysql(authOpts map[string]string, logLevel log.Level) (Mysql, error) {
|
|||
}
|
||||
|
||||
var msConfig = mq.Config{
|
||||
User: mysql.User,
|
||||
Passwd: mysql.Password,
|
||||
Net: mysql.Protocol,
|
||||
Addr: fmt.Sprintf("%s:%s", mysql.Host, mysql.Port),
|
||||
DBName: mysql.DBName,
|
||||
TLSConfig: mysql.SSLMode,
|
||||
User: mysql.User,
|
||||
Passwd: mysql.Password,
|
||||
Net: mysql.Protocol,
|
||||
Addr: fmt.Sprintf("%s:%s", mysql.Host, mysql.Port),
|
||||
DBName: mysql.DBName,
|
||||
TLSConfig: mysql.SSLMode,
|
||||
AllowNativePasswords: mysql.AllowNativePasswords,
|
||||
}
|
||||
|
||||
if customSSL {
|
||||
|
|
|
@ -14,6 +14,7 @@ func TestMysql(t *testing.T) {
|
|||
authOpts["mysql_host"] = "localhost"
|
||||
authOpts["mysql_port"] = "3306"
|
||||
authOpts["mysql_protocol"] = "tcp"
|
||||
authOpts["mysql_allow_native_passwords"] = "true"
|
||||
|
||||
Convey("If mandatory params are not set initialization should fail", t, func() {
|
||||
_, err := NewMysql(authOpts, log.DebugLevel)
|
||||
|
|
Loading…
Reference in New Issue