Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package install with HTML reports #177

Merged
merged 14 commits into from
Aug 24, 2023
Prev Previous commit
Next Next commit
Install logged, PoC
  • Loading branch information
krystian-panek-vmltech committed Aug 23, 2023
commit 5f71945826a110d0a4b2fe48c0f616b741d11e41
30 changes: 21 additions & 9 deletions pkg/package_manager.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pkg

import (
"bufio"
"fmt"
"github.com/samber/lo"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -207,7 +208,7 @@ func (pm *PackageManager) installRegular(remotePath string) error {
}
var status pkg.CommandResult
if err = fmtx.UnmarshalJSON(response.RawBody(), &status); err != nil {
return fmt.Errorf("%s > cannot install package '%s'; cannot parse response: %w", pm.instance.ID(), remotePath, err)
return fmt.Errorf("%s > cannot install package '%s'; cannot parse JSON response: %w", pm.instance.ID(), remotePath, err)
}
if !status.Success {
return fmt.Errorf("%s > cannot install package '%s'; unexpected status: %s", pm.instance.ID(), remotePath, status.Message)
Expand All @@ -218,14 +219,25 @@ func (pm *PackageManager) installRegular(remotePath string) error {

func (pm *PackageManager) installLogged(remotePath string) error {
log.Infof("%s > installing package '%s'", pm.instance.ID(), remotePath)
response, err := pm.instance.http.Request(). // TODO cmd as query param or not?
SetFormData(map[string]string{"cmd": "install", "recursive": fmt.Sprintf("%v", pm.InstallRecursive)}).
Post(ServiceHtmlPath + remotePath)

// TODO parse HTML; process output line by line (do not buffer whole output)
// TODO log file per package; append for each deployment; separators with timestamps for each deployment
// TODO use logger?

// TODO cmd as query param or not?
response, err := pm.instance.http.Request().
SetFormData(map[string]string{"cmd": "install", "recursive": fmt.Sprintf("%v", pm.InstallRecursive)}).
Post(ServiceHtmlPath + remotePath)
if err != nil {
return fmt.Errorf("%s > cannot install package '%s': %w", pm.instance.ID(), remotePath, err)
} else if response.IsError() {
return fmt.Errorf("%s > cannot install package '%s': '%s'", pm.instance.ID(), remotePath, response.Status())
}
scanner := bufio.NewScanner(response.RawBody())
for scanner.Scan() {
line := scanner.Text()
// TODO parse HTML; process output line by line (do not buffer whole output)
// TODO log file per package; append for each deployment; separators with timestamps for each deployment
// TODO use logger?
}
if err := scanner.Err(); err != nil {
return fmt.Errorf("%s > cannot install package '%s': cannot parse HTML response: %w", pm.instance.ID(), remotePath, err)
}
log.Infof("%s > installed package '%s'", pm.instance.ID(), remotePath)
return nil
}
Expand Down