Skip to content

Commit c39acba

Browse files
authored
Add support get the latest version from a URL (#167)
* Add support get the latest version from a URL * for the security reason, only support https
1 parent 017a33d commit c39acba

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

.github/workflows/pull-request.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
- name: Run Gosec Security Scanner
7474
uses: securego/gosec@master
7575
with:
76-
args: '-exclude=G402,G204,G304,G110,G306 ./...'
76+
args: '-exclude=G402,G204,G304,G110,G306,G107 ./...'
7777
CodeQL:
7878
name: CodeQL
7979
runs-on: ubuntu-20.04

pkg/installer/check.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/mitchellh/go-homedir"
1313
"gopkg.in/yaml.v2"
1414
"io/ioutil"
15+
"net/http"
1516
"net/url"
1617
sysos "os"
1718
"path"
@@ -192,6 +193,10 @@ func (o *Installer) ProviderURLParse(path string, acceptPreRelease bool) (packag
192193
o.AdditionBinaries = cfg.AdditionBinaries
193194
o.Tar = cfg.Tar != "false"
194195

196+
if cfg.LatestVersion != "" {
197+
version = getVersionOrDefault(cfg.LatestVersion, version)
198+
}
199+
195200
if version == "latest" || version == "" {
196201
ghClient := pkg.ReleaseClient{
197202
Org: o.Org,
@@ -270,6 +275,19 @@ func (o *Installer) ProviderURLParse(path string, acceptPreRelease bool) (packag
270275
return
271276
}
272277

278+
func getVersionOrDefault(version string, defaultVer string) (target string) {
279+
target = defaultVer
280+
// for the security reason, only support https
281+
if strings.HasPrefix(version, "https://") {
282+
if response, err := http.Get(version); err == nil {
283+
if data, err := ioutil.ReadAll(response.Body); err == nil {
284+
target = string(data)
285+
}
286+
}
287+
}
288+
return
289+
}
290+
273291
// IsSupport checks if support
274292
func IsSupport(cfg HDConfig) bool {
275293
var osSupport, archSupport bool

pkg/installer/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type HDConfig struct {
1717
FromSource bool `yaml:"fromSource"`
1818
URL string `yaml:"url"`
1919
Tar string `yaml:"tar"`
20+
LatestVersion string `yaml:"latestVersion"`
2021
SupportOS []string `yaml:"supportOS"`
2122
SupportArch []string `yaml:"supportArch"`
2223
Replacements map[string]string `yaml:"replacements"`

0 commit comments

Comments
 (0)