Skip to contentSkip to conversation

fetch2.wget: add support for per-source download flags

RFC PATCH In review Yann Dirson 2 participants 4 messages Dec 2, 2020 – Dec 4, 2020

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 fetch2.wget: add support for per-source download flags

From: Yann Dirson <[email protected]>

Adds support for a new FETCHFLAGS_wget variable, overridable for individual SRC_URI entries:

FETCHFLAGS_wget = "--some-flag"
FETCHFLAGS_wget[uriname] = "--some-better-flag"

Typical use: add authorization headers to a request, for example to access a gitlab private package registry:

FETCHFLAGS_wget[foo] = '--header="Authorization: Bearer ${FOO_NPM_REGISTRY_TOKEN}"'

---
 lib/bb/fetch2/wget.py | 6 ++++++
 1 file changed, 6 insertions(+)

If this approch is OK, I guess this will need a doc update.

lib/bb/fetch2/wget.py +6 -0
index e6d9f528..d9ec6e3b 100644
@@ -99,6 +99,12 @@ class Wget(FetchMethod):
         if ud.user and ud.pswd:
             fetchcmd += " --user=%s --password=%s --auth-no-challenge" % (ud.user, ud.pswd)
 
+        flags = d.getVar("FETCHFLAGS_wget") or ""
+        pername_flags = d.getVarFlags("FETCHFLAGS_wget")
+        if pername_flags and ud.names[0] in pername_flags:
+            flags = pername_flags[ud.names[0]]
+        fetchcmd += " " + flags
+
         uri = ud.url.split(";")[0]
         if os.path.exists(ud.localpath):
             # file exists, but we didnt complete it.. trying again..
Signature · 1 line
2.29.2
#1 lore raw

An alternative I thought about would be to:

1. expose all the FETCHCMD_$method vars with their default values through setVar,
so we can _append them, as today it is only possible to fully override them

2. use something like FETCHCMD_$method_append_srcuri-$name="--foo". However that
would require to add "srcuri-$name" to overrides temporarily for each file fetched, and I don't
quite see how that could fit in the current codebase

Quoted 43 lines · Le mer. 2 déc. 2020 à 10:50, <[email protected]> a écrit :

From: Yann Dirson <[email protected]>

Adds support for a new FETCHFLAGS_wget variable, overridable for individual SRC_URI entries:

FETCHFLAGS_wget = "--some-flag"
FETCHFLAGS_wget[uriname] = "--some-better-flag"

Typical use: add authorization headers to a request, for example to access a gitlab private package registry:

FETCHFLAGS_wget[foo] = '--header="Authorization: Bearer
${FOO_NPM_REGISTRY_TOKEN}"'

---
 lib/bb/fetch2/wget.py | 6 ++++++
 1 file changed, 6 insertions(+)

If this approch is OK, I guess this will need a doc update.

lib/bb/fetch2/wget.py +6 -0
index e6d9f528..d9ec6e3b 100644
@@ -99,6 +99,12 @@ class Wget(FetchMethod):
         if ud.user and ud.pswd:
             fetchcmd += " --user=%s --password=%s --auth-no-challenge" %
 (ud.user, ud.pswd)
 
+        flags = d.getVar("FETCHFLAGS_wget") or ""
+        pername_flags = d.getVarFlags("FETCHFLAGS_wget")
+        if pername_flags and ud.names[0] in pername_flags:
+            flags = pername_flags[ud.names[0]]
+        fetchcmd += " " + flags
+
         uri = ud.url.split(";")[0]
         if os.path.exists(ud.localpath):
             # file exists, but we didnt complete it.. trying again..
--
2.29.2
Signature · 2 lines
Yann Dirson <[email protected]>
Blade / Shadow -- http://shadow.tech
#2 lore raw
Quoted 7 lines · Yann Dirson

An alternative I thought about would be to:

1. expose all the FETCHCMD_$method vars with their default values through setVar,
so we can _append them, as today it is only possible to fully override them

Quoted 5 lines

2. use something like FETCHCMD_$method_append_srcuri-$name="--foo". However that
would require to add "srcuri-$name" to overrides temporarily for each file fetched, and I don't
quite see how that could fit in the current codebase

FETCHCMD was never a nice fit and we've tried to back away from using that. That is particularly true give you want to do it on a per url basis. The hope was we could add things to the urls as parameters if/as needed. The strings you're trying to add are fairly complex to encode into urls though, I'm not sure if there is a good way we could make that work, could we encode it somehow?

Cheers,

Richard

#3 lore raw
Quoted 14 lines · Richard Purdie
Quoted 7 lines · Yann Dirson

An alternative I thought about would be to:

1. expose all the FETCHCMD_$method vars with their default values through setVar,
so we can _append them, as today it is only possible to fully override them

Quoted 5 lines

2. use something like FETCHCMD_$method_append_srcuri-$name="--foo". However that
would require to add "srcuri-$name" to overrides temporarily for each file fetched, and I don't
quite see how that could fit in the current codebase

Quoted 7 lines

FETCHCMD was never a nice fit and we've tried to back away from using that. That is particularly true give you want to do it on a per url basis. The hope was we could add things to the urls as parameters if/as needed. The strings you're trying to add are fairly complex to encode into urls though, I'm not sure if there is a good way we could make that work, could we encode it somehow?

My first attempt _was_ using parameters: I added an authz_bearer parameter and
patched Wget.download() to append '--header="Authorization: Bearer $value" '.

Other than the problem of it requiring patching Wget.download() for each feature we'd
want to use, it was quite annoying to use in combination to the yarn support sent to
openembedded-core the same day: there the SRC_URI are generated and the script is not smart enough to detect on which SRC_URI it would have to add this
parameter.

Rather than adding more ad-hoc guessing from npm config, I prefered to go the explicit route and find a way to specify such things separately.

The alternative would have been digging the information in the package's .npmrc
(which it is an envvar reference that was added there specifically to ease the integration
with our previous yarn fetcher, which probably does not say anything about the general
case) and teach yarn-v1-mkbbinc to find the info. I just have no idea whether a general
solution to that problem even exists :)

Best regards,

Signature · 2 lines
Yann Dirson <[email protected]>
Blade / Shadow -- http://shadow.tech