bolt icon indicating copy to clipboard operation
bolt copied to clipboard

`download_file()` improvements

Open jay7x opened this issue 7 months ago • 3 comments

Use Case

The existing approach with storing a file downloaded to the $destination directory under the basename($source) file name is quite limiting.. Downloading bunch of files from a host or downloading files with the same name but different path from a host makes it especially painful.

Describe the Solution You Would Like

  1. It'd be nice if download_file() accepts an Array as a source. This way we can download bunch of files with one call. That opens another question how to download a bunch of files within one transport connection, but it's another question.
  2. Make $destination a dynamic template, which can accept the source file name and a host name as a parameters. For example:
$res = download_file(['/tmp/1/example.txt', '/tmp/2/example.txt'], 'examples/<%= md5sum($hostname)[1,8] %>/<%= $source_path.regsubst('[/]', '_') %>/<%= shellquote($source_filename) %>.txt', _dynamic_destination => true)

Side notes

  1. That allows to solve https://github.com/puppetlabs/bolt/issues/3198 also. No real reason to wipe the target directory I guess.
  2. Maybe it's better to implement another function instead of extending the download_file() (download_files())?. Though, there is no breaking change as long as template processing is requested explicitly in the $options.

jay7x avatar Jun 28 '24 03:06 jay7x