Skip to content

Commit

Permalink
Rip out support for ancient versions
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenpost committed Mar 18, 2024
1 parent 79fb374 commit 6ea7af6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 37 deletions.
9 changes: 0 additions & 9 deletions lib/puppet/provider/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,6 @@ def mongo_version
self.class.mongo_version
end

def self.mongo_26?
v = mongo_version
!v[%r{^2\.6\.}].nil?
end

def mongo_26?
self.class.mongo_26?
end

def self.mongo_4?
v = mongo_version
!v[%r{^4\.}].nil?
Expand Down
38 changes: 13 additions & 25 deletions lib/puppet/provider/mongodb_user/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,12 @@ def create
roles: role_hashes(@resource[:roles], @resource[:database]),
}

if mongo_4? || mongo_5?
if @resource[:auth_mechanism] == :scram_sha_256
command[:mechanisms] = ['SCRAM-SHA-256']
command[:pwd] = @resource[:password]
command[:digestPassword] = true
else
command[:mechanisms] = ['SCRAM-SHA-1']
command[:pwd] = password_hash
command[:digestPassword] = false
end
if @resource[:auth_mechanism] == :scram_sha_256
command[:mechanisms] = ['SCRAM-SHA-256']
command[:pwd] = @resource[:password]
command[:digestPassword] = true
else
command[:mechanisms] = ['SCRAM-SHA-1']
command[:pwd] = password_hash
command[:digestPassword] = false
end
Expand Down Expand Up @@ -110,22 +105,15 @@ def password_hash=(_value)
end
end

def password=(value)
if mongo_26?
mongo_eval("db.changeUserPassword(#{@resource[:username].to_json}, #{value.to_json})", @resource[:database])
else
command = {
updateUser: @resource[:username],
pwd: @resource[:password],
digestPassword: true
}
def password=(_value)
command = {
updateUser: @resource[:username],
pwd: @resource[:password],
digestPassword: true,
mechanisms: @resource[:auth_mechanism] == :scram_sha_256 ? ['SCRAM-SHA-256'] : ['SCRAM-SHA-1']
}

if mongo_4? || mongo_5?
command[:mechanisms] = @resource[:auth_mechanism] == :scram_sha_256 ? ['SCRAM-SHA-256'] : ['SCRAM-SHA-1']
end

mongo_eval("db.runCommand(#{command.to_json})", @resource[:database])
end
mongo_eval("db.runCommand(#{command.to_json})", @resource[:database])
end

def roles=(roles)
Expand Down
2 changes: 0 additions & 2 deletions spec/unit/puppet/provider/mongodb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

describe 'mongo version detection' do
v = {
'2.6.x' => { '26' => true, '4' => false, '5' => false },
'4.x.x' => { '26' => false, '4' => true, '5' => false },
'5.x.x' => { '26' => false, '4' => false, '5' => true },
'x.x.x' => { '26' => false, '4' => false, '5' => false }
Expand All @@ -23,7 +22,6 @@
v.each do |key, results|
it "version detection for [#{key}]" do
allow(provider_class).to receive(:mongo_eval).with('db.version()').and_return(key)
expect(provider_class.mongo_26?).to be results['26']
expect(provider_class.mongo_4?).to be results['4']
expect(provider_class.mongo_5?).to be results['5']
end
Expand Down
3 changes: 2 additions & 1 deletion spec/unit/puppet/provider/mongodb_user/mongodb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
mongodconffile = tmp.path
allow(provider.class).to receive(:mongod_conf_file).and_return(mongodconffile)
allow(provider.class).to receive(:mongo_eval).with('printjson(db.system.users.find().toArray())').and_return(raw_users)
allow(provider.class).to receive(:mongo_version).and_return('2.6.x')
allow(provider.class).to receive(:mongo_version).and_return('4.4.0')
allow(provider.class).to receive(:db_ismaster).and_return(true)
end

Expand All @@ -85,6 +85,7 @@
"createUser":"new_user",
"customData":{"createdBy":"Puppet Mongodb_user['new_user']"},
"roles":[{"role":"role1","db":"new_database"},{"role":"role2","db":"other_database"}],
"mechanisms":["SCRAM-SHA-1"],
"pwd":"pass",
"digestPassword":false
}
Expand Down

0 comments on commit 6ea7af6

Please sign in to comment.