From b4a2b96e327e6b505967bdc10a39ee438ed39519 Mon Sep 17 00:00:00 2001 From: shoonoise Date: Wed, 14 Oct 2015 17:39:57 +0300 Subject: [PATCH] Add options to manage snapshot publishing --- conf/defaults.ini | 6 ++++++ conf/sample.ini | 6 ++++++ pkg/api/api.go | 1 + pkg/api/dashboard_snapshot.go | 8 ++++++++ pkg/setting/setting.go | 11 +++++++++++ .../app/features/dashboard/partials/shareModal.html | 7 +++---- public/app/features/dashboard/shareSnapshotCtrl.js | 9 ++++++++- 7 files changed, 43 insertions(+), 5 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 69d045dc4ae..b2e1c950e32 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -125,6 +125,12 @@ disable_gravatar = false # data source proxy whitelist (ip_or_domain:port seperated by spaces) data_source_proxy_whitelist = +[snapshots] +# snapshot sharing options +external_enabled = true +external_snapshot_url = https://snapshots-origin.raintank.io +external_snapshot_name = Publish to snapshot.raintank.io + #################################### Users #################################### [users] # disable user signup / registration diff --git a/conf/sample.ini b/conf/sample.ini index e8550c66c1a..bdcebfc9131 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -120,6 +120,12 @@ # data source proxy whitelist (ip_or_domain:port seperated by spaces) ;data_source_proxy_whitelist = +[snapshots] +# snapshot sharing options +;external_enabled = true +;external_snapshot_url = https://snapshots-origin.raintank.io +;external_snapshot_name = Publish to snapshot.raintank.io + #################################### Users #################################### [users] # disable user signup / registration diff --git a/pkg/api/api.go b/pkg/api/api.go index 013b2ebe076..1fdf768d55c 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -65,6 +65,7 @@ func Register(r *macaron.Macaron) { r.Post("/api/snapshots/", bind(m.CreateDashboardSnapshotCommand{}), CreateDashboardSnapshot) r.Get("/dashboard/snapshot/*", Index) + r.Get("/api/snapshot/shared-options/", GetSharingOptions) r.Get("/api/snapshots/:key", GetDashboardSnapshot) r.Get("/api/snapshots-delete/:key", DeleteDashboardSnapshot) diff --git a/pkg/api/dashboard_snapshot.go b/pkg/api/dashboard_snapshot.go index be044cc25eb..521dee29a63 100644 --- a/pkg/api/dashboard_snapshot.go +++ b/pkg/api/dashboard_snapshot.go @@ -12,6 +12,14 @@ import ( "github.com/grafana/grafana/pkg/util" ) +func GetSharingOptions(c *middleware.Context) { + c.JSON(200, util.DynMap{ + "externalSnapshotURL": setting.ExternalSnapshotUrl, + "externalSnapshotName": setting.ExternalSnapshotName, + "externalEnabled": setting.ExternalEnabled, + }) +} + func CreateDashboardSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapshotCommand) { if cmd.External { // external snapshot ref requires key and delete key diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index d6a853a9cdc..bd011fdc2f6 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -76,6 +76,11 @@ var ( EmailCodeValidMinutes int DataProxyWhiteList map[string]bool + // Snapshots + ExternalSnapshotUrl string + ExternalSnapshotName string + ExternalEnabled bool + // User settings AllowUserSignUp bool AllowUserOrgCreate bool @@ -414,6 +419,12 @@ func NewConfigContext(args *CommandLineArgs) error { CookieRememberName = security.Key("cookie_remember_name").String() DisableGravatar = security.Key("disable_gravatar").MustBool(true) + // read snapshots settings + snapshots := Cfg.Section("snapshots") + ExternalSnapshotUrl = snapshots.Key("external_snapshot_url").String() + ExternalSnapshotName = snapshots.Key("external_snapshot_name").String() + ExternalEnabled = snapshots.Key("external_enabled").MustBool(true) + // read data source proxy white list DataProxyWhiteList = make(map[string]bool) for _, hostAndIp := range security.Key("data_source_proxy_whitelist").Strings(" ") { diff --git a/public/app/features/dashboard/partials/shareModal.html b/public/app/features/dashboard/partials/shareModal.html index 75af7ee4c22..a8db481ca91 100644 --- a/public/app/features/dashboard/partials/shareModal.html +++ b/public/app/features/dashboard/partials/shareModal.html @@ -107,7 +107,7 @@