mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user