Skip to content

Commit 6714ee9

Browse files
authored
operations/files.download: add extra optional arguments for wget or curl
1 parent 87ffe03 commit 6714ee9

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

pyinfra/operations/files.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ def download(
8383
insecure=False,
8484
proxy: str | None = None,
8585
temp_dir: str | Path | None = None,
86+
extra_curl_args: dict[str, str] | None = None,
87+
extra_wget_args: dict[str, str] | None = None,
8688
):
8789
"""
8890
Download files from remote locations using ``curl`` or ``wget``.
@@ -102,6 +104,8 @@ def download(
102104
+ insecure: disable SSL verification for the HTTP request
103105
+ proxy: simple HTTP proxy through which we can download files, form `http://<yourproxy>:<port>`
104106
+ temp_dir: use this custom temporary directory during the download
107+
+ extra_curl_args: optional dictionary with custom arguments for curl
108+
+ extra_wget_args: optional dictionary with custom arguments for wget
105109
106110
**Example:**
107111
@@ -164,6 +168,14 @@ def download(
164168
curl_args: list[Union[str, StringCommand]] = ["-sSLf"]
165169
wget_args: list[Union[str, StringCommand]] = ["-q"]
166170

171+
if extra_curl_args:
172+
for key, value in extra_curl_args.items():
173+
curl_args.append(StringCommand(key, QuoteString(value)))
174+
175+
if extra_wget_args:
176+
for key, value in extra_wget_args.items():
177+
wget_args.append(StringCommand(key, QuoteString(value)))
178+
167179
if proxy:
168180
curl_args.append(f"--proxy {proxy}")
169181
wget_args.append("-e use_proxy=yes")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"args": ["http://myfile"],
3+
"kwargs": {
4+
"dest": "/home/myfile",
5+
"extra_curl_args": {
6+
"--user": "abc:def"
7+
}
8+
},
9+
"facts": {
10+
"server.Date": "datetime:2015-01-01T00:00:00",
11+
"files.File": {
12+
"path=/home/myfile": null
13+
},
14+
"server.Which": {
15+
"command=curl": "yes"
16+
}
17+
},
18+
"commands": [
19+
"curl -sSLf --user abc:def http://myfile -o _tempfile_",
20+
"mv _tempfile_ /home/myfile"
21+
]
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"args": ["http://myfile"],
3+
"kwargs": {
4+
"dest": "/home/myfile",
5+
"extra_wget_args": {
6+
"--user": "abc:def"
7+
}
8+
},
9+
"facts": {
10+
"server.Date": "datetime:2015-01-01T00:00:00",
11+
"files.File": {
12+
"path=/home/myfile": null
13+
},
14+
"server.Which": {
15+
"command=curl": null,
16+
"command=wget": "yes"
17+
}
18+
},
19+
"commands": [
20+
"wget -q --user abc:def http://myfile -O _tempfile_ || ( rm -f _tempfile_ ; exit 1 )",
21+
"mv _tempfile_ /home/myfile"
22+
]
23+
}

0 commit comments

Comments
 (0)