Refactors IsSrcRemoteFileURL to only validate the URL is valid (#2563)

`IsSrcRemoteFileURL` was doing a `http.Get` call to make sure the URL was valid, but not surfacing any errors.
Because the error from the http.Get call is not handled, some useful information can be buried.
It also means kaniko will download the file twice during a build, once to validate, and once to actually add the file
to the image.
Removing the http.Get call and validating the URL is valid, and has the correct schema and hostname will stop
the double handling, and allow any errors to be surfaced through the error handing in the file download function.

Fixes #1590

Signed-off-by: Angus Williams <anguswilliams@gmail.com>
This commit is contained in:
Angus Williams
2023-06-14 10:20:28 -07:00
committed by GitHub
parent 5cbc06369e
commit de3032f982
2 changed files with 43 additions and 39 deletions
+2 -7
View File
@@ -18,7 +18,6 @@ package util
import (
"fmt"
"net/http"
"net/url"
"os"
"os/user"
@@ -291,12 +290,8 @@ func IsSrcsValid(srcsAndDest instructions.SourcesAndDest, resolvedSources []stri
}
func IsSrcRemoteFileURL(rawurl string) bool {
_, err := url.ParseRequestURI(rawurl)
if err != nil {
return false
}
_, err = http.Get(rawurl) //nolint:noctx
return err == nil
u, err := url.ParseRequestURI(rawurl)
return err == nil && u.Scheme != "" && u.Host != ""
}
func UpdateConfigEnv(envVars []instructions.KeyValuePair, config *v1.Config, replacementEnvs []string) error {