Cloudmigration: decode json data (#85548)

* decode get

* decode bytes

* response

* .

* linter

* quick fixes

---------

Co-authored-by: Michael Mandrus <michael.mandrus@grafana.com>
This commit is contained in:
Leonard Gram
2024-04-03 18:47:49 +02:00
committed by GitHub
parent e4c92483dc
commit a457ab3192
3 changed files with 21 additions and 4 deletions

View File

@@ -271,7 +271,14 @@ func (cma *CloudMigrationAPI) GetMigrationRun(c *contextmodel.ReqContext) respon
if err != nil {
return response.Error(http.StatusInternalServerError, "migration status error", err)
}
return response.JSON(http.StatusOK, migrationStatus)
runResponse, err := migrationStatus.ToResponse()
if err != nil {
cma.log.Error("could not return migration run", "err", err)
return response.Error(http.StatusInternalServerError, "migration run get error", err)
}
return response.JSON(http.StatusOK, runResponse)
}
// swagger:parameters getCloudMigrationRun

View File

@@ -1,6 +1,8 @@
package cloudmigration
import (
"encoding/json"
"errors"
"time"
"github.com/grafana/grafana/pkg/util/errutil"
@@ -53,6 +55,16 @@ type CloudMigrationRun struct {
Finished time.Time `json:"finished"`
}
func (r CloudMigrationRun) ToResponse() (*MigrateDataResponseDTO, error) {
var result MigrateDataResponseDTO
err := json.Unmarshal(r.Result, &result)
if err != nil {
return nil, errors.New("could not parse result of run")
}
result.RunID = r.ID
return &result, nil
}
type CloudMigrationRunList struct {
Runs []MigrateDataResponseDTO `json:"runs"`
}