Dashboard snapshot: more work on snapshot deletion, and saving external reference, #1623

This commit is contained in:
Torkel Ödegaard
2015-03-26 20:59:41 +01:00
parent 4322f29f34
commit 541cd2e430
4 changed files with 41 additions and 28 deletions
+9 -4
View File
@@ -13,14 +13,19 @@ import (
)
func CreateDashboardSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapshotCommand) {
cmd.Key = util.GetRandomString(32)
cmd.DeleteKey = util.GetRandomString(32)
if cmd.External {
// external snapshot ref requires key and delete key
if cmd.Key != "" && cmd.DeleteKey != "" {
c.JsonApiErr(400, "Missing key and delete key for external snapshot", nil)
return
}
cmd.OrgId = -1
cmd.UserId = -1
metrics.M_Api_Dashboard_Snapshot_External.Inc(1)
} else {
cmd.Key = util.GetRandomString(32)
cmd.DeleteKey = util.GetRandomString(32)
cmd.OrgId = c.OrgId
cmd.UserId = c.UserId
metrics.M_Api_Dashboard_Snapshot_Create.Inc(1)
@@ -78,5 +83,5 @@ func DeleteDashboardSnapshot(c *middleware.Context) {
return
}
c.JSON(200, util.DynMap{"message": "Snapshot deleted. It might take an hour before it is cleared from a CDN cache."})
c.JSON(200, util.DynMap{"message": "Snapshot deleted. It might take an hour before it's cleared from a CDN cache."})
}
+9 -8
View File
@@ -24,15 +24,16 @@ type DashboardSnapshot struct {
// COMMANDS
type CreateDashboardSnapshotCommand struct {
Dashboard map[string]interface{} `json:"dashboard" binding:"Required"`
External bool `json:"external"`
ExternalUrl string `json:"externalUrl"`
Expires int64 `json:"expires"`
Dashboard map[string]interface{} `json:"dashboard" binding:"Required"`
Expires int64 `json:"expires"`
OrgId int64 `json:"-"`
UserId int64 `json:"-"`
Key string `json:"-"`
DeleteKey string `json:"-"`
// these are passed when storing an external snapshot ref
External bool `json:"external"`
Key string `json:"key"`
DeleteKey string `json:"deleteKey"`
OrgId int64 `json:"-"`
UserId int64 `json:"-"`
Result *DashboardSnapshot
}
+9 -10
View File
@@ -24,16 +24,15 @@ func CreateDashboardSnapshot(cmd *m.CreateDashboardSnapshotCommand) error {
}
snapshot := &m.DashboardSnapshot{
Key: cmd.Key,
DeleteKey: cmd.DeleteKey,
OrgId: cmd.OrgId,
UserId: cmd.UserId,
External: cmd.External,
ExternalUrl: cmd.ExternalUrl,
Dashboard: cmd.Dashboard,
Expires: expires,
Created: time.Now(),
Updated: time.Now(),
Key: cmd.Key,
DeleteKey: cmd.DeleteKey,
OrgId: cmd.OrgId,
UserId: cmd.UserId,
External: cmd.External,
Dashboard: cmd.Dashboard,
Expires: expires,
Created: time.Now(),
Updated: time.Now(),
}
_, err := sess.Insert(snapshot)