Skip to content

Commit 845e5f7

Browse files
committed
CONT-568 : Adding deferred function for password
1 parent 54ca950 commit 845e5f7

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

lib/puppet/functions/docker/env.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
Puppet::Functions.create_function(:'docker::env') do
4+
dispatch :env do
5+
param 'Array', :args
6+
return_type 'Array'
7+
end
8+
9+
def env(args)
10+
args
11+
end
12+
end

manifests/registry.pp

+5-5
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@
134134
}
135135
} elsif $ensure == 'present' {
136136
exec { 'compute-hash':
137-
command => template('docker/windows/compute_hash.ps1.erb'),
138-
environment => $exec_env,
137+
command => stdlib::deferrable_epp('docker/windows/compute_hash.ps1.epp', { 'passfile' => $passfile }),
138+
environment => Deferred('docker::env', [$exec_env]),
139139
provider => $exec_provider,
140140
logoutput => true,
141-
unless => template('docker/windows/check_hash.ps1.erb'),
141+
unless => stdlib::deferrable_epp('docker/windows/check_hash.ps1.epp', { 'passfile' => $passfile }),
142142
notify => Exec["${title} auth"],
143143
}
144144
}
@@ -148,8 +148,8 @@
148148
}
149149

150150
exec { "${title} auth":
151-
environment => $exec_env,
152-
command => $_auth_command,
151+
environment => Deferred('docker::env', [$exec_env]),
152+
command => Deferred('sprintf', [$_auth_command]),
153153
user => $exec_user,
154154
path => $exec_path,
155155
timeout => $exec_timeout,

spec/functions/env_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'docker::env' do
6+
it { is_expected.to run.with_params([4]).and_return([4]) }
7+
it { is_expected.to run.with_params([4, 5, '3']).and_return([4, 5, '3']) }
8+
it { is_expected.to run.with_params(2).and_raise_error(StandardError) }
9+
it { is_expected.to run.with_params('string').and_raise_error(StandardError) }
10+
it { is_expected.to run.with_params(nil).and_raise_error(StandardError) }
11+
end

templates/windows/check_hash.ps1.erb renamed to templates/windows/check_hash.ps1.epp

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ $StringBuilder = New-Object System.Text.StringBuilder
77
[Void]$StringBuilder.Append($_.ToString("x2"))
88
}
99

10-
if([System.IO.File]::Exists("<%= @passfile %>")){
11-
$CurrentContent = Get-Content -Path "<%= @passfile %>"
10+
if([System.IO.File]::Exists("<%= $passfile %>")){
11+
$CurrentContent = Get-Content -Path "<%= $passfile %>"
1212
if($CurrentContent -eq $StringBuilder.ToString()){
1313
exit 0
1414
}
1515
}
1616

17-
exit 1
17+
exit 1

templates/windows/compute_hash.ps1.erb renamed to templates/windows/compute_hash.ps1.epp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ $StringBuilder = New-Object System.Text.StringBuilder
77
[Void]$StringBuilder.Append($_.ToString("x2"))
88
}
99

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

0 commit comments

Comments
 (0)