| 
									
										
										
										
											2014-12-29 20:36:08 +08:00
										 |  |  | package api | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2021-11-02 20:42:55 +08:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 	"net/http" | 
					
						
							| 
									
										
										
										
											2014-12-29 20:36:08 +08:00
										 |  |  | 	"strconv" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 21:54:26 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/models" | 
					
						
							| 
									
										
										
										
											2015-02-28 05:29:00 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/plugins" | 
					
						
							| 
									
										
										
										
											2021-10-05 21:54:26 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/accesscontrol" | 
					
						
							| 
									
										
										
										
											2022-06-28 00:23:15 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/datasources" | 
					
						
							| 
									
										
										
										
											2022-03-16 21:37:19 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/licensing" | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/pluginsettings" | 
					
						
							| 
									
										
										
										
											2022-08-11 03:47:03 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/secrets/kvstore" | 
					
						
							| 
									
										
										
										
											2015-02-05 17:37:13 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/setting" | 
					
						
							| 
									
										
										
										
											2021-10-05 21:54:26 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/tsdb/grafanads" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/util" | 
					
						
							| 
									
										
										
										
											2014-12-29 20:36:08 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | func (hs *HTTPServer) GetFrontendSettings(c *models.ReqContext) { | 
					
						
							|  |  |  | 	settings, err := hs.getFrontendSettingsMap(c) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		c.JsonApiErr(400, "Failed to get frontend settings", err) | 
					
						
							|  |  |  | 		return | 
					
						
							| 
									
										
										
										
											2015-08-17 02:52:30 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-02-28 16:46:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 	c.JSON(http.StatusOK, settings) | 
					
						
							| 
									
										
										
										
											2020-09-08 04:10:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // getFrontendSettingsMap returns a json object with all the settings needed for front end initialisation.
 | 
					
						
							|  |  |  | func (hs *HTTPServer) getFrontendSettingsMap(c *models.ReqContext) (map[string]interface{}, error) { | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	enabledPlugins, err := hs.enabledPlugins(c.Req.Context(), c.OrgID) | 
					
						
							| 
									
										
										
										
											2020-09-08 04:10:06 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-02-25 17:00:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-14 18:16:13 +08:00
										 |  |  | 	pluginsToPreload := make([]*plugins.PreloadPlugin, 0) | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 	for _, app := range enabledPlugins[plugins.App] { | 
					
						
							| 
									
										
										
										
											2020-09-08 04:10:06 +08:00
										 |  |  | 		if app.Preload { | 
					
						
							| 
									
										
										
										
											2021-12-14 18:16:13 +08:00
										 |  |  | 			pluginsToPreload = append(pluginsToPreload, &plugins.PreloadPlugin{ | 
					
						
							| 
									
										
										
										
											2021-11-10 18:54:58 +08:00
										 |  |  | 				Path:    app.Module, | 
					
						
							|  |  |  | 				Version: app.Info.Version, | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2020-09-08 04:10:06 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-28 19:24:42 +08:00
										 |  |  | 	dataSources, err := hs.getFSDataSources(c, enabledPlugins) | 
					
						
							| 
									
										
										
										
											2020-09-08 04:10:06 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	defaultDS := "-- Grafana --" | 
					
						
							|  |  |  | 	for n, ds := range dataSources { | 
					
						
							| 
									
										
										
										
											2021-12-14 18:16:13 +08:00
										 |  |  | 		if ds.IsDefault { | 
					
						
							| 
									
										
										
										
											2020-09-08 04:10:06 +08:00
										 |  |  | 			defaultDS = n | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-12-29 20:36:08 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-14 18:16:13 +08:00
										 |  |  | 	panels := make(map[string]plugins.PanelDTO) | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 	for _, panel := range enabledPlugins[plugins.Panel] { | 
					
						
							|  |  |  | 		if panel.State == plugins.AlphaRelease && !hs.Cfg.PluginsEnableAlpha { | 
					
						
							| 
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-14 18:16:13 +08:00
										 |  |  | 		panels[panel.ID] = plugins.PanelDTO{ | 
					
						
							|  |  |  | 			ID:            panel.ID, | 
					
						
							|  |  |  | 			Name:          panel.Name, | 
					
						
							|  |  |  | 			Info:          panel.Info, | 
					
						
							|  |  |  | 			Module:        panel.Module, | 
					
						
							|  |  |  | 			BaseURL:       panel.BaseURL, | 
					
						
							|  |  |  | 			SkipDataQuery: panel.SkipDataQuery, | 
					
						
							|  |  |  | 			HideFromList:  panel.HideFromList, | 
					
						
							|  |  |  | 			ReleaseState:  string(panel.State), | 
					
						
							|  |  |  | 			Signature:     string(panel.Signature), | 
					
						
							|  |  |  | 			Sort:          getPanelSort(panel.ID), | 
					
						
							| 
									
										
										
										
											2015-11-21 20:46:18 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 13:39:50 +08:00
										 |  |  | 	hideVersion := hs.Cfg.AnonymousHideVersion && !c.IsSignedIn | 
					
						
							|  |  |  | 	version := setting.BuildVersion | 
					
						
							|  |  |  | 	commit := setting.BuildCommit | 
					
						
							|  |  |  | 	buildstamp := setting.BuildStamp | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if hideVersion { | 
					
						
							|  |  |  | 		version = "" | 
					
						
							|  |  |  | 		commit = "" | 
					
						
							|  |  |  | 		buildstamp = 0 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 21:54:26 +08:00
										 |  |  | 	hasAccess := accesscontrol.HasAccess(hs.AccessControl, c) | 
					
						
							| 
									
										
										
										
											2022-08-11 03:47:03 +08:00
										 |  |  | 	secretsManagerPluginEnabled := kvstore.EvaluateRemoteSecretsPlugin(hs.secretsPluginManager, hs.Cfg) == nil | 
					
						
							| 
									
										
										
										
											2021-10-05 21:54:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-29 20:36:08 +08:00
										 |  |  | 	jsonObj := map[string]interface{}{ | 
					
						
							| 
									
										
										
										
											2021-09-15 19:00:38 +08:00
										 |  |  | 		"defaultDatasource":                   defaultDS, | 
					
						
							|  |  |  | 		"datasources":                         dataSources, | 
					
						
							|  |  |  | 		"minRefreshInterval":                  setting.MinRefreshInterval, | 
					
						
							|  |  |  | 		"panels":                              panels, | 
					
						
							|  |  |  | 		"appUrl":                              hs.Cfg.AppURL, | 
					
						
							|  |  |  | 		"appSubUrl":                           hs.Cfg.AppSubURL, | 
					
						
							|  |  |  | 		"allowOrgCreate":                      (setting.AllowUserOrgCreate && c.IsSignedIn) || c.IsGrafanaAdmin, | 
					
						
							|  |  |  | 		"authProxyEnabled":                    setting.AuthProxyEnabled, | 
					
						
							|  |  |  | 		"ldapEnabled":                         hs.Cfg.LDAPEnabled, | 
					
						
							| 
									
										
										
										
											2022-07-27 22:10:47 +08:00
										 |  |  | 		"jwtHeaderName":                       hs.Cfg.JWTAuthHeaderName, | 
					
						
							|  |  |  | 		"jwtUrlLogin":                         hs.Cfg.JWTAuthURLLogin, | 
					
						
							| 
									
										
										
										
											2021-09-15 19:00:38 +08:00
										 |  |  | 		"alertingEnabled":                     setting.AlertingEnabled, | 
					
						
							|  |  |  | 		"alertingErrorOrTimeout":              setting.AlertingErrorOrTimeout, | 
					
						
							|  |  |  | 		"alertingNoDataOrNullValues":          setting.AlertingNoDataOrNullValues, | 
					
						
							|  |  |  | 		"alertingMinInterval":                 setting.AlertingMinInterval, | 
					
						
							|  |  |  | 		"liveEnabled":                         hs.Cfg.LiveMaxConnections != 0, | 
					
						
							|  |  |  | 		"autoAssignOrg":                       setting.AutoAssignOrg, | 
					
						
							|  |  |  | 		"verifyEmailEnabled":                  setting.VerifyEmailEnabled, | 
					
						
							|  |  |  | 		"sigV4AuthEnabled":                    setting.SigV4AuthEnabled, | 
					
						
							| 
									
										
										
										
											2022-08-11 22:12:57 +08:00
										 |  |  | 		"azureAuthEnabled":                    setting.AzureAuthEnabled, | 
					
						
							| 
									
										
										
										
											2022-05-16 18:45:41 +08:00
										 |  |  | 		"rbacEnabled":                         hs.Cfg.RBACEnabled, | 
					
						
							| 
									
										
										
										
											2021-09-15 19:00:38 +08:00
										 |  |  | 		"exploreEnabled":                      setting.ExploreEnabled, | 
					
						
							| 
									
										
										
										
											2022-03-29 23:27:53 +08:00
										 |  |  | 		"helpEnabled":                         setting.HelpEnabled, | 
					
						
							|  |  |  | 		"profileEnabled":                      setting.ProfileEnabled, | 
					
						
							| 
									
										
										
										
											2022-01-29 00:55:09 +08:00
										 |  |  | 		"queryHistoryEnabled":                 hs.Cfg.QueryHistoryEnabled, | 
					
						
							| 
									
										
										
										
											2021-09-15 19:00:38 +08:00
										 |  |  | 		"googleAnalyticsId":                   setting.GoogleAnalyticsId, | 
					
						
							|  |  |  | 		"rudderstackWriteKey":                 setting.RudderstackWriteKey, | 
					
						
							|  |  |  | 		"rudderstackDataPlaneUrl":             setting.RudderstackDataPlaneUrl, | 
					
						
							| 
									
										
										
										
											2021-12-06 22:42:29 +08:00
										 |  |  | 		"rudderstackSdkUrl":                   setting.RudderstackSdkUrl, | 
					
						
							|  |  |  | 		"rudderstackConfigUrl":                setting.RudderstackConfigUrl, | 
					
						
							| 
									
										
										
										
											2022-04-14 21:18:03 +08:00
										 |  |  | 		"feedbackLinksEnabled":                hs.Cfg.FeedbackLinksEnabled, | 
					
						
							| 
									
										
										
										
											2021-09-15 19:00:38 +08:00
										 |  |  | 		"applicationInsightsConnectionString": hs.Cfg.ApplicationInsightsConnectionString, | 
					
						
							|  |  |  | 		"applicationInsightsEndpointUrl":      hs.Cfg.ApplicationInsightsEndpointUrl, | 
					
						
							|  |  |  | 		"disableLoginForm":                    setting.DisableLoginForm, | 
					
						
							|  |  |  | 		"disableUserSignUp":                   !setting.AllowUserSignUp, | 
					
						
							|  |  |  | 		"loginHint":                           setting.LoginHint, | 
					
						
							|  |  |  | 		"passwordHint":                        setting.PasswordHint, | 
					
						
							|  |  |  | 		"externalUserMngInfo":                 setting.ExternalUserMngInfo, | 
					
						
							|  |  |  | 		"externalUserMngLinkUrl":              setting.ExternalUserMngLinkUrl, | 
					
						
							|  |  |  | 		"externalUserMngLinkName":             setting.ExternalUserMngLinkName, | 
					
						
							|  |  |  | 		"viewersCanEdit":                      setting.ViewersCanEdit, | 
					
						
							| 
									
										
										
										
											2022-02-17 00:14:33 +08:00
										 |  |  | 		"angularSupportEnabled":               hs.Cfg.AngularSupportEnabled, | 
					
						
							| 
									
										
										
										
											2021-09-15 19:00:38 +08:00
										 |  |  | 		"editorsCanAdmin":                     hs.Cfg.EditorsCanAdmin, | 
					
						
							|  |  |  | 		"disableSanitizeHtml":                 hs.Cfg.DisableSanitizeHtml, | 
					
						
							|  |  |  | 		"pluginsToPreload":                    pluginsToPreload, | 
					
						
							| 
									
										
										
										
											2015-01-05 17:46:58 +08:00
										 |  |  | 		"buildInfo": map[string]interface{}{ | 
					
						
							| 
									
										
										
										
											2020-06-17 13:39:50 +08:00
										 |  |  | 			"hideVersion":   hideVersion, | 
					
						
							|  |  |  | 			"version":       version, | 
					
						
							|  |  |  | 			"commit":        commit, | 
					
						
							|  |  |  | 			"buildstamp":    buildstamp, | 
					
						
							| 
									
										
										
										
											2020-01-27 16:24:44 +08:00
										 |  |  | 			"edition":       hs.License.Edition(), | 
					
						
							| 
									
										
										
										
											2022-01-31 23:06:16 +08:00
										 |  |  | 			"latestVersion": hs.grafanaUpdateChecker.LatestVersion(), | 
					
						
							|  |  |  | 			"hasUpdate":     hs.grafanaUpdateChecker.UpdateAvailable(), | 
					
						
							| 
									
										
										
										
											2016-05-17 21:00:48 +08:00
										 |  |  | 			"env":           setting.Env, | 
					
						
							| 
									
										
										
										
											2019-11-01 21:56:12 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		"licenseInfo": map[string]interface{}{ | 
					
						
							| 
									
										
										
										
											2022-01-24 23:08:05 +08:00
										 |  |  | 			"expiry":          hs.License.Expiry(), | 
					
						
							|  |  |  | 			"stateInfo":       hs.License.StateInfo(), | 
					
						
							| 
									
										
										
										
											2022-03-16 21:37:19 +08:00
										 |  |  | 			"licenseUrl":      hs.License.LicenseURL(hasAccess(accesscontrol.ReqGrafanaAdmin, licensing.PageAccess)), | 
					
						
							| 
									
										
										
										
											2022-01-24 23:08:05 +08:00
										 |  |  | 			"edition":         hs.License.Edition(), | 
					
						
							|  |  |  | 			"enabledFeatures": hs.License.EnabledFeatures(), | 
					
						
							| 
									
										
										
										
											2015-01-05 17:46:58 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-01-27 01:44:20 +08:00
										 |  |  | 		"featureToggles":                   hs.Features.GetEnabled(c.Req.Context()), | 
					
						
							| 
									
										
										
										
											2021-05-27 18:45:06 +08:00
										 |  |  | 		"rendererAvailable":                hs.RenderService.IsAvailable(), | 
					
						
							| 
									
										
										
										
											2021-06-04 19:33:49 +08:00
										 |  |  | 		"rendererVersion":                  hs.RenderService.Version(), | 
					
						
							| 
									
										
										
										
											2022-08-11 03:47:03 +08:00
										 |  |  | 		"secretsManagerPluginEnabled":      secretsManagerPluginEnabled, | 
					
						
							| 
									
										
										
										
											2021-05-27 18:45:06 +08:00
										 |  |  | 		"http2Enabled":                     hs.Cfg.Protocol == setting.HTTP2Scheme, | 
					
						
							|  |  |  | 		"sentry":                           hs.Cfg.Sentry, | 
					
						
							| 
									
										
										
										
											2022-06-28 15:25:30 +08:00
										 |  |  | 		"grafanaJavascriptAgent":           hs.Cfg.GrafanaJavascriptAgent, | 
					
						
							| 
									
										
										
										
											2021-05-27 18:45:06 +08:00
										 |  |  | 		"pluginCatalogURL":                 hs.Cfg.PluginCatalogURL, | 
					
						
							| 
									
										
										
										
											2021-08-04 17:49:05 +08:00
										 |  |  | 		"pluginAdminEnabled":               hs.Cfg.PluginAdminEnabled, | 
					
						
							| 
									
										
										
										
											2021-05-31 18:30:32 +08:00
										 |  |  | 		"pluginAdminExternalManageEnabled": hs.Cfg.PluginAdminEnabled && hs.Cfg.PluginAdminExternalManageEnabled, | 
					
						
							| 
									
										
										
										
											2021-11-15 22:51:16 +08:00
										 |  |  | 		"pluginCatalogHiddenPlugins":       hs.Cfg.PluginCatalogHiddenPlugins, | 
					
						
							| 
									
										
										
										
											2021-05-27 18:45:06 +08:00
										 |  |  | 		"expressionsEnabled":               hs.Cfg.ExpressionsEnabled, | 
					
						
							|  |  |  | 		"awsAllowedAuthProviders":          hs.Cfg.AWSAllowedAuthProviders, | 
					
						
							|  |  |  | 		"awsAssumeRoleEnabled":             hs.Cfg.AWSAssumeRoleEnabled, | 
					
						
							| 
									
										
										
										
											2021-05-12 22:23:37 +08:00
										 |  |  | 		"azure": map[string]interface{}{ | 
					
						
							|  |  |  | 			"cloud":                  hs.Cfg.Azure.Cloud, | 
					
						
							|  |  |  | 			"managedIdentityEnabled": hs.Cfg.Azure.ManagedIdentityEnabled, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2021-05-27 01:27:28 +08:00
										 |  |  | 		"caching": map[string]bool{ | 
					
						
							|  |  |  | 			"enabled": hs.Cfg.SectionWithEnvOverrides("caching").Key("enabled").MustBool(true), | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2021-11-18 05:45:05 +08:00
										 |  |  | 		"recordedQueries": map[string]bool{ | 
					
						
							| 
									
										
										
										
											2022-01-28 00:09:39 +08:00
										 |  |  | 			"enabled": hs.Cfg.SectionWithEnvOverrides("recorded_queries").Key("enabled").MustBool(true), | 
					
						
							| 
									
										
										
										
											2021-11-18 05:45:05 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-03-23 04:30:45 +08:00
										 |  |  | 		"reporting": map[string]bool{ | 
					
						
							|  |  |  | 			"enabled": hs.Cfg.SectionWithEnvOverrides("reporting").Key("enabled").MustBool(true), | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2021-11-15 22:51:16 +08:00
										 |  |  | 		"unifiedAlertingEnabled": hs.Cfg.UnifiedAlerting.Enabled, | 
					
						
							| 
									
										
										
										
											2022-08-01 21:01:14 +08:00
										 |  |  | 		"unifiedAlerting": map[string]interface{}{ | 
					
						
							|  |  |  | 			"minInterval": hs.Cfg.UnifiedAlerting.MinInterval.String(), | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2021-07-22 04:48:20 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-17 01:49:50 +08:00
										 |  |  | 	if hs.ThumbService != nil { | 
					
						
							|  |  |  | 		jsonObj["dashboardPreviews"] = hs.ThumbService.GetDashboardPreviewsSetupSettings(c) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-22 04:48:20 +08:00
										 |  |  | 	if hs.Cfg.GeomapDefaultBaseLayerConfig != nil { | 
					
						
							|  |  |  | 		jsonObj["geomapDefaultBaseLayerConfig"] = hs.Cfg.GeomapDefaultBaseLayerConfig | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if !hs.Cfg.GeomapEnableCustomBaseLayers { | 
					
						
							|  |  |  | 		jsonObj["geomapDisableCustomBaseLayer"] = true | 
					
						
							| 
									
										
										
										
											2014-12-29 20:36:08 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return jsonObj, nil | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-02-18 21:06:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | func (hs *HTTPServer) getFSDataSources(c *models.ReqContext, enabledPlugins EnabledPlugins) (map[string]plugins.DataSourceDTO, error) { | 
					
						
							| 
									
										
										
										
											2022-06-28 00:23:15 +08:00
										 |  |  | 	orgDataSources := make([]*datasources.DataSource, 0) | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	if c.OrgID != 0 { | 
					
						
							|  |  |  | 		query := datasources.GetDataSourcesQuery{OrgId: c.OrgID, DataSourceLimit: hs.Cfg.DataSourceLimit} | 
					
						
							| 
									
										
										
										
											2022-08-10 21:04:51 +08:00
										 |  |  | 		err := hs.DataSourcesService.GetDataSources(c.Req.Context(), &query) | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return nil, err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		filtered, err := hs.filterDatasourcesByQueryPermission(c.Req.Context(), c.SignedInUser, query.Result) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return nil, err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		orgDataSources = filtered | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dataSources := make(map[string]plugins.DataSourceDTO) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, ds := range orgDataSources { | 
					
						
							|  |  |  | 		url := ds.Url | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-28 00:23:15 +08:00
										 |  |  | 		if ds.Access == datasources.DS_ACCESS_PROXY { | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 			url = "/api/datasources/proxy/" + strconv.FormatInt(ds.Id, 10) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		dsDTO := plugins.DataSourceDTO{ | 
					
						
							|  |  |  | 			ID:        ds.Id, | 
					
						
							|  |  |  | 			UID:       ds.Uid, | 
					
						
							|  |  |  | 			Type:      ds.Type, | 
					
						
							|  |  |  | 			Name:      ds.Name, | 
					
						
							|  |  |  | 			URL:       url, | 
					
						
							|  |  |  | 			IsDefault: ds.IsDefault, | 
					
						
							|  |  |  | 			Access:    string(ds.Access), | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		plugin, exists := enabledPlugins.Get(plugins.DataSource, ds.Type) | 
					
						
							|  |  |  | 		if !exists { | 
					
						
							|  |  |  | 			c.Logger.Error("Could not find plugin definition for data source", "datasource_type", ds.Type) | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		dsDTO.Preload = plugin.Preload | 
					
						
							|  |  |  | 		dsDTO.Module = plugin.Module | 
					
						
							|  |  |  | 		dsDTO.PluginMeta = &plugins.PluginMetaDTO{ | 
					
						
							|  |  |  | 			JSONData:  plugin.JSONData, | 
					
						
							|  |  |  | 			Signature: plugin.Signature, | 
					
						
							|  |  |  | 			Module:    plugin.Module, | 
					
						
							|  |  |  | 			BaseURL:   plugin.BaseURL, | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ds.JsonData == nil { | 
					
						
							|  |  |  | 			dsDTO.JSONData = make(map[string]interface{}) | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			dsDTO.JSONData = ds.JsonData.MustMap() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-28 00:23:15 +08:00
										 |  |  | 		if ds.Access == datasources.DS_ACCESS_DIRECT { | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 			if ds.BasicAuth { | 
					
						
							| 
									
										
										
										
											2022-04-26 00:57:45 +08:00
										 |  |  | 				password, err := hs.DataSourcesService.DecryptedBasicAuthPassword(c.Req.Context(), ds) | 
					
						
							|  |  |  | 				if err != nil { | 
					
						
							|  |  |  | 					return nil, err | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 				dsDTO.BasicAuth = util.GetBasicAuthHeader( | 
					
						
							|  |  |  | 					ds.BasicAuthUser, | 
					
						
							| 
									
										
										
										
											2022-04-26 00:57:45 +08:00
										 |  |  | 					password, | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 				) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if ds.WithCredentials { | 
					
						
							|  |  |  | 				dsDTO.WithCredentials = ds.WithCredentials | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-28 00:23:15 +08:00
										 |  |  | 			if ds.Type == datasources.DS_INFLUXDB_08 { | 
					
						
							| 
									
										
										
										
											2022-04-26 00:57:45 +08:00
										 |  |  | 				password, err := hs.DataSourcesService.DecryptedPassword(c.Req.Context(), ds) | 
					
						
							|  |  |  | 				if err != nil { | 
					
						
							|  |  |  | 					return nil, err | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 				dsDTO.Username = ds.User | 
					
						
							| 
									
										
										
										
											2022-04-26 00:57:45 +08:00
										 |  |  | 				dsDTO.Password = password | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 				dsDTO.URL = url + "/db/" + ds.Database | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-28 00:23:15 +08:00
										 |  |  | 			if ds.Type == datasources.DS_INFLUXDB { | 
					
						
							| 
									
										
										
										
											2022-04-26 00:57:45 +08:00
										 |  |  | 				password, err := hs.DataSourcesService.DecryptedPassword(c.Req.Context(), ds) | 
					
						
							|  |  |  | 				if err != nil { | 
					
						
							|  |  |  | 					return nil, err | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 				dsDTO.Username = ds.User | 
					
						
							| 
									
										
										
										
											2022-04-26 00:57:45 +08:00
										 |  |  | 				dsDTO.Password = password | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 				dsDTO.URL = url | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-28 00:23:15 +08:00
										 |  |  | 		if (ds.Type == datasources.DS_INFLUXDB) || (ds.Type == datasources.DS_ES) { | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 			dsDTO.Database = ds.Database | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-28 00:23:15 +08:00
										 |  |  | 		if ds.Type == datasources.DS_PROMETHEUS { | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 			// add unproxied server URL for link to Prometheus web UI
 | 
					
						
							|  |  |  | 			ds.JsonData.Set("directUrl", ds.Url) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		dataSources[ds.Name] = dsDTO | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// add data sources that are built in (meaning they are not added via data sources page, nor have any entry in
 | 
					
						
							|  |  |  | 	// the datasource table)
 | 
					
						
							|  |  |  | 	for _, ds := range hs.pluginStore.Plugins(c.Req.Context(), plugins.DataSource) { | 
					
						
							|  |  |  | 		if ds.BuiltIn { | 
					
						
							|  |  |  | 			dto := plugins.DataSourceDTO{ | 
					
						
							|  |  |  | 				Type:     string(ds.Type), | 
					
						
							|  |  |  | 				Name:     ds.Name, | 
					
						
							|  |  |  | 				JSONData: make(map[string]interface{}), | 
					
						
							|  |  |  | 				PluginMeta: &plugins.PluginMetaDTO{ | 
					
						
							|  |  |  | 					JSONData:  ds.JSONData, | 
					
						
							|  |  |  | 					Signature: ds.Signature, | 
					
						
							|  |  |  | 					Module:    ds.Module, | 
					
						
							|  |  |  | 					BaseURL:   ds.BaseURL, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if ds.Name == grafanads.DatasourceName { | 
					
						
							|  |  |  | 				dto.ID = grafanads.DatasourceID | 
					
						
							|  |  |  | 				dto.UID = grafanads.DatasourceUID | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			dataSources[ds.Name] = dto | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return dataSources, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-26 23:42:39 +08:00
										 |  |  | func getPanelSort(id string) int { | 
					
						
							|  |  |  | 	sort := 100 | 
					
						
							|  |  |  | 	switch id { | 
					
						
							| 
									
										
										
										
											2021-01-11 00:41:20 +08:00
										 |  |  | 	case "timeseries": | 
					
						
							| 
									
										
										
										
											2021-05-05 19:19:14 +08:00
										 |  |  | 		sort = 1 | 
					
						
							| 
									
										
										
										
											2021-05-03 22:49:09 +08:00
										 |  |  | 	case "barchart": | 
					
						
							| 
									
										
										
										
											2021-05-05 19:19:14 +08:00
										 |  |  | 		sort = 2 | 
					
						
							| 
									
										
										
										
											2021-05-03 22:49:09 +08:00
										 |  |  | 	case "stat": | 
					
						
							| 
									
										
										
										
											2021-05-05 19:19:14 +08:00
										 |  |  | 		sort = 3 | 
					
						
							| 
									
										
										
										
											2021-05-03 22:49:09 +08:00
										 |  |  | 	case "gauge": | 
					
						
							| 
									
										
										
										
											2021-05-05 19:19:14 +08:00
										 |  |  | 		sort = 4 | 
					
						
							| 
									
										
										
										
											2021-05-03 22:49:09 +08:00
										 |  |  | 	case "bargauge": | 
					
						
							| 
									
										
										
										
											2021-05-05 19:19:14 +08:00
										 |  |  | 		sort = 5 | 
					
						
							| 
									
										
										
										
											2021-05-03 22:49:09 +08:00
										 |  |  | 	case "table": | 
					
						
							| 
									
										
										
										
											2021-05-05 19:19:14 +08:00
										 |  |  | 		sort = 6 | 
					
						
							| 
									
										
										
										
											2021-05-03 22:49:09 +08:00
										 |  |  | 	case "singlestat": | 
					
						
							| 
									
										
										
										
											2021-05-05 19:19:14 +08:00
										 |  |  | 		sort = 7 | 
					
						
							| 
									
										
										
										
											2021-05-03 22:49:09 +08:00
										 |  |  | 	case "piechart": | 
					
						
							| 
									
										
										
										
											2021-05-05 19:19:14 +08:00
										 |  |  | 		sort = 8 | 
					
						
							| 
									
										
										
										
											2021-05-18 04:00:04 +08:00
										 |  |  | 	case "state-timeline": | 
					
						
							| 
									
										
										
										
											2019-02-16 04:33:36 +08:00
										 |  |  | 		sort = 9 | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  | 	case "heatmap": | 
					
						
							| 
									
										
										
										
											2020-01-17 16:43:17 +08:00
										 |  |  | 		sort = 10 | 
					
						
							| 
									
										
										
										
											2021-05-30 02:24:14 +08:00
										 |  |  | 	case "status-history": | 
					
						
							| 
									
										
										
										
											2021-01-11 00:41:20 +08:00
										 |  |  | 		sort = 11 | 
					
						
							| 
									
										
										
										
											2021-05-20 23:36:20 +08:00
										 |  |  | 	case "histogram": | 
					
						
							| 
									
										
										
										
											2021-01-11 00:41:20 +08:00
										 |  |  | 		sort = 12 | 
					
						
							| 
									
										
										
										
											2021-05-20 23:36:20 +08:00
										 |  |  | 	case "graph": | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  | 		sort = 13 | 
					
						
							| 
									
										
										
										
											2021-05-20 23:36:20 +08:00
										 |  |  | 	case "text": | 
					
						
							| 
									
										
										
										
											2021-05-03 22:49:09 +08:00
										 |  |  | 		sort = 14 | 
					
						
							| 
									
										
										
										
											2021-05-20 23:36:20 +08:00
										 |  |  | 	case "alertlist": | 
					
						
							| 
									
										
										
										
											2021-05-05 19:19:14 +08:00
										 |  |  | 		sort = 15 | 
					
						
							| 
									
										
										
										
											2021-05-20 23:36:20 +08:00
										 |  |  | 	case "dashlist": | 
					
						
							| 
									
										
										
										
											2021-05-18 04:00:04 +08:00
										 |  |  | 		sort = 16 | 
					
						
							| 
									
										
										
										
											2021-05-20 23:36:20 +08:00
										 |  |  | 	case "news": | 
					
						
							|  |  |  | 		sort = 17 | 
					
						
							| 
									
										
										
										
											2016-10-26 23:42:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return sort | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | // EnabledPlugins represents a mapping from plugin types (panel, data source, etc.) to plugin IDs to plugins
 | 
					
						
							| 
									
										
										
										
											2021-11-17 19:04:22 +08:00
										 |  |  | // For example ["panel"] -> ["piechart"] -> {pie chart plugin DTO}
 | 
					
						
							|  |  |  | type EnabledPlugins map[plugins.Type]map[string]plugins.PluginDTO | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-17 19:04:22 +08:00
										 |  |  | func (ep EnabledPlugins) Get(pluginType plugins.Type, pluginID string) (plugins.PluginDTO, bool) { | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 	if _, exists := ep[pluginType][pluginID]; exists { | 
					
						
							|  |  |  | 		return ep[pluginType][pluginID], true | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-17 19:04:22 +08:00
										 |  |  | 	return plugins.PluginDTO{}, false | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-02 20:42:55 +08:00
										 |  |  | func (hs *HTTPServer) enabledPlugins(ctx context.Context, orgID int64) (EnabledPlugins, error) { | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 	ep := make(EnabledPlugins) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-02 20:42:55 +08:00
										 |  |  | 	pluginSettingMap, err := hs.pluginSettings(ctx, orgID) | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return ep, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-17 19:04:22 +08:00
										 |  |  | 	apps := make(map[string]plugins.PluginDTO) | 
					
						
							|  |  |  | 	for _, app := range hs.pluginStore.Plugins(ctx, plugins.App) { | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 		if b, exists := pluginSettingMap[app.ID]; exists { | 
					
						
							|  |  |  | 			app.Pinned = b.Pinned | 
					
						
							|  |  |  | 			apps[app.ID] = app | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ep[plugins.App] = apps | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-17 19:04:22 +08:00
										 |  |  | 	dataSources := make(map[string]plugins.PluginDTO) | 
					
						
							|  |  |  | 	for _, ds := range hs.pluginStore.Plugins(ctx, plugins.DataSource) { | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 		if _, exists := pluginSettingMap[ds.ID]; exists { | 
					
						
							|  |  |  | 			dataSources[ds.ID] = ds | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ep[plugins.DataSource] = dataSources | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-17 19:04:22 +08:00
										 |  |  | 	panels := make(map[string]plugins.PluginDTO) | 
					
						
							|  |  |  | 	for _, p := range hs.pluginStore.Plugins(ctx, plugins.Panel) { | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 		if _, exists := pluginSettingMap[p.ID]; exists { | 
					
						
							|  |  |  | 			panels[p.ID] = p | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ep[plugins.Panel] = panels | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ep, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | func (hs *HTTPServer) pluginSettings(ctx context.Context, orgID int64) (map[string]*pluginsettings.DTO, error) { | 
					
						
							|  |  |  | 	pluginSettings := make(map[string]*pluginsettings.DTO) | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 	// fill settings from database
 | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 	if pss, err := hs.PluginSettings.GetPluginSettings(ctx, &pluginsettings.GetArgs{OrgID: orgID}); err != nil { | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		for _, ps := range pss { | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 			pluginSettings[ps.PluginID] = ps | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 	// fill settings from app plugins
 | 
					
						
							| 
									
										
										
										
											2021-11-17 19:04:22 +08:00
										 |  |  | 	for _, plugin := range hs.pluginStore.Plugins(ctx, plugins.App) { | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 		// ignore settings that already exist
 | 
					
						
							|  |  |  | 		if _, exists := pluginSettings[plugin.ID]; exists { | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 		// add new setting which is enabled depending on if AutoEnabled: true
 | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 		pluginSetting := &pluginsettings.DTO{ | 
					
						
							|  |  |  | 			PluginID: plugin.ID, | 
					
						
							|  |  |  | 			OrgID:    orgID, | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 			Enabled:  plugin.AutoEnabled, | 
					
						
							|  |  |  | 			Pinned:   plugin.AutoEnabled, | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 		pluginSettings[plugin.ID] = pluginSetting | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// fill settings from all remaining plugins (including potential app child plugins)
 | 
					
						
							| 
									
										
										
										
											2021-11-17 19:04:22 +08:00
										 |  |  | 	for _, plugin := range hs.pluginStore.Plugins(ctx) { | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 		// ignore settings that already exist
 | 
					
						
							|  |  |  | 		if _, exists := pluginSettings[plugin.ID]; exists { | 
					
						
							|  |  |  | 			continue | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 		// add new setting which is enabled by default
 | 
					
						
							| 
									
										
										
										
											2022-03-19 03:49:13 +08:00
										 |  |  | 		pluginSetting := &pluginsettings.DTO{ | 
					
						
							|  |  |  | 			PluginID: plugin.ID, | 
					
						
							|  |  |  | 			OrgID:    orgID, | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 			Enabled:  true, | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 		// if plugin is included in an app, check app settings
 | 
					
						
							|  |  |  | 		if plugin.IncludedInAppID != "" { | 
					
						
							|  |  |  | 			// app child plugins are disabled unless app is enabled
 | 
					
						
							|  |  |  | 			pluginSetting.Enabled = false | 
					
						
							|  |  |  | 			if p, exists := pluginSettings[plugin.IncludedInAppID]; exists { | 
					
						
							|  |  |  | 				pluginSetting.Enabled = p.Enabled | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 		pluginSettings[plugin.ID] = pluginSetting | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-05 22:07:53 +08:00
										 |  |  | 	return pluginSettings, nil | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | } |