Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/autoupdate/package_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"runtime"
"text/template"

"github.com/Masterminds/sprig/v3"
"github.com/gravitational/trace"
)

Expand Down Expand Up @@ -56,7 +57,10 @@ const (

// MakeURL constructs the package download URL from template, base URL and revision.
func MakeURL(uriTmpl string, baseURL string, pkg string, version string, flags InstallFlags) (string, error) {
tmpl, err := template.New("uri").Parse(uriTmpl)
// We add sprig functions to have access to `semver` and be able to change the template in tests based on
// the version requested (e.g. pull pre-releases version from the dev repo, and official versions
// from the prod one).
tmpl, err := template.New("uri").Funcs(sprig.HermeticTxtFuncMap()).Parse(uriTmpl)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're removing the external template override in #51383, will that be a problem for this testing use case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would require at least some way of passing a template and dynamically change the base-url depending on the build provenance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to use sprig at all?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now we can add only semver and semverCompare to solve this use-case, but we'll have to document this somewhere. I can vendor the semver code.

if err != nil {
return "", trace.Wrap(err)
}
Expand Down