Skip to content

Commit

Permalink
changing deferred functions
Browse files Browse the repository at this point in the history
  • Loading branch information
malikparvez authored and Ramesh7 committed May 31, 2023
1 parent 9ab21f1 commit c2fac17
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 46 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', :a
return_type 'Array'
end

def env(args)
args
end
end
12 changes: 0 additions & 12 deletions lib/puppet/functions/password.rb

This file was deleted.

44 changes: 10 additions & 34 deletions manifests/registry.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@

$docker_command = $docker::params::docker_command

# Use Deferred to encrypt the password
$deferred_password = Deferred('docker::password', [$password])

if $facts['os']['family'] == 'windows' {
$exec_environment = ["PATH=${facts['docker_program_files_path']}/Docker/",]
$exec_timeout = 3000
Expand All @@ -79,12 +76,12 @@
}

if $ensure == 'present' {
if $username != undef and $deferred_password != undef and $email != undef and $version != undef and $version =~ /1[.][1-9]0?/ {
if $username != undef and $password != undef and $email != undef and $version != undef and $version =~ /1[.][1-9]0?/ {
$auth_cmd = "${docker_command} login -u '${username}' -p \"${password_env}\" -e '${email}' ${server}"
$auth_environment = Deferred('docker::password', [$password])
} elsif $username != undef and $deferred_password != undef {
$auth_environment = "password=${password}"
} elsif $username != undef and $password != undef {
$auth_cmd = "${docker_command} login -u '${username}' -p \"${password_env}\" ${server}"
$auth_environment = Deferred('docker::password', [$password])
$auth_environment = "password=${password}"
} else {
$auth_cmd = "${docker_command} login ${server}"
$auth_environment = ''
Expand All @@ -94,35 +91,14 @@
$auth_environment = ''
}

#$docker_auth = "${title}${auth_environment}${auth_cmd}${local_user}"
$docker_auth = Deferred('sprintf', ['%spassword=%s%s%s',
$title,
$auth_environment,
$auth_cmd,
$local_user,
])
$docker_auth = "${title}${auth_environment}${auth_cmd}${local_user}"

if $auth_environment =~ Deferred {
$exec_env = Deferred('sprintf', ['%spassword=%sdocker_auth=%s',
$exec_environment,
$auth_environment,
$docker_auth,
]
)
if $auth_environment != '' {
$exec_env = concat($exec_environment, $auth_environment, "docker_auth=${docker_auth}")
} else {
$exec_env = Deferred('sprintf', ['%sdocker_auth=%s',
$exec_environment,
$docker_auth,
]
)
$exec_env = concat($exec_environment, "docker_auth=${docker_auth}")
}

#if $auth_environment != '' {
# $exec_env = concat($exec_environment, concat('password=',$auth_environment), "docker_auth=${docker_auth}")
#} else {
# $exec_env = concat($exec_environment, "docker_auth=${docker_auth}")
#}

if $receipt {
if $facts['os']['family'] != 'windows' {
# server may be an URI, which can contain /
Expand Down Expand Up @@ -172,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

0 comments on commit c2fac17

Please sign in to comment.