Skip to content

Commit

Permalink
cleanup unused code and debug lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan De Wit committed Aug 17, 2023
1 parent d70d9f8 commit 639bada
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 32 deletions.
31 changes: 4 additions & 27 deletions lib/puppet/provider/mongodb_replset/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def master_host(members)
end

def self.replset_properties
Puppet.debug('XXXXXXXXX in replset_properties')
conn_string = conn_string # rubocop:disable Lint/SelfAssignment
begin
output = mongo_command('rs.conf()', conn_string)
Expand All @@ -147,7 +146,6 @@ def self.replset_properties
rescue Puppet::ExecutionFailure => e
#if e.message =~ %r{command replSetGetConfig requires authentication} || e.message =~ %r{not authorized on admin to execute command} || e.message =~ %r{no replset config has been received}

Check failure on line 147 in lib/puppet/provider/mongodb_replset/mongo.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/LeadingCommentSpace: Missing space after `#`. (https://rubystyle.guide#hash-space)
if e.message =~ %r{command replSetGetConfig requires authentication} || e.message =~ %r{not authorized on admin to execute command}
Puppet.debug('XXXXXXXXX in replset_properties rescue part')
output = mongo_command('rs.status()', conn_string)
if output['members']
memb = []
Expand All @@ -173,21 +171,8 @@ def get_hosts_status(members)
Puppet.debug "Checking replicaset member #{host} ..."
begin
status = rs_status(host)
Puppet.debug('XXXXXXXXXXXXXX should not get here since I dont have a replicaset')
raise Puppet::Error, "Can't configure replicaset #{name}, host #{host} is not supposed to be part of a replicaset." if status.key?('errmsg') && status['errmsg'] == 'not running with --replSet'

# if auth_enabled && status.key?('errmsg')
# Puppet.debug "In auth_enabled && status.key?('errmsg')"
# if status['errmsg'].include?('requires authentication') || status['errmsg'].include?('not authorized on admin') || status['errmsg'].include?('Authentication failed')
# Puppet.debug "In auth_enabled && status.key?('errmsg') need authentication"
# Puppet.warning "Host #{host} is available, but you are unauthorized because of authentication is enabled: #{auth_enabled}"
# alive.push(member)
# elsif status['errmsg'].include?('no replset config has been received')
# Puppet.debug 'Mongo rs.status() RS not initialized output'
# alive.push(member)
# end
# end

if status.key?('set')
raise Puppet::Error, "Can't configure replicaset #{name}, host #{host} is already part of another replicaset." if status['set'] != name

Expand All @@ -199,7 +184,6 @@ def get_hosts_status(members)
alive.push(member)
end
rescue Puppet::ExecutionFailure => e
Puppet.debug('XXXXXXXXXXXX in rescue checking connection mebers')
if auth_enabled
case e.message
when %r{no replset config has been received}
Expand Down Expand Up @@ -425,17 +409,10 @@ def mongo_command(command, host, retries = 4)
end

def self.mongo_command(command, host = nil, retries = 4)
#begin
output = mongo_eval("EJSON.stringify(#{command})", 'admin', retries, host)
#rescue Puppet::ExecutionFailure => e
#if e.message =~ %r{no replset config has been received} || e.message =~ %r{Authentication failed}
if output =~ %r{no replset config has been received} || output =~ %r{Authentication failed}
output = '{}'
# else
# Puppet.debug "Got an exception: #{e}"
# raise
end
#end
output = mongo_eval("EJSON.stringify(#{command})", 'admin', retries, host)
if output =~ %r{no replset config has been received} || output =~ %r{Authentication failed}

Check failure on line 413 in lib/puppet/provider/mongodb_replset/mongo.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/IfUnlessModifier: Favor modifier `if` usage when having a single-line body. Another good alternative is the usage of control flow `&&`/`||`. (https://rubystyle.guide#if-as-a-modifier)
output = '{}'
end

# Hack to avoid non-json empty sets
output = '{}' if output == "null\n"
Expand Down
5 changes: 0 additions & 5 deletions lib/puppet/provider/mongodb_user/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def self.instances

users = JSON.parse out

Puppet.debug("XXXXXXXX In self.instances, retrieved users: #{users}")

users.map do |user|
db = if user['db'] == '$external'
# For external users, we need to retreive the original DB name from here.
Expand All @@ -44,7 +42,6 @@ def self.instances

# Assign prefetched users based on username and database, not on id and name
def self.prefetch(resources)
Puppet.debug("XXXXXXXXXXX in prefetch: got following instances: #{instances}")
users = instances
resources.each do |name, resource|
provider = users.find { |user| user.username == resource[:username] && user.database == resource[:database] }
Expand Down Expand Up @@ -84,10 +81,8 @@ def create
end

if @resource[:auth_mechanism] == :x509
Puppet.debug("XXXXXXXXXX about to create X509 user with command: #{command}")
mongo_eval("db.getSiblingDB(\"$external\").runCommand(#{command.to_json})", @resource[:database])
else
Puppet.debug("XXXXXXXXXX about to create regular user with command: #{command}")
mongo_eval("db.runCommand(#{command.to_json})", @resource[:database])
end
else
Expand Down

0 comments on commit 639bada

Please sign in to comment.