|
|
|
@ -76,7 +76,11 @@ func createExternalDashboardSnapshot(cmd models.CreateDashboardSnapshotCommand) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// POST /api/snapshots
|
|
|
|
|
func CreateDashboardSnapshot(c *models.ReqContext, cmd models.CreateDashboardSnapshotCommand) { |
|
|
|
|
func CreateDashboardSnapshot(c *models.ReqContext) response.Response { |
|
|
|
|
cmd := models.CreateDashboardSnapshotCommand{} |
|
|
|
|
if err := web.Bind(c.Req, &cmd); err != nil { |
|
|
|
|
return response.Error(http.StatusBadRequest, "bad request data", err) |
|
|
|
|
} |
|
|
|
|
if cmd.Name == "" { |
|
|
|
|
cmd.Name = "Unnamed snapshot" |
|
|
|
|
} |
|
|
|
@ -89,13 +93,13 @@ func CreateDashboardSnapshot(c *models.ReqContext, cmd models.CreateDashboardSna |
|
|
|
|
if cmd.External { |
|
|
|
|
if !setting.ExternalEnabled { |
|
|
|
|
c.JsonApiErr(403, "External dashboard creation is disabled", nil) |
|
|
|
|
return |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
response, err := createExternalDashboardSnapshot(cmd) |
|
|
|
|
if err != nil { |
|
|
|
|
c.JsonApiErr(500, "Failed to create external snapshot", err) |
|
|
|
|
return |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
url = response.Url |
|
|
|
@ -112,7 +116,7 @@ func CreateDashboardSnapshot(c *models.ReqContext, cmd models.CreateDashboardSna |
|
|
|
|
cmd.Key, err = util.GetRandomString(32) |
|
|
|
|
if err != nil { |
|
|
|
|
c.JsonApiErr(500, "Could not generate random string", err) |
|
|
|
|
return |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -121,7 +125,7 @@ func CreateDashboardSnapshot(c *models.ReqContext, cmd models.CreateDashboardSna |
|
|
|
|
cmd.DeleteKey, err = util.GetRandomString(32) |
|
|
|
|
if err != nil { |
|
|
|
|
c.JsonApiErr(500, "Could not generate random string", err) |
|
|
|
|
return |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -132,7 +136,7 @@ func CreateDashboardSnapshot(c *models.ReqContext, cmd models.CreateDashboardSna |
|
|
|
|
|
|
|
|
|
if err := bus.Dispatch(&cmd); err != nil { |
|
|
|
|
c.JsonApiErr(500, "Failed to create snapshot", err) |
|
|
|
|
return |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
c.JSON(200, util.DynMap{ |
|
|
|
@ -142,6 +146,7 @@ func CreateDashboardSnapshot(c *models.ReqContext, cmd models.CreateDashboardSna |
|
|
|
|
"deleteUrl": setting.ToAbsUrl("api/snapshots-delete/" + cmd.DeleteKey), |
|
|
|
|
"id": cmd.Result.Id, |
|
|
|
|
}) |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GET /api/snapshots/:key
|
|
|
|
|