UNPKG

@grafana/runtime

Version:
218 lines (215 loc) • 7.4 kB
import { merge } from 'lodash'; import { systemDateFormats, getThemeById } from '@grafana/data'; "use strict"; class GrafanaBootConfig { constructor(options) { this.publicDashboardsEnabled = true; this.snapshotEnabled = true; this.datasources = {}; this.panels = {}; this.apps = {}; this.auth = {}; this.minRefreshInterval = ""; this.appUrl = ""; this.appSubUrl = ""; this.namespace = "default"; this.windowTitlePrefix = "Grafana - "; this.buildInfo = { version: "1.0", commit: "1", env: "production" }; this.externalUserMngLinkUrl = ""; this.externalUserMngLinkName = ""; this.externalUserMngInfo = ""; this.externalUserMngAnalytics = false; this.externalUserMngAnalyticsParams = ""; this.allowOrgCreate = false; this.feedbackLinksEnabled = true; this.disableLoginForm = false; this.defaultDatasource = ""; // UID this.authProxyEnabled = false; this.exploreEnabled = false; this.queryHistoryEnabled = false; this.helpEnabled = false; this.profileEnabled = false; this.newsFeedEnabled = true; this.ldapEnabled = false; this.jwtHeaderName = ""; this.jwtUrlLogin = false; this.sigV4AuthEnabled = false; this.azureAuthEnabled = false; this.secureSocksDSProxyEnabled = false; this.samlEnabled = false; this.samlName = ""; this.autoAssignOrg = true; this.verifyEmailEnabled = false; this.oauth = {}; this.rbacEnabled = true; this.disableUserSignUp = false; this.loginHint = ""; this.passwordHint = ""; this.viewersCanEdit = false; this.disableSanitizeHtml = false; this.trustedTypesDefaultPolicyEnabled = false; this.cspReportOnlyEnabled = false; this.liveEnabled = true; this.liveMessageSizeLimit = 65536; this.featureToggles = {}; this.anonymousEnabled = false; this.licenseInfo = {}; this.rendererAvailable = false; this.rendererVersion = ""; this.rendererDefaultImageWidth = 1e3; this.rendererDefaultImageHeight = 500; this.rendererDefaultImageScale = 1; this.supportBundlesEnabled = false; this.http2Enabled = false; this.grafanaJavascriptAgent = { enabled: false, customEndpoint: "", apiKey: "", allInstrumentationsEnabled: false, errorInstrumentalizationEnabled: true, consoleInstrumentalizationEnabled: false, webVitalsInstrumentalizationEnabled: false, tracingInstrumentalizationEnabled: false }; this.pluginCatalogURL = "https://grafana.com/grafana/plugins/"; this.pluginAdminEnabled = true; this.pluginAdminExternalManageEnabled = false; this.pluginCatalogHiddenPlugins = []; this.pluginCatalogManagedPlugins = []; this.pluginCatalogPreinstalledPlugins = []; this.pluginsCDNBaseURL = ""; this.expressionsEnabled = false; this.awsAllowedAuthProviders = []; this.awsAssumeRoleEnabled = false; this.azure = { managedIdentityEnabled: false, workloadIdentityEnabled: false, userIdentityEnabled: false, userIdentityFallbackCredentialsEnabled: false, azureEntraPasswordCredentialsEnabled: false }; this.caching = { enabled: false }; this.unifiedAlertingEnabled = false; this.unifiedAlerting = { minInterval: "", stateHistory: { backend: void 0, primary: void 0, prometheusTargetDatasourceUID: void 0, prometheusMetricName: void 0 }, recordingRulesEnabled: false, defaultRecordingRulesTargetDatasourceUID: void 0, // Backward compatibility fields - populated by backend alertStateHistoryBackend: void 0, alertStateHistoryPrimary: void 0 }; this.recordedQueries = { enabled: true }; this.featureHighlights = { enabled: false }; this.reporting = { enabled: true }; this.analytics = { enabled: true }; this.googleAnalytics4SendManualPageViews = false; this.analyticsConsoleReporting = false; this.dashboardPerformanceMetrics = []; this.panelSeriesLimit = 0; this.sqlConnectionLimits = { maxOpenConns: 100, maxIdleConns: 100, connMaxLifetime: 14400 }; this.defaultDatasourceManageAlertsUiToggle = true; this.defaultAllowRecordingRulesTargetAlertsUiToggle = true; this.enableFrontendSandboxForPlugins = []; this.cloudMigrationPollIntervalMs = 2e3; this.exploreDefaultTimeOffset = "1h"; this.listDashboardScopesEndpoint = ""; this.listScopesEndpoint = ""; this.bootData = options.bootData; merge(this, options); if (this.dateFormats) { systemDateFormats.update(this.dateFormats); } overrideFeatureTogglesFromUrl(this); overrideFeatureTogglesFromLocalStorage(this); this.theme2 = getThemeById(this.bootData.user.theme); this.bootData.user.lightTheme = this.theme2.isLight; this.theme = this.theme2.v1; this.regionalFormat = options.bootData.user.regionalFormat; } } function overrideFeatureTogglesFromLocalStorage(config2) { const featureToggles = config2.featureToggles; const localStorageKey = "grafana.featureToggles"; const localStorageValue = window.localStorage.getItem(localStorageKey); if (localStorageValue) { const features = localStorageValue.split(","); for (const feature of features) { const [featureName, featureValue] = feature.split("="); const toggleState = featureValue === "true" || featureValue === "1"; featureToggles[featureName] = toggleState; console.log(`Setting feature toggle ${featureName} = ${toggleState} via localstorage`); } } } function overrideFeatureTogglesFromUrl(config2) { if (window.location.href.indexOf("__feature") === -1) { return; } const isDevelopment = config2.buildInfo.env === "development"; const safeRuntimeFeatureFlags = /* @__PURE__ */ new Set(["queryServiceFromUI", "dashboardSceneSolo"]); const params = new URLSearchParams(window.location.search); params.forEach((value, key) => { if (key.startsWith("__feature.")) { const featureToggles = config2.featureToggles; const featureName = key.substring(10); const toggleState = value === "true" || value === ""; if (toggleState !== featureToggles[key]) { if (isDevelopment || safeRuntimeFeatureFlags.has(featureName)) { featureToggles[featureName] = toggleState; console.log(`Setting feature toggle ${featureName} = ${toggleState} via url`); } else { console.log(`Unable to change feature toggle ${featureName} via url in production.`); } } } }); } let bootData = window.grafanaBootData; if (!bootData) { if (process.env.NODE_ENV !== "test") { console.error("window.grafanaBootData was not set by the time config was initialized"); } bootData = { assets: { dark: "", light: "" }, settings: {}, user: {}, navTree: [] }; } const config = new GrafanaBootConfig({ ...bootData.settings, // need to separately include bootData here // this allows people to access the user object on config.bootData.user and maintains backwards compatibility // TODO expose a user object (similar to `GrafanaBootConfig`) and deprecate this recursive bootData bootData }); export { GrafanaBootConfig, config }; //# sourceMappingURL=config.mjs.map