Skip to content

Commit 7726218

Browse files
authored
Merge pull request #34 from b4b4r07/fix/http-url-bug
Fix `http.Installed()` behavior
2 parents 0f920b9 + ed263c5 commit 7726218

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

pkg/config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func parse(cfg Config) []Package {
8181
pkgs = append(pkgs, pkg)
8282
}
8383
for _, pkg := range cfg.HTTP {
84+
pkg.ParseURL()
8485
pkgs = append(pkgs, pkg)
8586
}
8687

pkg/config/http.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ func (c HTTP) call(ctx context.Context) error {
7575

7676
os.MkdirAll(c.GetHome(), os.ModePerm)
7777
dest := filepath.Join(c.GetHome(), filepath.Base(c.URL))
78+
79+
log.Printf("[DEBUG] http: %s: copying %q to %q", c.GetName(), c.URL, dest)
7880
file, err := os.Create(dest)
7981
if err != nil {
8082
return err
@@ -102,17 +104,6 @@ func (c HTTP) Install(ctx context.Context, status chan<- Status) error {
102104
// Go installing step!
103105
}
104106

105-
url, err := templates.New(data.New(data.WithPackage(c))).
106-
Replace(c.Templates.Replacements).
107-
Apply(c.URL)
108-
if err != nil {
109-
return err
110-
}
111-
if url != c.URL {
112-
log.Printf("[DEBUG] %s: templating url %s", c.GetName(), url)
113-
c.URL = url
114-
}
115-
116107
ctx, cancel := context.WithCancel(ctx)
117108
defer cancel()
118109

@@ -252,3 +243,18 @@ func (c HTTP) GetDependsOn() []string {
252243
func (c HTTP) GetResource() state.Resource {
253244
return getResource(c)
254245
}
246+
247+
func (c *HTTP) ParseURL() {
248+
templated, err := templates.New(data.New(data.WithPackage(c))).
249+
Replace(c.Templates.Replacements).
250+
Apply(c.URL)
251+
if err != nil {
252+
log.Printf("[ERROR] %s: failed to parse URL", c.GetName())
253+
return
254+
}
255+
if templated != c.URL {
256+
log.Printf("[TRACE] %s: templating URL %q to %q", c.GetName(), c.URL, templated)
257+
c.URL = templated
258+
}
259+
return
260+
}

0 commit comments

Comments
 (0)