setting.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. // Copyright 2014 Unknwon
  2. // Copyright 2014 Torkel Ödegaard
  3. package setting
  4. import (
  5. "bytes"
  6. "fmt"
  7. "net/url"
  8. "os"
  9. "path"
  10. "path/filepath"
  11. "regexp"
  12. "runtime"
  13. "strings"
  14. "gopkg.in/ini.v1"
  15. "github.com/go-macaron/session"
  16. "github.com/grafana/grafana/pkg/log"
  17. "github.com/grafana/grafana/pkg/util"
  18. )
  19. type Scheme string
  20. const (
  21. HTTP Scheme = "http"
  22. HTTPS Scheme = "https"
  23. SOCKET Scheme = "socket"
  24. DEFAULT_HTTP_ADDR string = "0.0.0.0"
  25. )
  26. const (
  27. DEV string = "development"
  28. PROD string = "production"
  29. TEST string = "test"
  30. )
  31. var (
  32. // App settings.
  33. Env = DEV
  34. AppUrl string
  35. AppSubUrl string
  36. InstanceName string
  37. // build
  38. BuildVersion string
  39. BuildCommit string
  40. BuildStamp int64
  41. Enterprise bool
  42. ApplicationName string
  43. // Paths
  44. LogsPath string
  45. HomePath string
  46. DataPath string
  47. PluginsPath string
  48. CustomInitPath = "conf/custom.ini"
  49. // Log settings.
  50. LogModes []string
  51. LogConfigs []util.DynMap
  52. // Http server options
  53. Protocol Scheme
  54. Domain string
  55. HttpAddr, HttpPort string
  56. SshPort int
  57. CertFile, KeyFile string
  58. SocketPath string
  59. RouterLogging bool
  60. DataProxyLogging bool
  61. StaticRootPath string
  62. EnableGzip bool
  63. EnforceDomain bool
  64. // Security settings.
  65. SecretKey string
  66. LogInRememberDays int
  67. CookieUserName string
  68. CookieRememberName string
  69. DisableGravatar bool
  70. EmailCodeValidMinutes int
  71. DataProxyWhiteList map[string]bool
  72. DisableBruteForceLoginProtection bool
  73. // Snapshots
  74. ExternalSnapshotUrl string
  75. ExternalSnapshotName string
  76. ExternalEnabled bool
  77. SnapShotRemoveExpired bool
  78. // Dashboard history
  79. DashboardVersionsToKeep int
  80. // User settings
  81. AllowUserSignUp bool
  82. AllowUserOrgCreate bool
  83. AutoAssignOrg bool
  84. AutoAssignOrgRole string
  85. VerifyEmailEnabled bool
  86. LoginHint string
  87. DefaultTheme string
  88. DisableLoginForm bool
  89. DisableSignoutMenu bool
  90. ExternalUserMngLinkUrl string
  91. ExternalUserMngLinkName string
  92. ExternalUserMngInfo string
  93. ViewersCanEdit bool
  94. // Http auth
  95. AdminUser string
  96. AdminPassword string
  97. AnonymousEnabled bool
  98. AnonymousOrgName string
  99. AnonymousOrgRole string
  100. // Auth proxy settings
  101. AuthProxyEnabled bool
  102. AuthProxyHeaderName string
  103. AuthProxyHeaderProperty string
  104. AuthProxyAutoSignUp bool
  105. AuthProxyLdapSyncTtl int
  106. AuthProxyWhitelist string
  107. // Basic Auth
  108. BasicAuthEnabled bool
  109. // Plugin settings
  110. PluginAppsSkipVerifyTLS bool
  111. // Session settings.
  112. SessionOptions session.Options
  113. SessionConnMaxLifetime int64
  114. // Global setting objects.
  115. Raw *ini.File
  116. ConfRootPath string
  117. IsWindows bool
  118. // PhantomJs Rendering
  119. ImagesDir string
  120. PhantomDir string
  121. // for logging purposes
  122. configFiles []string
  123. appliedCommandLineProperties []string
  124. appliedEnvOverrides []string
  125. ReportingEnabled bool
  126. CheckForUpdates bool
  127. GoogleAnalyticsId string
  128. GoogleTagManagerId string
  129. // LDAP
  130. LdapEnabled bool
  131. LdapConfigFile string
  132. LdapAllowSignup = true
  133. // QUOTA
  134. Quota QuotaSettings
  135. // Alerting
  136. AlertingEnabled bool
  137. ExecuteAlerts bool
  138. // Explore UI
  139. ExploreEnabled bool
  140. // logger
  141. logger log.Logger
  142. // Grafana.NET URL
  143. GrafanaComUrl string
  144. // S3 temp image store
  145. S3TempImageStoreBucketUrl string
  146. S3TempImageStoreAccessKey string
  147. S3TempImageStoreSecretKey string
  148. ImageUploadProvider string
  149. )
  150. type Cfg struct {
  151. Raw *ini.File
  152. // Paths
  153. ProvisioningPath string
  154. // SMTP email settings
  155. Smtp SmtpSettings
  156. ImagesDir string
  157. DisableBruteForceLoginProtection bool
  158. }
  159. type CommandLineArgs struct {
  160. Config string
  161. HomePath string
  162. Args []string
  163. }
  164. func init() {
  165. IsWindows = runtime.GOOS == "windows"
  166. logger = log.New("settings")
  167. }
  168. func parseAppUrlAndSubUrl(section *ini.Section) (string, string) {
  169. appUrl := section.Key("root_url").MustString("http://localhost:3000/")
  170. if appUrl[len(appUrl)-1] != '/' {
  171. appUrl += "/"
  172. }
  173. // Check if has app suburl.
  174. url, err := url.Parse(appUrl)
  175. if err != nil {
  176. log.Fatal(4, "Invalid root_url(%s): %s", appUrl, err)
  177. }
  178. appSubUrl := strings.TrimSuffix(url.Path, "/")
  179. return appUrl, appSubUrl
  180. }
  181. func ToAbsUrl(relativeUrl string) string {
  182. return AppUrl + relativeUrl
  183. }
  184. func shouldRedactKey(s string) bool {
  185. uppercased := strings.ToUpper(s)
  186. return strings.Contains(uppercased, "PASSWORD") || strings.Contains(uppercased, "SECRET") || strings.Contains(uppercased, "PROVIDER_CONFIG")
  187. }
  188. func shouldRedactURLKey(s string) bool {
  189. uppercased := strings.ToUpper(s)
  190. return strings.Contains(uppercased, "DATABASE_URL")
  191. }
  192. func applyEnvVariableOverrides(file *ini.File) error {
  193. appliedEnvOverrides = make([]string, 0)
  194. for _, section := range file.Sections() {
  195. for _, key := range section.Keys() {
  196. sectionName := strings.ToUpper(strings.Replace(section.Name(), ".", "_", -1))
  197. keyName := strings.ToUpper(strings.Replace(key.Name(), ".", "_", -1))
  198. envKey := fmt.Sprintf("GF_%s_%s", sectionName, keyName)
  199. envValue := os.Getenv(envKey)
  200. if len(envValue) > 0 {
  201. key.SetValue(envValue)
  202. if shouldRedactKey(envKey) {
  203. envValue = "*********"
  204. }
  205. if shouldRedactURLKey(envKey) {
  206. u, err := url.Parse(envValue)
  207. if err != nil {
  208. return fmt.Errorf("could not parse environment variable. key: %s, value: %s. error: %v", envKey, envValue, err)
  209. }
  210. ui := u.User
  211. if ui != nil {
  212. _, exists := ui.Password()
  213. if exists {
  214. u.User = url.UserPassword(ui.Username(), "-redacted-")
  215. envValue = u.String()
  216. }
  217. }
  218. }
  219. appliedEnvOverrides = append(appliedEnvOverrides, fmt.Sprintf("%s=%s", envKey, envValue))
  220. }
  221. }
  222. }
  223. return nil
  224. }
  225. func applyCommandLineDefaultProperties(props map[string]string, file *ini.File) {
  226. appliedCommandLineProperties = make([]string, 0)
  227. for _, section := range file.Sections() {
  228. for _, key := range section.Keys() {
  229. keyString := fmt.Sprintf("default.%s.%s", section.Name(), key.Name())
  230. value, exists := props[keyString]
  231. if exists {
  232. key.SetValue(value)
  233. if shouldRedactKey(keyString) {
  234. value = "*********"
  235. }
  236. appliedCommandLineProperties = append(appliedCommandLineProperties, fmt.Sprintf("%s=%s", keyString, value))
  237. }
  238. }
  239. }
  240. }
  241. func applyCommandLineProperties(props map[string]string, file *ini.File) {
  242. for _, section := range file.Sections() {
  243. sectionName := section.Name() + "."
  244. if section.Name() == ini.DEFAULT_SECTION {
  245. sectionName = ""
  246. }
  247. for _, key := range section.Keys() {
  248. keyString := sectionName + key.Name()
  249. value, exists := props[keyString]
  250. if exists {
  251. appliedCommandLineProperties = append(appliedCommandLineProperties, fmt.Sprintf("%s=%s", keyString, value))
  252. key.SetValue(value)
  253. }
  254. }
  255. }
  256. }
  257. func getCommandLineProperties(args []string) map[string]string {
  258. props := make(map[string]string)
  259. for _, arg := range args {
  260. if !strings.HasPrefix(arg, "cfg:") {
  261. continue
  262. }
  263. trimmed := strings.TrimPrefix(arg, "cfg:")
  264. parts := strings.Split(trimmed, "=")
  265. if len(parts) != 2 {
  266. log.Fatal(3, "Invalid command line argument", arg)
  267. return nil
  268. }
  269. props[parts[0]] = parts[1]
  270. }
  271. return props
  272. }
  273. func makeAbsolute(path string, root string) string {
  274. if filepath.IsAbs(path) {
  275. return path
  276. }
  277. return filepath.Join(root, path)
  278. }
  279. func evalEnvVarExpression(value string) string {
  280. regex := regexp.MustCompile(`\${(\w+)}`)
  281. return regex.ReplaceAllStringFunc(value, func(envVar string) string {
  282. envVar = strings.TrimPrefix(envVar, "${")
  283. envVar = strings.TrimSuffix(envVar, "}")
  284. envValue := os.Getenv(envVar)
  285. // if env variable is hostname and it is empty use os.Hostname as default
  286. if envVar == "HOSTNAME" && envValue == "" {
  287. envValue, _ = os.Hostname()
  288. }
  289. return envValue
  290. })
  291. }
  292. func evalConfigValues(file *ini.File) {
  293. for _, section := range file.Sections() {
  294. for _, key := range section.Keys() {
  295. key.SetValue(evalEnvVarExpression(key.Value()))
  296. }
  297. }
  298. }
  299. func loadSpecifedConfigFile(configFile string, masterFile *ini.File) error {
  300. if configFile == "" {
  301. configFile = filepath.Join(HomePath, CustomInitPath)
  302. // return without error if custom file does not exist
  303. if !pathExists(configFile) {
  304. return nil
  305. }
  306. }
  307. userConfig, err := ini.Load(configFile)
  308. if err != nil {
  309. return fmt.Errorf("Failed to parse %v, %v", configFile, err)
  310. }
  311. userConfig.BlockMode = false
  312. for _, section := range userConfig.Sections() {
  313. for _, key := range section.Keys() {
  314. if key.Value() == "" {
  315. continue
  316. }
  317. defaultSec, err := masterFile.GetSection(section.Name())
  318. if err != nil {
  319. defaultSec, _ = masterFile.NewSection(section.Name())
  320. }
  321. defaultKey, err := defaultSec.GetKey(key.Name())
  322. if err != nil {
  323. defaultKey, _ = defaultSec.NewKey(key.Name(), key.Value())
  324. }
  325. defaultKey.SetValue(key.Value())
  326. }
  327. }
  328. configFiles = append(configFiles, configFile)
  329. return nil
  330. }
  331. func loadConfiguration(args *CommandLineArgs) (*ini.File, error) {
  332. var err error
  333. // load config defaults
  334. defaultConfigFile := path.Join(HomePath, "conf/defaults.ini")
  335. configFiles = append(configFiles, defaultConfigFile)
  336. // check if config file exists
  337. if _, err := os.Stat(defaultConfigFile); os.IsNotExist(err) {
  338. fmt.Println("Grafana-server Init Failed: Could not find config defaults, make sure homepath command line parameter is set or working directory is homepath")
  339. os.Exit(1)
  340. }
  341. // load defaults
  342. parsedFile, err := ini.Load(defaultConfigFile)
  343. if err != nil {
  344. fmt.Println(fmt.Sprintf("Failed to parse defaults.ini, %v", err))
  345. os.Exit(1)
  346. return nil, err
  347. }
  348. parsedFile.BlockMode = false
  349. // command line props
  350. commandLineProps := getCommandLineProperties(args.Args)
  351. // load default overrides
  352. applyCommandLineDefaultProperties(commandLineProps, parsedFile)
  353. // load specified config file
  354. err = loadSpecifedConfigFile(args.Config, parsedFile)
  355. if err != nil {
  356. initLogging(parsedFile)
  357. log.Fatal(3, err.Error())
  358. }
  359. // apply environment overrides
  360. err = applyEnvVariableOverrides(parsedFile)
  361. if err != nil {
  362. return nil, err
  363. }
  364. // apply command line overrides
  365. applyCommandLineProperties(commandLineProps, parsedFile)
  366. // evaluate config values containing environment variables
  367. evalConfigValues(parsedFile)
  368. // update data path and logging config
  369. DataPath = makeAbsolute(parsedFile.Section("paths").Key("data").String(), HomePath)
  370. initLogging(parsedFile)
  371. return parsedFile, err
  372. }
  373. func pathExists(path string) bool {
  374. _, err := os.Stat(path)
  375. if err == nil {
  376. return true
  377. }
  378. if os.IsNotExist(err) {
  379. return false
  380. }
  381. return false
  382. }
  383. func setHomePath(args *CommandLineArgs) {
  384. if args.HomePath != "" {
  385. HomePath = args.HomePath
  386. return
  387. }
  388. HomePath, _ = filepath.Abs(".")
  389. // check if homepath is correct
  390. if pathExists(filepath.Join(HomePath, "conf/defaults.ini")) {
  391. return
  392. }
  393. // try down one path
  394. if pathExists(filepath.Join(HomePath, "../conf/defaults.ini")) {
  395. HomePath = filepath.Join(HomePath, "../")
  396. }
  397. }
  398. var skipStaticRootValidation = false
  399. func validateStaticRootPath() error {
  400. if skipStaticRootValidation {
  401. return nil
  402. }
  403. if _, err := os.Stat(path.Join(StaticRootPath, "build")); err != nil {
  404. logger.Error("Failed to detect generated javascript files in public/build")
  405. }
  406. return nil
  407. }
  408. func NewCfg() *Cfg {
  409. return &Cfg{}
  410. }
  411. func (cfg *Cfg) Load(args *CommandLineArgs) error {
  412. setHomePath(args)
  413. iniFile, err := loadConfiguration(args)
  414. if err != nil {
  415. return err
  416. }
  417. cfg.Raw = iniFile
  418. // Temporary keep global, to make refactor in steps
  419. Raw = cfg.Raw
  420. ApplicationName = "Grafana"
  421. if Enterprise {
  422. ApplicationName += " Enterprise"
  423. }
  424. Env = iniFile.Section("").Key("app_mode").MustString("development")
  425. InstanceName = iniFile.Section("").Key("instance_name").MustString("unknown_instance_name")
  426. PluginsPath = makeAbsolute(iniFile.Section("paths").Key("plugins").String(), HomePath)
  427. cfg.ProvisioningPath = makeAbsolute(iniFile.Section("paths").Key("provisioning").String(), HomePath)
  428. server := iniFile.Section("server")
  429. AppUrl, AppSubUrl = parseAppUrlAndSubUrl(server)
  430. Protocol = HTTP
  431. if server.Key("protocol").MustString("http") == "https" {
  432. Protocol = HTTPS
  433. CertFile = server.Key("cert_file").String()
  434. KeyFile = server.Key("cert_key").String()
  435. }
  436. if server.Key("protocol").MustString("http") == "socket" {
  437. Protocol = SOCKET
  438. SocketPath = server.Key("socket").String()
  439. }
  440. Domain = server.Key("domain").MustString("localhost")
  441. HttpAddr = server.Key("http_addr").MustString(DEFAULT_HTTP_ADDR)
  442. HttpPort = server.Key("http_port").MustString("3000")
  443. RouterLogging = server.Key("router_logging").MustBool(false)
  444. EnableGzip = server.Key("enable_gzip").MustBool(false)
  445. EnforceDomain = server.Key("enforce_domain").MustBool(false)
  446. StaticRootPath = makeAbsolute(server.Key("static_root_path").String(), HomePath)
  447. if err := validateStaticRootPath(); err != nil {
  448. return err
  449. }
  450. // read data proxy settings
  451. dataproxy := iniFile.Section("dataproxy")
  452. DataProxyLogging = dataproxy.Key("logging").MustBool(false)
  453. // read security settings
  454. security := iniFile.Section("security")
  455. SecretKey = security.Key("secret_key").String()
  456. LogInRememberDays = security.Key("login_remember_days").MustInt()
  457. CookieUserName = security.Key("cookie_username").String()
  458. CookieRememberName = security.Key("cookie_remember_name").String()
  459. DisableGravatar = security.Key("disable_gravatar").MustBool(true)
  460. cfg.DisableBruteForceLoginProtection = security.Key("disable_brute_force_login_protection").MustBool(false)
  461. DisableBruteForceLoginProtection = cfg.DisableBruteForceLoginProtection
  462. // read snapshots settings
  463. snapshots := iniFile.Section("snapshots")
  464. ExternalSnapshotUrl = snapshots.Key("external_snapshot_url").String()
  465. ExternalSnapshotName = snapshots.Key("external_snapshot_name").String()
  466. ExternalEnabled = snapshots.Key("external_enabled").MustBool(true)
  467. SnapShotRemoveExpired = snapshots.Key("snapshot_remove_expired").MustBool(true)
  468. // read dashboard settings
  469. dashboards := iniFile.Section("dashboards")
  470. DashboardVersionsToKeep = dashboards.Key("versions_to_keep").MustInt(20)
  471. // read data source proxy white list
  472. DataProxyWhiteList = make(map[string]bool)
  473. for _, hostAndIp := range util.SplitString(security.Key("data_source_proxy_whitelist").String()) {
  474. DataProxyWhiteList[hostAndIp] = true
  475. }
  476. // admin
  477. AdminUser = security.Key("admin_user").String()
  478. AdminPassword = security.Key("admin_password").String()
  479. users := iniFile.Section("users")
  480. AllowUserSignUp = users.Key("allow_sign_up").MustBool(true)
  481. AllowUserOrgCreate = users.Key("allow_org_create").MustBool(true)
  482. AutoAssignOrg = users.Key("auto_assign_org").MustBool(true)
  483. AutoAssignOrgRole = users.Key("auto_assign_org_role").In("Editor", []string{"Editor", "Admin", "Viewer"})
  484. VerifyEmailEnabled = users.Key("verify_email_enabled").MustBool(false)
  485. LoginHint = users.Key("login_hint").String()
  486. DefaultTheme = users.Key("default_theme").String()
  487. ExternalUserMngLinkUrl = users.Key("external_manage_link_url").String()
  488. ExternalUserMngLinkName = users.Key("external_manage_link_name").String()
  489. ExternalUserMngInfo = users.Key("external_manage_info").String()
  490. ViewersCanEdit = users.Key("viewers_can_edit").MustBool(false)
  491. // auth
  492. auth := iniFile.Section("auth")
  493. DisableLoginForm = auth.Key("disable_login_form").MustBool(false)
  494. DisableSignoutMenu = auth.Key("disable_signout_menu").MustBool(false)
  495. // anonymous access
  496. AnonymousEnabled = iniFile.Section("auth.anonymous").Key("enabled").MustBool(false)
  497. AnonymousOrgName = iniFile.Section("auth.anonymous").Key("org_name").String()
  498. AnonymousOrgRole = iniFile.Section("auth.anonymous").Key("org_role").String()
  499. // auth proxy
  500. authProxy := iniFile.Section("auth.proxy")
  501. AuthProxyEnabled = authProxy.Key("enabled").MustBool(false)
  502. AuthProxyHeaderName = authProxy.Key("header_name").String()
  503. AuthProxyHeaderProperty = authProxy.Key("header_property").String()
  504. AuthProxyAutoSignUp = authProxy.Key("auto_sign_up").MustBool(true)
  505. AuthProxyLdapSyncTtl = authProxy.Key("ldap_sync_ttl").MustInt()
  506. AuthProxyWhitelist = authProxy.Key("whitelist").String()
  507. // basic auth
  508. authBasic := iniFile.Section("auth.basic")
  509. BasicAuthEnabled = authBasic.Key("enabled").MustBool(true)
  510. // global plugin settings
  511. PluginAppsSkipVerifyTLS = iniFile.Section("plugins").Key("app_tls_skip_verify_insecure").MustBool(false)
  512. // PhantomJS rendering
  513. cfg.ImagesDir = filepath.Join(DataPath, "png")
  514. ImagesDir = cfg.ImagesDir
  515. PhantomDir = filepath.Join(HomePath, "tools/phantomjs")
  516. analytics := iniFile.Section("analytics")
  517. ReportingEnabled = analytics.Key("reporting_enabled").MustBool(true)
  518. CheckForUpdates = analytics.Key("check_for_updates").MustBool(true)
  519. GoogleAnalyticsId = analytics.Key("google_analytics_ua_id").String()
  520. GoogleTagManagerId = analytics.Key("google_tag_manager_id").String()
  521. ldapSec := iniFile.Section("auth.ldap")
  522. LdapEnabled = ldapSec.Key("enabled").MustBool(false)
  523. LdapConfigFile = ldapSec.Key("config_file").String()
  524. LdapAllowSignup = ldapSec.Key("allow_sign_up").MustBool(true)
  525. alerting := iniFile.Section("alerting")
  526. AlertingEnabled = alerting.Key("enabled").MustBool(true)
  527. ExecuteAlerts = alerting.Key("execute_alerts").MustBool(true)
  528. explore := iniFile.Section("explore")
  529. ExploreEnabled = explore.Key("enabled").MustBool(false)
  530. cfg.readSessionConfig()
  531. cfg.readSmtpSettings()
  532. cfg.readQuotaSettings()
  533. if VerifyEmailEnabled && !cfg.Smtp.Enabled {
  534. log.Warn("require_email_validation is enabled but smtp is disabled")
  535. }
  536. // check old key name
  537. GrafanaComUrl = iniFile.Section("grafana_net").Key("url").MustString("")
  538. if GrafanaComUrl == "" {
  539. GrafanaComUrl = iniFile.Section("grafana_com").Key("url").MustString("https://grafana.com")
  540. }
  541. imageUploadingSection := iniFile.Section("external_image_storage")
  542. ImageUploadProvider = imageUploadingSection.Key("provider").MustString("")
  543. return nil
  544. }
  545. func (cfg *Cfg) readSessionConfig() {
  546. sec := cfg.Raw.Section("session")
  547. SessionOptions = session.Options{}
  548. SessionOptions.Provider = sec.Key("provider").In("memory", []string{"memory", "file", "redis", "mysql", "postgres", "memcache"})
  549. SessionOptions.ProviderConfig = strings.Trim(sec.Key("provider_config").String(), "\" ")
  550. SessionOptions.CookieName = sec.Key("cookie_name").MustString("grafana_sess")
  551. SessionOptions.CookiePath = AppSubUrl
  552. SessionOptions.Secure = sec.Key("cookie_secure").MustBool()
  553. SessionOptions.Gclifetime = cfg.Raw.Section("session").Key("gc_interval_time").MustInt64(86400)
  554. SessionOptions.Maxlifetime = cfg.Raw.Section("session").Key("session_life_time").MustInt64(86400)
  555. SessionOptions.IDLength = 16
  556. if SessionOptions.Provider == "file" {
  557. SessionOptions.ProviderConfig = makeAbsolute(SessionOptions.ProviderConfig, DataPath)
  558. os.MkdirAll(path.Dir(SessionOptions.ProviderConfig), os.ModePerm)
  559. }
  560. if SessionOptions.CookiePath == "" {
  561. SessionOptions.CookiePath = "/"
  562. }
  563. SessionConnMaxLifetime = cfg.Raw.Section("session").Key("conn_max_lifetime").MustInt64(14400)
  564. }
  565. func initLogging(file *ini.File) {
  566. // split on comma
  567. LogModes = strings.Split(file.Section("log").Key("mode").MustString("console"), ",")
  568. // also try space
  569. if len(LogModes) == 1 {
  570. LogModes = strings.Split(file.Section("log").Key("mode").MustString("console"), " ")
  571. }
  572. LogsPath = makeAbsolute(file.Section("paths").Key("logs").String(), HomePath)
  573. log.ReadLoggingConfig(LogModes, LogsPath, file)
  574. }
  575. func (cfg *Cfg) LogConfigSources() {
  576. var text bytes.Buffer
  577. for _, file := range configFiles {
  578. logger.Info("Config loaded from", "file", file)
  579. }
  580. if len(appliedCommandLineProperties) > 0 {
  581. for _, prop := range appliedCommandLineProperties {
  582. logger.Info("Config overridden from command line", "arg", prop)
  583. }
  584. }
  585. if len(appliedEnvOverrides) > 0 {
  586. text.WriteString("\tEnvironment variables used:\n")
  587. for _, prop := range appliedEnvOverrides {
  588. logger.Info("Config overridden from Environment variable", "var", prop)
  589. }
  590. }
  591. logger.Info("Path Home", "path", HomePath)
  592. logger.Info("Path Data", "path", DataPath)
  593. logger.Info("Path Logs", "path", LogsPath)
  594. logger.Info("Path Plugins", "path", PluginsPath)
  595. logger.Info("Path Provisioning", "path", cfg.ProvisioningPath)
  596. logger.Info("App mode " + Env)
  597. }