options.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. // Copyright 2019 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package config // import "miniflux.app/config"
  5. import (
  6. "fmt"
  7. "sort"
  8. "strings"
  9. "time"
  10. "miniflux.app/version"
  11. )
  12. const (
  13. defaultHTTPS = false
  14. defaultLogDateTime = false
  15. defaultHSTS = true
  16. defaultHTTPService = true
  17. defaultSchedulerService = true
  18. defaultDebug = false
  19. defaultTiming = false
  20. defaultBaseURL = "http://localhost"
  21. defaultRootURL = "http://localhost"
  22. defaultBasePath = ""
  23. defaultWorkerPoolSize = 5
  24. defaultPollingFrequency = 60
  25. defaultBatchSize = 100
  26. defaultPollingScheduler = "round_robin"
  27. defaultSchedulerEntryFrequencyMinInterval = 5
  28. defaultSchedulerEntryFrequencyMaxInterval = 24 * 60
  29. defaultPollingParsingErrorLimit = 3
  30. defaultRunMigrations = false
  31. defaultDatabaseURL = "user=postgres password=postgres dbname=miniflux2 sslmode=disable"
  32. defaultDatabaseMaxConns = 20
  33. defaultDatabaseMinConns = 1
  34. defaultDatabaseConnectionLifetime = 5
  35. defaultListenAddr = "127.0.0.1:8080"
  36. defaultCertFile = ""
  37. defaultKeyFile = ""
  38. defaultCertDomain = ""
  39. defaultCleanupFrequencyHours = 24
  40. defaultCleanupArchiveReadDays = 60
  41. defaultCleanupArchiveUnreadDays = 180
  42. defaultCleanupArchiveBatchSize = 10000
  43. defaultCleanupRemoveSessionsDays = 30
  44. defaultProxyImages = "http-only"
  45. defaultFetchYouTubeWatchTime = false
  46. defaultCreateAdmin = false
  47. defaultAdminUsername = ""
  48. defaultAdminPassword = ""
  49. defaultOAuth2UserCreation = false
  50. defaultOAuth2ClientID = ""
  51. defaultOAuth2ClientSecret = ""
  52. defaultOAuth2RedirectURL = ""
  53. defaultOAuth2OidcDiscoveryEndpoint = ""
  54. defaultOAuth2Provider = ""
  55. defaultPocketConsumerKey = ""
  56. defaultHTTPClientTimeout = 20
  57. defaultHTTPClientMaxBodySize = 15
  58. defaultHTTPClientProxy = ""
  59. defaultAuthProxyHeader = ""
  60. defaultAuthProxyUserCreation = false
  61. defaultMaintenanceMode = false
  62. defaultMaintenanceMessage = "Miniflux is currently under maintenance"
  63. defaultMetricsCollector = false
  64. defaultMetricsRefreshInterval = 60
  65. defaultMetricsAllowedNetworks = "127.0.0.1/8"
  66. defaultWatchdog = true
  67. defaultInvidiousInstance = "yewtu.be"
  68. )
  69. var defaultHTTPClientUserAgent = "Mozilla/5.0 (compatible; Miniflux/" + version.Version + "; +https://miniflux.app)"
  70. // Option contains a key to value map of a single option. It may be used to output debug strings.
  71. type Option struct {
  72. Key string
  73. Value interface{}
  74. }
  75. // Options contains configuration options.
  76. type Options struct {
  77. HTTPS bool
  78. logDateTime bool
  79. hsts bool
  80. httpService bool
  81. schedulerService bool
  82. debug bool
  83. serverTimingHeader bool
  84. baseURL string
  85. rootURL string
  86. basePath string
  87. databaseURL string
  88. databaseMaxConns int
  89. databaseMinConns int
  90. databaseConnectionLifetime int
  91. runMigrations bool
  92. listenAddr string
  93. certFile string
  94. certDomain string
  95. certKeyFile string
  96. cleanupFrequencyHours int
  97. cleanupArchiveReadDays int
  98. cleanupArchiveUnreadDays int
  99. cleanupArchiveBatchSize int
  100. cleanupRemoveSessionsDays int
  101. pollingFrequency int
  102. batchSize int
  103. pollingScheduler string
  104. schedulerEntryFrequencyMinInterval int
  105. schedulerEntryFrequencyMaxInterval int
  106. pollingParsingErrorLimit int
  107. workerPoolSize int
  108. createAdmin bool
  109. adminUsername string
  110. adminPassword string
  111. proxyImages string
  112. fetchYouTubeWatchTime bool
  113. oauth2UserCreationAllowed bool
  114. oauth2ClientID string
  115. oauth2ClientSecret string
  116. oauth2RedirectURL string
  117. oauth2OidcDiscoveryEndpoint string
  118. oauth2Provider string
  119. pocketConsumerKey string
  120. httpClientTimeout int
  121. httpClientMaxBodySize int64
  122. httpClientProxy string
  123. httpClientUserAgent string
  124. authProxyHeader string
  125. authProxyUserCreation bool
  126. maintenanceMode bool
  127. maintenanceMessage string
  128. metricsCollector bool
  129. metricsRefreshInterval int
  130. metricsAllowedNetworks []string
  131. watchdog bool
  132. invidiousInstance string
  133. }
  134. // NewOptions returns Options with default values.
  135. func NewOptions() *Options {
  136. return &Options{
  137. HTTPS: defaultHTTPS,
  138. logDateTime: defaultLogDateTime,
  139. hsts: defaultHSTS,
  140. httpService: defaultHTTPService,
  141. schedulerService: defaultSchedulerService,
  142. debug: defaultDebug,
  143. serverTimingHeader: defaultTiming,
  144. baseURL: defaultBaseURL,
  145. rootURL: defaultRootURL,
  146. basePath: defaultBasePath,
  147. databaseURL: defaultDatabaseURL,
  148. databaseMaxConns: defaultDatabaseMaxConns,
  149. databaseMinConns: defaultDatabaseMinConns,
  150. databaseConnectionLifetime: defaultDatabaseConnectionLifetime,
  151. runMigrations: defaultRunMigrations,
  152. listenAddr: defaultListenAddr,
  153. certFile: defaultCertFile,
  154. certDomain: defaultCertDomain,
  155. certKeyFile: defaultKeyFile,
  156. cleanupFrequencyHours: defaultCleanupFrequencyHours,
  157. cleanupArchiveReadDays: defaultCleanupArchiveReadDays,
  158. cleanupArchiveUnreadDays: defaultCleanupArchiveUnreadDays,
  159. cleanupArchiveBatchSize: defaultCleanupArchiveBatchSize,
  160. cleanupRemoveSessionsDays: defaultCleanupRemoveSessionsDays,
  161. pollingFrequency: defaultPollingFrequency,
  162. batchSize: defaultBatchSize,
  163. pollingScheduler: defaultPollingScheduler,
  164. schedulerEntryFrequencyMinInterval: defaultSchedulerEntryFrequencyMinInterval,
  165. schedulerEntryFrequencyMaxInterval: defaultSchedulerEntryFrequencyMaxInterval,
  166. pollingParsingErrorLimit: defaultPollingParsingErrorLimit,
  167. workerPoolSize: defaultWorkerPoolSize,
  168. createAdmin: defaultCreateAdmin,
  169. proxyImages: defaultProxyImages,
  170. fetchYouTubeWatchTime: defaultFetchYouTubeWatchTime,
  171. oauth2UserCreationAllowed: defaultOAuth2UserCreation,
  172. oauth2ClientID: defaultOAuth2ClientID,
  173. oauth2ClientSecret: defaultOAuth2ClientSecret,
  174. oauth2RedirectURL: defaultOAuth2RedirectURL,
  175. oauth2OidcDiscoveryEndpoint: defaultOAuth2OidcDiscoveryEndpoint,
  176. oauth2Provider: defaultOAuth2Provider,
  177. pocketConsumerKey: defaultPocketConsumerKey,
  178. httpClientTimeout: defaultHTTPClientTimeout,
  179. httpClientMaxBodySize: defaultHTTPClientMaxBodySize * 1024 * 1024,
  180. httpClientProxy: defaultHTTPClientProxy,
  181. httpClientUserAgent: defaultHTTPClientUserAgent,
  182. authProxyHeader: defaultAuthProxyHeader,
  183. authProxyUserCreation: defaultAuthProxyUserCreation,
  184. maintenanceMode: defaultMaintenanceMode,
  185. maintenanceMessage: defaultMaintenanceMessage,
  186. metricsCollector: defaultMetricsCollector,
  187. metricsRefreshInterval: defaultMetricsRefreshInterval,
  188. metricsAllowedNetworks: []string{defaultMetricsAllowedNetworks},
  189. watchdog: defaultWatchdog,
  190. invidiousInstance: defaultInvidiousInstance,
  191. }
  192. }
  193. // LogDateTime returns true if the date/time should be displayed in log messages.
  194. func (o *Options) LogDateTime() bool {
  195. return o.logDateTime
  196. }
  197. // HasMaintenanceMode returns true if maintenance mode is enabled.
  198. func (o *Options) HasMaintenanceMode() bool {
  199. return o.maintenanceMode
  200. }
  201. // MaintenanceMessage returns maintenance message.
  202. func (o *Options) MaintenanceMessage() string {
  203. return o.maintenanceMessage
  204. }
  205. // HasDebugMode returns true if debug mode is enabled.
  206. func (o *Options) HasDebugMode() bool {
  207. return o.debug
  208. }
  209. // HasServerTimingHeader returns true if server-timing headers enabled.
  210. func (o *Options) HasServerTimingHeader() bool {
  211. return o.serverTimingHeader
  212. }
  213. // BaseURL returns the application base URL with path.
  214. func (o *Options) BaseURL() string {
  215. return o.baseURL
  216. }
  217. // RootURL returns the base URL without path.
  218. func (o *Options) RootURL() string {
  219. return o.rootURL
  220. }
  221. // BasePath returns the application base path according to the base URL.
  222. func (o *Options) BasePath() string {
  223. return o.basePath
  224. }
  225. // IsDefaultDatabaseURL returns true if the default database URL is used.
  226. func (o *Options) IsDefaultDatabaseURL() bool {
  227. return o.databaseURL == defaultDatabaseURL
  228. }
  229. // DatabaseURL returns the database URL.
  230. func (o *Options) DatabaseURL() string {
  231. return o.databaseURL
  232. }
  233. // DatabaseMaxConns returns the maximum number of database connections.
  234. func (o *Options) DatabaseMaxConns() int {
  235. return o.databaseMaxConns
  236. }
  237. // DatabaseMinConns returns the minimum number of database connections.
  238. func (o *Options) DatabaseMinConns() int {
  239. return o.databaseMinConns
  240. }
  241. // DatabaseConnectionLifetime returns the maximum amount of time a connection may be reused.
  242. func (o *Options) DatabaseConnectionLifetime() time.Duration {
  243. return time.Duration(o.databaseConnectionLifetime) * time.Minute
  244. }
  245. // ListenAddr returns the listen address for the HTTP server.
  246. func (o *Options) ListenAddr() string {
  247. return o.listenAddr
  248. }
  249. // CertFile returns the SSL certificate filename if any.
  250. func (o *Options) CertFile() string {
  251. return o.certFile
  252. }
  253. // CertKeyFile returns the private key filename for custom SSL certificate.
  254. func (o *Options) CertKeyFile() string {
  255. return o.certKeyFile
  256. }
  257. // CertDomain returns the domain to use for Let's Encrypt certificate.
  258. func (o *Options) CertDomain() string {
  259. return o.certDomain
  260. }
  261. // CleanupFrequencyHours returns the interval in hours for cleanup jobs.
  262. func (o *Options) CleanupFrequencyHours() int {
  263. return o.cleanupFrequencyHours
  264. }
  265. // CleanupArchiveReadDays returns the number of days after which marking read items as removed.
  266. func (o *Options) CleanupArchiveReadDays() int {
  267. return o.cleanupArchiveReadDays
  268. }
  269. // CleanupArchiveUnreadDays returns the number of days after which marking unread items as removed.
  270. func (o *Options) CleanupArchiveUnreadDays() int {
  271. return o.cleanupArchiveUnreadDays
  272. }
  273. // CleanupArchiveBatchSize returns the number of entries to archive for each interval.
  274. func (o *Options) CleanupArchiveBatchSize() int {
  275. return o.cleanupArchiveBatchSize
  276. }
  277. // CleanupRemoveSessionsDays returns the number of days after which to remove sessions.
  278. func (o *Options) CleanupRemoveSessionsDays() int {
  279. return o.cleanupRemoveSessionsDays
  280. }
  281. // WorkerPoolSize returns the number of background worker.
  282. func (o *Options) WorkerPoolSize() int {
  283. return o.workerPoolSize
  284. }
  285. // PollingFrequency returns the interval to refresh feeds in the background.
  286. func (o *Options) PollingFrequency() int {
  287. return o.pollingFrequency
  288. }
  289. // BatchSize returns the number of feeds to send for background processing.
  290. func (o *Options) BatchSize() int {
  291. return o.batchSize
  292. }
  293. // PollingScheduler returns the scheduler used for polling feeds.
  294. func (o *Options) PollingScheduler() string {
  295. return o.pollingScheduler
  296. }
  297. // SchedulerEntryFrequencyMaxInterval returns the maximum interval in minutes for the entry frequency scheduler.
  298. func (o *Options) SchedulerEntryFrequencyMaxInterval() int {
  299. return o.schedulerEntryFrequencyMaxInterval
  300. }
  301. // SchedulerEntryFrequencyMinInterval returns the minimum interval in minutes for the entry frequency scheduler.
  302. func (o *Options) SchedulerEntryFrequencyMinInterval() int {
  303. return o.schedulerEntryFrequencyMinInterval
  304. }
  305. // PollingParsingErrorLimit returns the limit of errors when to stop polling.
  306. func (o *Options) PollingParsingErrorLimit() int {
  307. return o.pollingParsingErrorLimit
  308. }
  309. // IsOAuth2UserCreationAllowed returns true if user creation is allowed for OAuth2 users.
  310. func (o *Options) IsOAuth2UserCreationAllowed() bool {
  311. return o.oauth2UserCreationAllowed
  312. }
  313. // OAuth2ClientID returns the OAuth2 Client ID.
  314. func (o *Options) OAuth2ClientID() string {
  315. return o.oauth2ClientID
  316. }
  317. // OAuth2ClientSecret returns the OAuth2 client secret.
  318. func (o *Options) OAuth2ClientSecret() string {
  319. return o.oauth2ClientSecret
  320. }
  321. // OAuth2RedirectURL returns the OAuth2 redirect URL.
  322. func (o *Options) OAuth2RedirectURL() string {
  323. return o.oauth2RedirectURL
  324. }
  325. // OAuth2OidcDiscoveryEndpoint returns the OAuth2 OIDC discovery endpoint.
  326. func (o *Options) OAuth2OidcDiscoveryEndpoint() string {
  327. return o.oauth2OidcDiscoveryEndpoint
  328. }
  329. // OAuth2Provider returns the name of the OAuth2 provider configured.
  330. func (o *Options) OAuth2Provider() string {
  331. return o.oauth2Provider
  332. }
  333. // HasHSTS returns true if HTTP Strict Transport Security is enabled.
  334. func (o *Options) HasHSTS() bool {
  335. return o.hsts
  336. }
  337. // RunMigrations returns true if the environment variable RUN_MIGRATIONS is not empty.
  338. func (o *Options) RunMigrations() bool {
  339. return o.runMigrations
  340. }
  341. // CreateAdmin returns true if the environment variable CREATE_ADMIN is not empty.
  342. func (o *Options) CreateAdmin() bool {
  343. return o.createAdmin
  344. }
  345. // AdminUsername returns the admin username if defined.
  346. func (o *Options) AdminUsername() string {
  347. return o.adminUsername
  348. }
  349. // AdminPassword returns the admin password if defined.
  350. func (o *Options) AdminPassword() string {
  351. return o.adminPassword
  352. }
  353. // FetchYouTubeWatchTime returns true if the YouTube video duration
  354. // should be fetched and used as a reading time.
  355. func (o *Options) FetchYouTubeWatchTime() bool {
  356. return o.fetchYouTubeWatchTime
  357. }
  358. // ProxyImages returns "none" to never proxy, "http-only" to proxy non-HTTPS, "all" to always proxy.
  359. func (o *Options) ProxyImages() string {
  360. return o.proxyImages
  361. }
  362. // HasHTTPService returns true if the HTTP service is enabled.
  363. func (o *Options) HasHTTPService() bool {
  364. return o.httpService
  365. }
  366. // HasSchedulerService returns true if the scheduler service is enabled.
  367. func (o *Options) HasSchedulerService() bool {
  368. return o.schedulerService
  369. }
  370. // PocketConsumerKey returns the Pocket Consumer Key if configured.
  371. func (o *Options) PocketConsumerKey(defaultValue string) string {
  372. if o.pocketConsumerKey != "" {
  373. return o.pocketConsumerKey
  374. }
  375. return defaultValue
  376. }
  377. // HTTPClientTimeout returns the time limit in seconds before the HTTP client cancel the request.
  378. func (o *Options) HTTPClientTimeout() int {
  379. return o.httpClientTimeout
  380. }
  381. // HTTPClientMaxBodySize returns the number of bytes allowed for the HTTP client to transfer.
  382. func (o *Options) HTTPClientMaxBodySize() int64 {
  383. return o.httpClientMaxBodySize
  384. }
  385. // HTTPClientProxy returns the proxy URL for HTTP client.
  386. func (o *Options) HTTPClientProxy() string {
  387. return o.httpClientProxy
  388. }
  389. // HasHTTPClientProxyConfigured returns true if the HTTP proxy is configured.
  390. func (o *Options) HasHTTPClientProxyConfigured() bool {
  391. return o.httpClientProxy != ""
  392. }
  393. // AuthProxyHeader returns an HTTP header name that contains username for
  394. // authentication using auth proxy.
  395. func (o *Options) AuthProxyHeader() string {
  396. return o.authProxyHeader
  397. }
  398. // IsAuthProxyUserCreationAllowed returns true if user creation is allowed for
  399. // users authenticated using auth proxy.
  400. func (o *Options) IsAuthProxyUserCreationAllowed() bool {
  401. return o.authProxyUserCreation
  402. }
  403. // HasMetricsCollector returns true if metrics collection is enabled.
  404. func (o *Options) HasMetricsCollector() bool {
  405. return o.metricsCollector
  406. }
  407. // MetricsRefreshInterval returns the refresh interval in seconds.
  408. func (o *Options) MetricsRefreshInterval() int {
  409. return o.metricsRefreshInterval
  410. }
  411. // MetricsAllowedNetworks returns the list of networks allowed to connect to the metrics endpoint.
  412. func (o *Options) MetricsAllowedNetworks() []string {
  413. return o.metricsAllowedNetworks
  414. }
  415. // HTTPClientUserAgent returns the global User-Agent header for miniflux.
  416. func (o *Options) HTTPClientUserAgent() string {
  417. return o.httpClientUserAgent
  418. }
  419. // HasWatchdog returns true if the systemd watchdog is enabled.
  420. func (o *Options) HasWatchdog() bool {
  421. return o.watchdog
  422. }
  423. // InvidiousInstance returns the invidious instance used by miniflux
  424. func (o *Options) InvidiousInstance() string {
  425. return o.invidiousInstance
  426. }
  427. // SortedOptions returns options as a list of key value pairs, sorted by keys.
  428. func (o *Options) SortedOptions(redactSecret bool) []*Option {
  429. var keyValues = map[string]interface{}{
  430. "ADMIN_PASSWORD": redactSecretValue(o.adminPassword, redactSecret),
  431. "ADMIN_USERNAME": o.adminUsername,
  432. "AUTH_PROXY_HEADER": o.authProxyHeader,
  433. "AUTH_PROXY_USER_CREATION": o.authProxyUserCreation,
  434. "BASE_PATH": o.basePath,
  435. "BASE_URL": o.baseURL,
  436. "BATCH_SIZE": o.batchSize,
  437. "CERT_DOMAIN": o.certDomain,
  438. "CERT_FILE": o.certFile,
  439. "CLEANUP_ARCHIVE_READ_DAYS": o.cleanupArchiveReadDays,
  440. "CLEANUP_ARCHIVE_UNREAD_DAYS": o.cleanupArchiveUnreadDays,
  441. "CLEANUP_ARCHIVE_BATCH_SIZE": o.cleanupArchiveBatchSize,
  442. "CLEANUP_FREQUENCY_HOURS": o.cleanupFrequencyHours,
  443. "CLEANUP_REMOVE_SESSIONS_DAYS": o.cleanupRemoveSessionsDays,
  444. "CREATE_ADMIN": o.createAdmin,
  445. "DATABASE_MAX_CONNS": o.databaseMaxConns,
  446. "DATABASE_MIN_CONNS": o.databaseMinConns,
  447. "DATABASE_CONNECTION_LIFETIME": o.databaseConnectionLifetime,
  448. "DATABASE_URL": redactSecretValue(o.databaseURL, redactSecret),
  449. "DEBUG": o.debug,
  450. "DISABLE_HSTS": !o.hsts,
  451. "DISABLE_SCHEDULER_SERVICE": !o.schedulerService,
  452. "DISABLE_HTTP_SERVICE": !o.httpService,
  453. "FETCH_YOUTUBE_WATCH_TIME": o.fetchYouTubeWatchTime,
  454. "HTTPS": o.HTTPS,
  455. "HTTP_CLIENT_MAX_BODY_SIZE": o.httpClientMaxBodySize,
  456. "HTTP_CLIENT_PROXY": o.httpClientProxy,
  457. "HTTP_CLIENT_TIMEOUT": o.httpClientTimeout,
  458. "HTTP_CLIENT_USER_AGENT": o.httpClientUserAgent,
  459. "HTTP_SERVICE": o.httpService,
  460. "KEY_FILE": o.certKeyFile,
  461. "INVIDIOUS_INSTANCE": o.invidiousInstance,
  462. "LISTEN_ADDR": o.listenAddr,
  463. "LOG_DATE_TIME": o.logDateTime,
  464. "MAINTENANCE_MESSAGE": o.maintenanceMessage,
  465. "MAINTENANCE_MODE": o.maintenanceMode,
  466. "METRICS_ALLOWED_NETWORKS": strings.Join(o.metricsAllowedNetworks, ","),
  467. "METRICS_COLLECTOR": o.metricsCollector,
  468. "METRICS_REFRESH_INTERVAL": o.metricsRefreshInterval,
  469. "OAUTH2_CLIENT_ID": o.oauth2ClientID,
  470. "OAUTH2_CLIENT_SECRET": redactSecretValue(o.oauth2ClientSecret, redactSecret),
  471. "OAUTH2_OIDC_DISCOVERY_ENDPOINT": o.oauth2OidcDiscoveryEndpoint,
  472. "OAUTH2_PROVIDER": o.oauth2Provider,
  473. "OAUTH2_REDIRECT_URL": o.oauth2RedirectURL,
  474. "OAUTH2_USER_CREATION": o.oauth2UserCreationAllowed,
  475. "POCKET_CONSUMER_KEY": redactSecretValue(o.pocketConsumerKey, redactSecret),
  476. "POLLING_FREQUENCY": o.pollingFrequency,
  477. "POLLING_PARSING_ERROR_LIMIT": o.pollingParsingErrorLimit,
  478. "POLLING_SCHEDULER": o.pollingScheduler,
  479. "PROXY_IMAGES": o.proxyImages,
  480. "ROOT_URL": o.rootURL,
  481. "RUN_MIGRATIONS": o.runMigrations,
  482. "SCHEDULER_ENTRY_FREQUENCY_MAX_INTERVAL": o.schedulerEntryFrequencyMaxInterval,
  483. "SCHEDULER_ENTRY_FREQUENCY_MIN_INTERVAL": o.schedulerEntryFrequencyMinInterval,
  484. "SCHEDULER_SERVICE": o.schedulerService,
  485. "SERVER_TIMING_HEADER": o.serverTimingHeader,
  486. "WORKER_POOL_SIZE": o.workerPoolSize,
  487. "WATCHDOG": o.watchdog,
  488. }
  489. keys := make([]string, 0, len(keyValues))
  490. for key := range keyValues {
  491. keys = append(keys, key)
  492. }
  493. sort.Strings(keys)
  494. var sortedOptions []*Option
  495. for _, key := range keys {
  496. sortedOptions = append(sortedOptions, &Option{Key: key, Value: keyValues[key]})
  497. }
  498. return sortedOptions
  499. }
  500. func (o *Options) String() string {
  501. var builder strings.Builder
  502. for _, option := range o.SortedOptions(false) {
  503. fmt.Fprintf(&builder, "%s=%v\n", option.Key, option.Value)
  504. }
  505. return builder.String()
  506. }
  507. func redactSecretValue(value string, redactSecret bool) string {
  508. if redactSecret && value != "" {
  509. return "******"
  510. }
  511. return value
  512. }