Add 'auth_plugin' option (#389)

This commit is contained in:
Mackenzie Boyd
2019-10-23 03:19:23 -07:00
committed by Inada Naoki
parent 17045e8ed0
commit acf4cdcf89
2 changed files with 14 additions and 3 deletions

View File

@ -398,6 +398,7 @@ _mysql_ConnectionObject_Initialize(
"client_flag", "ssl", "client_flag", "ssl",
"local_infile", "local_infile",
"read_timeout", "write_timeout", "charset", "read_timeout", "write_timeout", "charset",
"auth_plugin",
NULL } ; NULL } ;
int connect_timeout = 0; int connect_timeout = 0;
int read_timeout = 0; int read_timeout = 0;
@ -406,13 +407,14 @@ _mysql_ConnectionObject_Initialize(
char *init_command=NULL, char *init_command=NULL,
*read_default_file=NULL, *read_default_file=NULL,
*read_default_group=NULL, *read_default_group=NULL,
*charset=NULL; *charset=NULL,
*auth_plugin=NULL;
self->converter = NULL; self->converter = NULL;
self->open = 0; self->open = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"|ssssisOiiisssiOiiis:connect", "|ssssisOiiisssiOiiiss:connect",
kwlist, kwlist,
&host, &user, &passwd, &db, &host, &user, &passwd, &db,
&port, &unix_socket, &conv, &port, &unix_socket, &conv,
@ -424,7 +426,8 @@ _mysql_ConnectionObject_Initialize(
&local_infile, &local_infile,
&read_timeout, &read_timeout,
&write_timeout, &write_timeout,
&charset &charset,
&auth_plugin
)) ))
return -1; return -1;
@ -491,6 +494,9 @@ _mysql_ConnectionObject_Initialize(
if (charset) { if (charset) {
mysql_options(&(self->connection), MYSQL_SET_CHARSET_NAME, charset); mysql_options(&(self->connection), MYSQL_SET_CHARSET_NAME, charset);
} }
if (auth_plugin) {
mysql_options(&(self->connection), MYSQL_DEFAULT_AUTH, auth_plugin);
}
conn = mysql_real_connect(&(self->connection), host, user, passwd, db, conn = mysql_real_connect(&(self->connection), host, user, passwd, db,
port, unix_socket, client_flag); port, unix_socket, client_flag);

View File

@ -86,6 +86,11 @@ class Connection(_mysql.connection):
On Python 2, this option changes default value of `use_unicode` On Python 2, this option changes default value of `use_unicode`
option from False to True. option from False to True.
:param str auth_plugin:
If supplied, the connection default authentication plugin will be
changed to this value. Example values:
`mysql_native_password` or `caching_sha2_password`
:param str sql_mode: :param str sql_mode:
If supplied, the session SQL mode will be changed to this If supplied, the session SQL mode will be changed to this
setting. setting.