3 # Define resource to retrieve files to staging directories. It is
4 # intententionally not replacing files, as these intend to be large binaries
9 # If you specify a different staging location, please manage the file
10 # resource as necessary.
12 define staging::file (
13 $source, #: the source file location, supports local files, puppet://, http://, https://, ftp://, s3://
14 $target = undef, #: the target file location, if unspecified ${staging::path}/${subdir}/${name}
15 $username = undef, #: https or ftp username
16 $certificate = undef, #: https certificate file
17 $password = undef, #: https or ftp user password or https certificate password
18 $environment = undef, #: environment variable for settings such as http_proxy, https_proxy, of ftp_proxy
19 $timeout = undef, #: the the time to wait for the file transfer to complete
20 $curl_option = undef, #: options to pass to curl
21 $wget_option = undef, #: options to pass to wget
22 $tries = undef, #: amount of retries for the file transfer when non transient connection errors exist
23 $try_sleep = undef, #: time to wait between retries for the file transfer
24 $subdir = $caller_module_name
29 $quoted_source = shellquote($source)
32 $target_file = $target
33 $staging_dir = staging_parse($target, 'parent')
35 $staging_dir = "${staging::path}/${subdir}"
36 $target_file = "${staging_dir}/${name}"
38 if ! defined(File[$staging_dir]) {
46 path => $staging::exec_path,
47 environment => $environment,
49 creates => $target_file,
51 try_sleep => $try_sleep,
53 logoutput => on_failure,
56 case $::staging_http_get {
58 $http_get = "curl ${curl_option} -f -L -o ${target_file} ${quoted_source}"
59 $http_get_passwd = "curl ${curl_option} -f -L -o ${target_file} -u ${username}:${password} ${quoted_source}"
60 $http_get_cert = "curl ${curl_option} -f -L -o ${target_file} -E ${certificate}:${password} ${quoted_source}"
61 $ftp_get = "curl ${curl_option} -o ${target_file} ${quoted_source}"
62 $ftp_get_passwd = "curl ${curl_option} -o ${target_file} -u ${username}:${password} ${quoted_source}"
65 $http_get = "wget ${wget_option} -O ${target_file} ${quoted_source}"
66 $http_get_passwd = "wget ${wget_option} -O ${target_file} --user=${username} --password=${password} ${quoted_source}"
67 $http_get_cert = "wget ${wget_option} -O ${target_file} --user=${username} --certificate=${certificate} ${quoted_source}"
69 $ftp_get_passwd = $http_get_passwd
72 $http_get = "powershell.exe -Command \"\$wc = New-Object System.Net.WebClient;\$wc.DownloadFile('${source}','${target_file}')\""
74 $http_get_password = "powershell.exe -Command \"\$wc = (New-Object System.Net.WebClient);\$wc.Credentials = New-Object System.Net.NetworkCredential('${username}','${password}');\$wc.DownloadFile(${source},${target_file})\""
75 $ftp_get_password = $http_get_password
93 if $username { $command = $http_get_passwd }
94 else { $command = $http_get }
100 if $username { $command = $http_get_passwd }
101 elsif $certificate { $command = $http_get_cert }
102 else { $command = $http_get }
108 if $username { $command = $ftp_get_passwd }
109 else { $command = $ftp_get }
115 $command = "aws s3 cp ${source} ${target_file}"
121 fail("staging::file: do not recognize source ${source}.")