Skip to content

Commit

Permalink
Merge pull request #918 from puppetlabs/CONT-568_deferred
Browse files Browse the repository at this point in the history
CONT-568 : Adding deferred function for password
  • Loading branch information
GSPatton authored Jul 19, 2023
2 parents 54ca950 + 845e5f7 commit 5453ccc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
12 changes: 12 additions & 0 deletions lib/puppet/functions/docker/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

Puppet::Functions.create_function(:'docker::env') do
dispatch :env do
param 'Array', :args
return_type 'Array'
end

def env(args)
args
end
end
10 changes: 5 additions & 5 deletions manifests/registry.pp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@
}
} elsif $ensure == 'present' {
exec { 'compute-hash':
command => template('docker/windows/compute_hash.ps1.erb'),
environment => $exec_env,
command => stdlib::deferrable_epp('docker/windows/compute_hash.ps1.epp', { 'passfile' => $passfile }),
environment => Deferred('docker::env', [$exec_env]),
provider => $exec_provider,
logoutput => true,
unless => template('docker/windows/check_hash.ps1.erb'),
unless => stdlib::deferrable_epp('docker/windows/check_hash.ps1.epp', { 'passfile' => $passfile }),
notify => Exec["${title} auth"],
}
}
Expand All @@ -148,8 +148,8 @@
}

exec { "${title} auth":
environment => $exec_env,
command => $_auth_command,
environment => Deferred('docker::env', [$exec_env]),
command => Deferred('sprintf', [$_auth_command]),
user => $exec_user,
path => $exec_path,
timeout => $exec_timeout,
Expand Down
11 changes: 11 additions & 0 deletions spec/functions/env_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'docker::env' do
it { is_expected.to run.with_params([4]).and_return([4]) }
it { is_expected.to run.with_params([4, 5, '3']).and_return([4, 5, '3']) }
it { is_expected.to run.with_params(2).and_raise_error(StandardError) }
it { is_expected.to run.with_params('string').and_raise_error(StandardError) }
it { is_expected.to run.with_params(nil).and_raise_error(StandardError) }
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ $StringBuilder = New-Object System.Text.StringBuilder
[Void]$StringBuilder.Append($_.ToString("x2"))
}

if([System.IO.File]::Exists("<%= @passfile %>")){
$CurrentContent = Get-Content -Path "<%= @passfile %>"
if([System.IO.File]::Exists("<%= $passfile %>")){
$CurrentContent = Get-Content -Path "<%= $passfile %>"
if($CurrentContent -eq $StringBuilder.ToString()){
exit 0
}
}

exit 1
exit 1
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ $StringBuilder = New-Object System.Text.StringBuilder
[Void]$StringBuilder.Append($_.ToString("x2"))
}

$StringBuilder.ToString() | Out-File <%= @passfile %>
$StringBuilder.ToString() | Out-File <%= $passfile %>

0 comments on commit 5453ccc

Please sign in to comment.