Skip to content

Commit dacf12f

Browse files
committed
fixe check_all_attributes
1 parent 85a1db3 commit dacf12f

File tree

4 files changed

+22
-65
lines changed

4 files changed

+22
-65
lines changed

lib/puppet/provider/archive/ruby.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,16 @@ def environment
293293
envlist = [envlist] unless envlist.is_a? Array
294294
envlist.each do |setting|
295295
unless (match = %r{^(\w+)=((.|\n)*)$}.match(setting))
296-
warning format(_('Cannot understand environment setting %{setting}'), setting: setting.inspect)
296+
warning "Cannot understand environment setting #{setting.inspect}"
297297
next
298298
end
299299
var = match[1]
300300
value = match[2]
301301

302-
warning format(_("Overriding environment setting '%{var}' with '%{value}'"), var: var, value: value) if env.include?(var) || env.include?(var.to_sym)
302+
warning "Overriding environment setting '#{var}' with '#{value}'" if env.include?(var) || env.include?(var.to_sym)
303303

304304
if value.nil? || value.empty?
305-
msg = format(_("Empty environment setting '%{var}'"), var: var)
305+
msg = "Empty environment setting '#{var}'"
306306
Puppet.warn_once('undefined_variables', "empty_env_var_#{var}", msg, resource.file, resource.line)
307307
end
308308

@@ -364,6 +364,6 @@ def extractexe(command)
364364
def validatecmd(command)
365365
exe = extractexe(command)
366366
# if we're not fully qualified, require a path
367-
self.fail format(_("'%{exe}' is not qualified and no path was specified. Please qualify the command or specify a path."), exe: exe) if !absolute_path?(exe) && resource[:path].nil?
367+
self.fail "'#{exe}' is not qualified and no path was specified. Please qualify the command or specify a path." if !absolute_path?(exe) && resource[:path].nil?
368368
end
369369
end

lib/puppet/type/archive.rb

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def value=(*values)
294294
def check(value)
295295
# TRANSLATORS 'creates' is a parameter name and should not be translated
296296
debug("Checking that 'creates' path '#{value}' exists")
297-
Puppet::FileSystem.exist?(value)
297+
! Puppet::FileSystem.exist?(value)
298298
end
299299
end
300300

@@ -457,7 +457,7 @@ def check(value)
457457
# Verify that we pass all of the checks. The argument determines whether
458458
# we skip the :refreshonly check, which is necessary because we now check
459459
# within refresh
460-
def check_all_attributes(_refreshing = false)
460+
def check_all_attributes
461461
self.class.checks.each do |check|
462462
next unless @parameters.include?(check)
463463

@@ -470,54 +470,11 @@ def check_all_attributes(_refreshing = false)
470470
# but don't print sensitive commands or parameters in the clear
471471
sourcestring = @parameters[:source].sensitive ? '[command redacted]' : @parameters[:source].value
472472

473-
debug(format("'%{source}' won't be executed because of failed check '%{check}'", source: sourcestring, check: check))
473+
debug("'#{sourcestring}' won't be executed because of failed check '#{check}'")
474474

475-
return false
476-
end
477-
end
478-
true
479-
end
480-
481-
def output
482-
if property(:returns).nil?
483-
nil
484-
else
485-
property(:returns).output
486-
end
487-
end
488-
489-
# Run the command, or optionally run a separately-specified command.
490-
def refresh
491-
return unless check_all_attributes(true)
492-
493-
cmd = self[:refresh]
494-
if cmd
495-
provider.run(cmd)
496-
else
497-
property(:returns).sync
498-
end
499-
end
500-
501-
private
502-
503-
def set_sensitive_parameters(sensitive_parameters)
504-
# If any are sensitive, mark all as sensitive
505-
sensitive = false
506-
parameters_to_check = %i[command unless onlyif]
507-
508-
parameters_to_check.each do |p|
509-
if sensitive_parameters.include?(p)
510-
sensitive_parameters.delete(p)
511-
sensitive = true
475+
return true
512476
end
513477
end
514-
515-
if sensitive
516-
parameters_to_check.each do |p|
517-
parameter(p).sensitive = true if parameters.include?(p)
518-
end
519-
end
520-
521-
super(sensitive_parameters)
478+
false
522479
end
523480
end

spec/acceptance/authentication_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
context 'authenticated download' do
77
let(:source) do
88
parser = URI::RFC2396_Parser.new
9-
parser.escape("http://httpbin.org/basic-auth/user/#{password}")
9+
parser.escape("https://httpbin.org/basic-auth/user/#{password}")
1010
end
1111
let(:pp) do
1212
<<-EOS

spec/unit/puppet/type/archive_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,41 +245,41 @@
245245
context 'with a single item' do
246246
it 'runs if the command exits non-zero' do
247247
resource[param] = cmd_fail
248-
expect(resource.check_all_attributes).to be(true)
248+
expect(resource.check_all_attributes).to be(false)
249249
end
250250

251251
it 'does not run if the command exits zero' do
252252
resource[param] = cmd_pass
253-
expect(resource.check_all_attributes).to be(false)
253+
expect(resource.check_all_attributes).to be(true)
254254
end
255255
end
256256

257257
context 'with an array with a single item' do
258258
it 'runs if the command exits non-zero' do
259259
resource[param] = [cmd_fail]
260-
expect(resource.check_all_attributes).to be(true)
260+
expect(resource.check_all_attributes).to be(false)
261261
end
262262

263263
it 'does not run if the command exits zero' do
264264
resource[param] = [cmd_pass]
265-
expect(resource.check_all_attributes).to be(false)
265+
expect(resource.check_all_attributes).to be(true)
266266
end
267267
end
268268

269269
context 'with an array with multiple items' do
270270
it 'runs if all the commands exits non-zero' do
271271
resource[param] = [cmd_fail] * 3
272-
expect(resource.check_all_attributes).to be(true)
272+
expect(resource.check_all_attributes).to be(false)
273273
end
274274

275275
it 'does not run if one command exits zero' do
276276
resource[param] = [cmd_pass, cmd_fail, cmd_pass]
277-
expect(resource.check_all_attributes).to be(false)
277+
expect(resource.check_all_attributes).to be(true)
278278
end
279279

280280
it 'does not run if all command exits zero' do
281281
resource[param] = [cmd_pass] * 3
282-
expect(resource.check_all_attributes).to be(false)
282+
expect(resource.check_all_attributes).to be(true)
283283
end
284284
end
285285

@@ -299,32 +299,32 @@
299299

300300
it 'runs if all the commands exits non-zero' do
301301
resource[param] = [[cmd_fail, '--flag'], [cmd_fail], [cmd_fail, '--flag']]
302-
expect(resource.check_all_attributes).to be(true)
302+
expect(resource.check_all_attributes).to be(false)
303303
end
304304

305305
it 'does not run if one command exits zero' do
306306
resource[param] = [[cmd_pass, '--flag'], [cmd_pass], [cmd_fail, '--flag']]
307-
expect(resource.check_all_attributes).to be(false)
307+
expect(resource.check_all_attributes).to be(true)
308308
end
309309

310310
it 'does not run if all command exits zero' do
311311
resource[param] = [[cmd_pass, '--flag'], [cmd_pass], [cmd_pass, '--flag']]
312-
expect(resource.check_all_attributes).to be(false)
312+
expect(resource.check_all_attributes).to be(true)
313313
end
314314
end
315315

316316
it 'emits output to debug' do
317317
Puppet::Util::Log.level = :debug
318318
resource[param] = cmd_fail
319-
expect(resource.check_all_attributes).to be(true)
319+
expect(resource.check_all_attributes).to be(false)
320320
expect(@logs.shift.message).to eq('test output')
321321
end
322322

323323
it 'does not emit output to debug if sensitive is true' do
324324
Puppet::Util::Log.level = :debug
325325
resource[param] = cmd_fail
326326
allow(resource.parameters[param]).to receive(:sensitive).and_return(true)
327-
expect(resource.check_all_attributes).to be(true)
327+
expect(resource.check_all_attributes).to be(false)
328328
expect(@logs).not_to include(an_object_having_attributes(level: :debug, message: 'test output'))
329329
expect(@logs).to include(an_object_having_attributes(level: :debug, message: '[output redacted]'))
330330
end

0 commit comments

Comments
 (0)