feat: added downloading templated archives

This commit is contained in:
David Allen 2025-08-28 12:25:45 -06:00
parent 1ebea8cb73
commit 98f9acad5d
Signed by: towk
GPG key ID: 0430CDBE22619155
5 changed files with 48 additions and 23 deletions

View file

@ -115,7 +115,7 @@ func (p *Jinja2) Run(store storage.KVStore, args []string) error {
}
// write render templates to data store output
store.Set("out", output.String())
store.Set("out", output.Bytes())
return nil
}

View file

@ -131,7 +131,7 @@ func (p *SmdClient) Run(store storage.KVStore, args []string) error {
// write data back to shared data store to be used by other plugins
bytes, err = json.Marshal(client)
if err != nil {
return fmt.Errorf("(smd) failed to marshal SMD client: %v")
return fmt.Errorf("(smd) failed to marshal SMD client: %v", err)
}
store.Set("shared", bytes)

View file

@ -53,13 +53,14 @@ func (s *Service) Download() http.HandlerFunc {
// determine if path is directory, file, or exists
if fileInfo, err = os.Stat(path); err == nil {
if fileInfo.IsDir() {
// get the final archive path
archivePath := fmt.Sprintf("%d.tar.gz", time.Now().Unix())
log.Debug().
Str("archive_path", archivePath).
Str("type", "directory").
Msg("Service.Download()")
// get the final archive path
archivePath := fmt.Sprintf("%d.tar.gz", time.Now().Unix())
out, err = os.Create(archivePath)
if err != nil {
s.writeErrorResponse(w, fmt.Sprintf("failed to create named file: %v", err), http.StatusInternalServerError)
@ -157,7 +158,7 @@ func (s *Service) Download() http.HandlerFunc {
s.writeErrorResponse(w, fmt.Sprintf("failed to get data from hook: %v", err), http.StatusInternalServerError)
return
}
w.Write([]byte(data.(string)))
w.Write(data.([]byte))
} else {
w.Write(contents)
}