-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add template for client tools auto-update download url (#51210)
* Add templates for client tools auto-update download url * Change to base url setting by env MakeURL moved to common function to be general for both, agent and client tools * Add godoc for common function and constant for default package * Use flags and version arguments instead of revision * Move base url env to shared constant
- Loading branch information
Showing
5 changed files
with
139 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Teleport | ||
* Copyright (C) 2025 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package autoupdate | ||
|
||
import ( | ||
"bytes" | ||
"runtime" | ||
"text/template" | ||
|
||
"github.com/gravitational/trace" | ||
) | ||
|
||
// InstallFlags sets flags for the Teleport installation. | ||
type InstallFlags int | ||
|
||
const ( | ||
// FlagEnterprise installs enterprise Teleport. | ||
FlagEnterprise InstallFlags = 1 << iota | ||
// FlagFIPS installs FIPS Teleport | ||
FlagFIPS | ||
) | ||
|
||
const ( | ||
// DefaultBaseURL is CDN URL for downloading official Teleport packages. | ||
DefaultBaseURL = "https://cdn.teleport.dev" | ||
// DefaultPackage is the name of Teleport package. | ||
DefaultPackage = "teleport" | ||
// DefaultCDNURITemplate is the default template for the Teleport CDN download URL. | ||
DefaultCDNURITemplate = `{{ .BaseURL }}/ | ||
{{- if eq .OS "darwin" }} | ||
{{- .Package }}{{ if and .Enterprise (eq .Package "teleport") }}-ent{{ end }}-{{ .Version }}.pkg | ||
{{- else if eq .OS "windows" }} | ||
{{- .Package }}-v{{ .Version }}-{{ .OS }}-amd64-bin.zip | ||
{{- else }} | ||
{{- .Package }}{{ if .Enterprise }}-ent{{ end }}-v{{ .Version }}-{{ .OS }}-{{ .Arch }}{{ if .FIPS }}-fips{{ end }}-bin.tar.gz | ||
{{- end }}` | ||
// BaseURLEnvVar allows to override base URL for the Teleport package URL via env var. | ||
BaseURLEnvVar = "TELEPORT_CDN_BASE_URL" | ||
) | ||
|
||
// 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) | ||
if err != nil { | ||
return "", trace.Wrap(err) | ||
} | ||
var uriBuf bytes.Buffer | ||
params := struct { | ||
BaseURL, OS, Version, Arch, Package string | ||
FIPS, Enterprise bool | ||
}{ | ||
BaseURL: baseURL, | ||
OS: runtime.GOOS, | ||
Version: version, | ||
Arch: runtime.GOARCH, | ||
FIPS: flags&FlagFIPS != 0, | ||
Enterprise: flags&(FlagEnterprise|FlagFIPS) != 0, | ||
Package: pkg, | ||
} | ||
err = tmpl.Execute(&uriBuf, params) | ||
if err != nil { | ||
return "", trace.Wrap(err) | ||
} | ||
|
||
return uriBuf.String(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters