Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel committed Aug 17, 2023
1 parent bb98db0 commit cdce329
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions api/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (
uuid2 "github.com/google/uuid"
qf "github.com/konveyor/tackle2-hub/api/filter"
"github.com/konveyor/tackle2-hub/model"
"github.com/konveyor/tackle2-hub/tar"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/logger"
"io"
"net/http"
"os"
pathlib "path"
)

//
Expand Down Expand Up @@ -1576,6 +1578,40 @@ func (h AnalysisHandler) DepAppReports(ctx *gin.Context) {
h.Respond(ctx, http.StatusOK, resources)
}

// AppReport godoc
// @summary Analysis static report.
// @description Analysis static report.
// @tags analysis
// @produce octet-stream
// @success 200
// @router /application/{id}/analysis/report [get]
// @param id path string true "Application ID"
func (h AnalysisHandler) AppReport(ctx *gin.Context) {
id := h.pk(ctx)
aWriter := AnalysisWriter{ctx: ctx}
path, err := aWriter.Build(id)
if err != nil {
_ = ctx.Error(err)
return
}
ctx.Writer.Header().Set(
"Content-Disposition",
fmt.Sprintf("attachment; filename=\"%s\"", "report.tar.gz"))
tarWriter := tar.NewWriter(ctx.Writer)
defer func() {
tarWriter.Close()
}()
err = tarWriter.AssertFile(path)
if err != nil {
_ = ctx.Error(err)
return
} else {
ctx.Status(http.StatusOK)
}

_ = tarWriter.AddFile(path, pathlib.Base(path))
}

//
// appIDs provides application IDs.
// filter:
Expand Down Expand Up @@ -1704,27 +1740,6 @@ func (h *AnalysisHandler) depIDs(ctx *gin.Context, f qf.Filter) (q *gorm.DB) {
return
}

// AppReport godoc
// @summary Analysis static report.
// @description Analysis static report.
// @tags analysis
// @produce octet-stream
// @success 200
// @router /application/{id}/analysis/report [get]
// @param id path string true "Application ID"
func (h AnalysisHandler) AppReport(ctx *gin.Context) {
id := h.pk(ctx)
aWriter := AnalysisWriter{ctx: ctx}
_, err := aWriter.Build(id)
if err != nil {
ctx.Error(err)
return
}
ctx.Writer.Header().Set(
"Content-Disposition",
fmt.Sprintf("attachment; filename=\"%s\"", "report.tar.gz"))
}

//
// Analysis REST resource.
type Analysis struct {
Expand Down Expand Up @@ -2071,7 +2086,7 @@ func (r *AnalysisWriter) Build(id uint) (path string, err error) {
return
}
uuid, _ := uuid2.NewUUID()
path = "/tmp/report" + uuid.String() + ".json"
path = "/tmp/report-" + uuid.String() + ".json"
r.file, err = os.Create(path)
if err != nil {
return
Expand Down

0 comments on commit cdce329

Please sign in to comment.