Skip to content

Commit

Permalink
add mechanisms attribute during fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan De Wit committed Jan 10, 2024
1 parent c1ba3d7 commit 6e3c95a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/puppet/provider/mongodb_user/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ def self.instances
Puppet.debug("Fetching user #{user}")
db = if user['db'] == '$external'
# For external users, we need to retreive the original DB name from here.
user['customData']['createdBy'][%r{.*on db (.*)'\]$}, 1]
user['customData']['createdBy'][%r{.* (.*)'\]$}, 1]
else
user['db']
end
new(name: user['_id'],
u = new(name: user['_id'],
ensure: :present,
username: user['user'],
database: db,
roles: from_roles(user['roles'], db),
password_hash: user['credentials']['MONGODB-CR'],
scram_credentials: user['credentials']['SCRAM-SHA-1'])
Puppet.debug("Fetching users, creating the found resources: #{u}")
u
end
else
Puppet.warning 'User info is available only from master host'
Expand All @@ -57,6 +59,7 @@ def create
password_hash = @resource[:password_hash]
password_hash = Puppet::Util::MongodbMd5er.md5(@resource[:username], @resource[:password]) if !password_hash && @resource[:password]


command = {
createUser: @resource[:username],
customData: {
Expand Down Expand Up @@ -88,8 +91,6 @@ def create
Puppet.debug("Creating user for with command #{command}")
mongo_eval("db.runCommand(#{command.to_json})", @resource[:database])
end
else
Puppet.warning 'User creation is available only from master host'

@property_hash[:ensure] = :present
@property_hash[:username] = @resource[:username]
Expand All @@ -98,6 +99,9 @@ def create
@property_hash[:roles] = @resource[:roles]

exists?

else
Puppet.warning 'User creation is available only from master host'
end
end

Expand Down

0 comments on commit 6e3c95a

Please sign in to comment.