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