|
47 | 47 |
|
48 | 48 | $docker_command = $docker::params::docker_command
|
49 | 49 |
|
| 50 | + if $::osfamily == 'windows' { |
| 51 | + $exec_environment = ['PATH=C:/Program Files/Docker/'] |
| 52 | + $exec_timeout = 3000 |
| 53 | + $exec_path = ['c:/Windows/Temp/', 'C:/Program Files/Docker/'] |
| 54 | + $exec_provider = 'powershell' |
| 55 | + $password_env = '$env:password' |
| 56 | + } else { |
| 57 | + $exec_environment = ['HOME=/root'] |
| 58 | + $exec_path = ['/bin', '/usr/bin'] |
| 59 | + $exec_timeout = 0 |
| 60 | + $exec_provider = undef |
| 61 | + $password_env = "\${password}" |
| 62 | + } |
| 63 | + |
50 | 64 | if $ensure == 'present' {
|
51 | 65 | if $username != undef and $password != undef and $email != undef and $version != undef and $version =~ /1[.][1-9]0?/ {
|
52 |
| - $auth_cmd = "${docker_command} login -u '${username}' -p \"\${password}\" -e '${email}' ${server}" |
| 66 | + $auth_cmd = "${docker_command} login -u '${username}' -p '${password_env}' -e '${email}' ${server}" |
53 | 67 | $auth_environment = "password=${password}"
|
54 | 68 | }
|
55 | 69 | elsif $username != undef and $password != undef {
|
56 |
| - $auth_cmd = "${docker_command} login -u '${username}' -p \"\${password}\" ${server}" |
| 70 | + $auth_cmd = "${docker_command} login -u '${username}' -p ${password_env} ${server}" |
57 | 71 | $auth_environment = "password=${password}"
|
58 | 72 | }
|
59 | 73 | else {
|
60 | 74 | $auth_cmd = "${docker_command} login ${server}"
|
61 |
| - $auth_environment = undef |
| 75 | + $auth_environment = '' |
62 | 76 | }
|
63 | 77 | }
|
64 | 78 | else {
|
65 | 79 | $auth_cmd = "${docker_command} logout ${server}"
|
66 |
| - $auth_environment = undef |
| 80 | + $auth_environment = '' |
67 | 81 | }
|
68 | 82 |
|
69 | 83 | if $receipt {
|
70 |
| - # no - with pw_hash |
71 |
| - $local_user_strip = regsubst($local_user, '-', '', 'G') |
72 |
| - |
73 |
| - $_pass_hash = $pass_hash ? { |
74 |
| - Undef => pw_hash("${title}${auth_environment}${auth_cmd}${local_user}", 'SHA-512', $local_user_strip), |
75 |
| - default => $pass_hash |
76 |
| - } |
77 | 84 |
|
78 | 85 | # server may be an URI, which can contain /
|
79 | 86 | $server_strip = regsubst($server, '/', '_', 'G')
|
80 |
| - $_auth_command = "${auth_cmd} || rm -f \"/root/registry-auth-puppet_receipt_${server_strip}_${local_user}\"" |
81 | 87 |
|
82 |
| - file { "/root/registry-auth-puppet_receipt_${server_strip}_${local_user}": |
83 |
| - ensure => $ensure, |
84 |
| - content => $_pass_hash, |
85 |
| - notify => Exec["${title} auth"], |
| 88 | + if $::osfamily != 'windows' { |
| 89 | + # no - with pw_hash |
| 90 | + $local_user_strip = regsubst($local_user, '-', '', 'G') |
| 91 | + |
| 92 | + $_pass_hash = $pass_hash ? { |
| 93 | + Undef => pw_hash("${title}${auth_environment}${auth_cmd}${local_user}", 'SHA-512', $local_user_strip), |
| 94 | + default => $pass_hash |
| 95 | + } |
| 96 | + $_auth_command = "${auth_cmd} || rm -f \"/root/registry-auth-puppet_receipt_${server_strip}_${local_user}\"" |
| 97 | + |
| 98 | + file { "/root/registry-auth-puppet_receipt_${server_strip}_${local_user}": |
| 99 | + ensure => $ensure, |
| 100 | + content => $_pass_hash, |
| 101 | + notify => Exec["${title} auth"], |
| 102 | + } |
| 103 | + } else { |
| 104 | + $pass = "${title}${auth_environment}${auth_cmd}${local_user}" |
| 105 | + $_auth_command = $auth_cmd |
| 106 | + $pw_hash_path = 'C:/Windows/Temp/compute_hash.ps1' |
| 107 | + $passfile = "C:/Windows/Temp/registry-auth-puppet_receipt_${server_strip}_${local_user}" |
| 108 | + file{ $pw_hash_path: |
| 109 | + ensure => present, |
| 110 | + force => true, |
| 111 | + content => template('docker/windows/compute_hash.ps1.erb'), |
| 112 | + notify => Exec['compute-hash'] |
| 113 | + } |
| 114 | + exec { 'compute-hash': |
| 115 | + command => "& ${pw_hash_path}", |
| 116 | + provider => $exec_provider, |
| 117 | + refreshonly => true, |
| 118 | + logoutput => true, |
| 119 | + notify => Exec["${title} auth"], |
| 120 | + } |
86 | 121 | }
|
87 | 122 | }
|
88 | 123 | else {
|
89 | 124 | $_auth_command = $auth_cmd
|
90 | 125 | }
|
91 | 126 |
|
92 | 127 | exec { "${title} auth":
|
93 |
| - environment => $auth_environment, |
| 128 | + environment => concat($exec_environment, $auth_environment), |
94 | 129 | command => $_auth_command,
|
95 |
| - user => $local_user, |
96 |
| - cwd => '/root', |
97 |
| - path => ['/bin', '/usr/bin'], |
98 |
| - timeout => 0, |
| 130 | + #user => $local_user, |
| 131 | + path => $exec_path, |
| 132 | + timeout => $exec_timeout, |
| 133 | + provider => $exec_provider, |
99 | 134 | refreshonly => $receipt,
|
100 | 135 | }
|
101 | 136 |
|
|
0 commit comments