Skip to content

Dynamic Password Provider #1370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ jobs:
- {os: ubuntu-22.04, ruby: '3.0', db: mariadb10.6}
- {os: ubuntu-20.04, ruby: '2.7', db: mariadb10.6}
- {os: ubuntu-20.04, ruby: '2.7', db: mysql80}
- {os: ubuntu-18.04, ruby: '2.7', db: mysql57}
# - {os: ubuntu-18.04, ruby: '2.7', db: mysql57} # no longer exists

# TODO - Windows CI
# - {os: windows-2022, ruby: '3.2', db: mysql80}
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ Metrics/BlockNesting:
# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 135
Max: 141

# Offense count: 3
# Configuration parameters: IgnoredMethods.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ Ruby runtime and MySQL client libraries are compiled with the same OpenSSL
family, 1.0 or 1.1 or 3.0, since only one can be loaded at runtime.

``` sh
$ brew install openssl@1.1
$ brew install openssl@1.1 zstd
$ gem install mysql2 -- --with-openssl-dir=$(brew --prefix openssl@1.1)

or
2 changes: 1 addition & 1 deletion ci/setup.sh
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ if [[ x$OSTYPE =~ ^xdarwin ]]; then
done

brew info "$DB"
brew install "$DB"
brew install "$DB" zstd
DB_PREFIX="$(brew --prefix "${DB}")"
export PATH="${DB_PREFIX}/bin:${PATH}"
export LDFLAGS="-L${DB_PREFIX}/lib"
2 changes: 1 addition & 1 deletion ext/mysql2/extconf.rb
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ def add_ssl_defines(header)
warn "-----\nUsing --with-mysql-dir=#{File.dirname inc}\n-----"
rpath_dir = lib
have_library('mysqlclient')
elsif (mc = (with_config('mysql-config') || Dir[GLOB].first))
elsif (mc = with_config('mysql-config') || Dir[GLOB].first)
# If the user has provided a --with-mysql-config argument, we must respect it or fail.
# If the user gave --with-mysql-config with no argument means we should try to find it.
mc = Dir[GLOB].first if mc == true
11 changes: 10 additions & 1 deletion lib/mysql2/client.rb
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ def initialize(opts = {})
end

user = opts[:username] || opts[:user]
pass = opts[:password] || opts[:pass]
pass = extract_password(opts)
host = opts[:host] || opts[:hostname]
port = opts[:port]
database = opts[:database] || opts[:dbname] || opts[:db]
@@ -97,6 +97,15 @@ def initialize(opts = {})
connect user, pass, host, port, database, socket, flags, conn_attrs
end

def extract_password(opts)
return opts[:password] || opts[:pass] unless opts[:password_provider]

klass = Kernel.const_get(opts[:password_provider])

obj = klass.new(opts)
obj.password
end

def parse_ssl_mode(mode)
m = mode.to_s.upcase
if m.start_with?('SSL_MODE_')
2 changes: 2 additions & 0 deletions mysql2.gemspec
Original file line number Diff line number Diff line change
@@ -22,4 +22,6 @@ Mysql2::GEMSPEC = Gem::Specification.new do |s|
s.files = `git ls-files README.md CHANGELOG.md LICENSE ext lib support`.split

s.metadata['msys2_mingw_dependencies'] = 'libmariadbclient'

s.add_dependency 'bigdecimal'
end