Skip to content
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

Dynamic Password Provider #1370

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]
$ brew install [email protected] zstd
$ gem install mysql2 -- --with-openssl-dir=$(brew --prefix [email protected])

or
Expand Down
2 changes: 1 addition & 1 deletion ci/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ext/mysql2/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion lib/mysql2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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_')
Expand Down
2 changes: 2 additions & 0 deletions mysql2.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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