Cloudmigration: swagger for the cloudmigration api (#85255)

* swagger for create token

* tried to fix errors

* update swagger annotations

* update swagger annotations

* update api GetMigrationList to return the *Response directly

* clean up previous commit

---------

Co-authored-by: joshhunt <josh@trtr.co>
This commit is contained in:
Leonard Gram
2024-04-02 13:57:42 +02:00
committed by GitHub
parent bc77745da6
commit 4e89267603
5 changed files with 1077 additions and 1 deletions

View File

@@ -51,6 +51,15 @@ func (cma *CloudMigrationAPI) registerEndpoints() {
}, middleware.ReqGrafanaAdmin)
}
// swagger:route POST /cloudmigration/token migrations createCloudMigrationToken
//
// Create gcom access token.
//
// Responses:
// 200: cloudMigrationCreateTokenResponse
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (cma *CloudMigrationAPI) CreateToken(c *contextmodel.ReqContext) response.Response {
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.CreateAccessToken")
defer span.End()
@@ -66,14 +75,35 @@ func (cma *CloudMigrationAPI) CreateToken(c *contextmodel.ReqContext) response.R
return response.JSON(http.StatusOK, cloudmigration.CreateAccessTokenResponseDTO(resp))
}
// swagger:route GET /cloudmigration/migration migrations getMigrationList
//
// Get a list of all cloud migrations.
//
// Responses:
// 200: cloudMigrationListResponse
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (cma *CloudMigrationAPI) GetMigrationList(c *contextmodel.ReqContext) response.Response {
cloudMigrations, err := cma.cloudMigrationsService.GetMigrationList(c.Req.Context())
if err != nil {
return response.Error(http.StatusInternalServerError, "migration list error", err)
}
return response.JSON(http.StatusOK, cloudMigrations)
}
// swagger:route GET /cloudmigration/migration/{id} migrations getCloudMigration
//
// Get a cloud migration.
//
// It returns migrations that has been created.
//
// Responses:
// 200: cloudMigrationResponse
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (cma *CloudMigrationAPI) GetMigration(c *contextmodel.ReqContext) response.Response {
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
if err != nil {
@@ -86,6 +116,23 @@ func (cma *CloudMigrationAPI) GetMigration(c *contextmodel.ReqContext) response.
return response.JSON(http.StatusOK, cloudMigration)
}
// swagger:parameters getCloudMigration
type GetCloudMigrationRequest struct {
// ID of an migration
//
// in: path
ID int64 `json:"id"`
}
// swagger:route POST /cloudmigration/migration migrations createMigration
//
// Create a migration.
//
// Responses:
// 200: cloudMigrationResponse
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (cma *CloudMigrationAPI) CreateMigration(c *contextmodel.ReqContext) response.Response {
cmd := cloudmigration.CloudMigrationRequest{}
if err := web.Bind(c.Req, &cmd); err != nil {
@@ -98,6 +145,17 @@ func (cma *CloudMigrationAPI) CreateMigration(c *contextmodel.ReqContext) respon
return response.JSON(http.StatusOK, cloudMigration)
}
// swagger:route GET /cloudmigration/migration/{id}/run migrations runCloudMigration
//
// Trigger the run of a migration to the Grafana Cloud.
//
// It returns migrations that has been created.
//
// Responses:
// 200: cloudMigrationRunResponse
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (cma *CloudMigrationAPI) RunMigration(c *contextmodel.ReqContext) response.Response {
cloudMigrationRun, err := cma.cloudMigrationsService.RunMigration(c.Req.Context(), web.Params(c.Req)[":id"])
if err != nil {
@@ -106,6 +164,23 @@ func (cma *CloudMigrationAPI) RunMigration(c *contextmodel.ReqContext) response.
return response.JSON(http.StatusOK, cloudMigrationRun)
}
// swagger:parameters runCloudMigration
type RunCloudMigrationRequest struct {
// ID of an migration
//
// in: path
ID int64 `json:"id"`
}
// swagger:route GET /cloudmigration/migration/{id}/run/{runID} migrations getCloudMigrationRun
//
// Get the result of a single migration run.
//
// Responses:
// 200: cloudMigrationRunResponse
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (cma *CloudMigrationAPI) GetMigrationRun(c *contextmodel.ReqContext) response.Response {
migrationStatus, err := cma.cloudMigrationsService.GetMigrationStatus(c.Req.Context(), web.Params(c.Req)[":id"], web.Params(c.Req)[":runID"])
if err != nil {
@@ -114,14 +189,55 @@ func (cma *CloudMigrationAPI) GetMigrationRun(c *contextmodel.ReqContext) respon
return response.JSON(http.StatusOK, migrationStatus)
}
// swagger:parameters getCloudMigrationRun
type GetMigrationRunParams struct {
// ID of an migration
//
// in: path
ID int64 `json:"id"`
// Run ID of a migration run
//
// in: path
RunID int64 `json:"runID"`
}
// swagger:route GET /cloudmigration/migration/{id}/run migrations getCloudMigrationRunList
//
// Get a list of migration runs for a migration.
//
// Responses:
// 200: cloudMigrationRunListResponse
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (cma *CloudMigrationAPI) GetMigrationRunList(c *contextmodel.ReqContext) response.Response {
migrationStatus, err := cma.cloudMigrationsService.GetMigrationStatusList(c.Req.Context(), web.Params(c.Req)[":id"])
if err != nil {
return response.Error(http.StatusInternalServerError, "migration status error", err)
}
return response.JSON(http.StatusOK, migrationStatus)
runList := cloudmigration.CloudMigrationRunList{Runs: migrationStatus}
return response.JSON(http.StatusOK, runList)
}
// swagger:parameters getCloudMigrationRunList
type GetCloudMigrationRunList struct {
// ID of an migration
//
// in: path
ID int64 `json:"id"`
}
// swagger:route DELETE /cloudmigration/migration/{id} migrations deleteCloudMigration
//
// Delete a migration.
//
// Responses:
// 200
// 401: unauthorisedError
// 403: forbiddenError
// 500: internalServerError
func (cma *CloudMigrationAPI) DeleteMigration(c *contextmodel.ReqContext) response.Response {
err := cma.cloudMigrationsService.DeleteMigration(c.Req.Context(), web.Params(c.Req)[":id"])
if err != nil {
@@ -129,3 +245,41 @@ func (cma *CloudMigrationAPI) DeleteMigration(c *contextmodel.ReqContext) respon
}
return response.Empty(http.StatusOK)
}
// swagger:parameters deleteCloudMigration
type DeleteMigrationRequest struct {
// ID of an migration
//
// in: path
ID int64 `json:"id"`
}
// swagger:response cloudMigrationRunResponse
type CloudMigrationRunResponse struct {
// in: body
Body cloudmigration.CloudMigrationRun
}
// swagger:response cloudMigrationListResponse
type CloudMigrationListResponse struct {
// in: body
Body cloudmigration.CloudMigrationListResponse
}
// swagger:response cloudMigrationResponse
type CloudMigrationResponse struct {
// in: body
Body cloudmigration.CloudMigrationResponse
}
// swagger:response cloudMigrationRunListResponse
type CloudMigrationRunListResponse struct {
// in: body
Body cloudmigration.CloudMigrationRunList
}
// swagger:response cloudMigrationCreateTokenResponse
type CloudMigrationCreateTokenResponse struct {
// in: body
Body cloudmigration.CreateAccessTokenResponseDTO
}

View File

@@ -50,6 +50,11 @@ type CloudMigrationRun struct {
Finished time.Time `json:"finished"`
}
type CloudMigrationRunList struct {
Runs []CloudMigrationRun `json:"runs"`
}
// swagger:parameters createMigration
type CloudMigrationRequest struct {
AuthToken string `json:"authToken"`
}