DownloadFile is a configuration extension for Foliant which downloads external files to use in your project.
It also resolves
!download YAML tag in the project config and inside XML-tags parameters.
$ pip install foliantcontrib.downloadfile
To configure DownloadFile add the following section to your foliant.yml file:
downloadfile: fail_fast: true ignore_ssl_errors: false queue: - url: https://example.com/image.png # required save_to: images/img1.png login: john password: qwerty123 - ...
true, build will be stopped if any file can't be downloaded. If
false— unavailable files will be just skipped. Doesn't affect
!downloadtag, this one will always break the build on errors. Default:
- Switch to
trueto skip SSL certificate check. Default:
- list of files to download. Each file is represented by a dictionary with the following fields:
- (requried) URL to the file which should be downloaded.
- path where the downloaded file should be saved, relative to the project root. If not supplied, file will be saved in the project root with the name from url.
- login for basic authentication.
- password for basic authentication.
Warning: don't store plain text passwords in foliant.yml. Use environment variables.
!download YAML tag¶
Another way to use DownloadFile is by specifying
!download YAML tag. This is the quickest and the simplest way, but it comes with a few disadvantages.
!download tag, followed by file URL, in any place in foliant.yml or tag parameters, where file path is expected:
preprocessors: - swaggerdoc: spec_path: !download https://example.com/swagger.json mode: widdershins
Generated template: <template engine="jinja2" ext_context="!download https://example.com/mycontext.yml"> ... </template>
The downloaded file will be saved in the
.downloadfilecache directory under a hashed name, and the
!download tag will be replaced by absolute path to this file.
The cons of this method are that you can't change the saved file path nor other parameters. Also if you reference the same file twice with
!download tag, it will be downloaded two times.