options.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package config // import "miniflux.app/v2/internal/config"
  4. import (
  5. "fmt"
  6. "sort"
  7. "strings"
  8. "time"
  9. "miniflux.app/v2/internal/crypto"
  10. "miniflux.app/v2/internal/version"
  11. )
  12. const (
  13. defaultHTTPS = false
  14. defaultLogFile = "stderr"
  15. defaultLogDateTime = false
  16. defaultLogFormat = "text"
  17. defaultLogLevel = "info"
  18. defaultHSTS = true
  19. defaultHTTPService = true
  20. defaultSchedulerService = true
  21. defaultDebug = false
  22. defaultTiming = false
  23. defaultBaseURL = "http://localhost"
  24. defaultRootURL = "http://localhost"
  25. defaultBasePath = ""
  26. defaultWorkerPoolSize = 16
  27. defaultPollingFrequency = 60
  28. defaultForceRefreshInterval = 30
  29. defaultBatchSize = 100
  30. defaultPollingScheduler = "round_robin"
  31. defaultSchedulerEntryFrequencyMinInterval = 5
  32. defaultSchedulerEntryFrequencyMaxInterval = 24 * 60
  33. defaultSchedulerEntryFrequencyFactor = 1
  34. defaultSchedulerRoundRobinMinInterval = 60
  35. defaultPollingParsingErrorLimit = 3
  36. defaultRunMigrations = false
  37. defaultDatabaseURL = "user=postgres password=postgres dbname=miniflux2 sslmode=disable"
  38. defaultDatabaseMaxConns = 20
  39. defaultDatabaseMinConns = 1
  40. defaultDatabaseConnectionLifetime = 5
  41. defaultListenAddr = "127.0.0.1:8080"
  42. defaultCertFile = ""
  43. defaultKeyFile = ""
  44. defaultCertDomain = ""
  45. defaultCleanupFrequencyHours = 24
  46. defaultCleanupArchiveReadDays = 60
  47. defaultCleanupArchiveUnreadDays = 180
  48. defaultCleanupArchiveBatchSize = 10000
  49. defaultCleanupRemoveSessionsDays = 30
  50. defaultProxyHTTPClientTimeout = 120
  51. defaultProxyOption = "http-only"
  52. defaultProxyMediaTypes = "image"
  53. defaultProxyUrl = ""
  54. defaultFetchOdyseeWatchTime = false
  55. defaultFetchYouTubeWatchTime = false
  56. defaultYouTubeEmbedUrlOverride = "https://www.youtube-nocookie.com/embed/"
  57. defaultCreateAdmin = false
  58. defaultAdminUsername = ""
  59. defaultAdminPassword = ""
  60. defaultOAuth2UserCreation = false
  61. defaultOAuth2ClientID = ""
  62. defaultOAuth2ClientSecret = ""
  63. defaultOAuth2RedirectURL = ""
  64. defaultOAuth2OidcDiscoveryEndpoint = ""
  65. defaultOAuth2Provider = ""
  66. defaultPocketConsumerKey = ""
  67. defaultHTTPClientTimeout = 20
  68. defaultHTTPClientMaxBodySize = 15
  69. defaultHTTPClientProxy = ""
  70. defaultHTTPServerTimeout = 300
  71. defaultAuthProxyHeader = ""
  72. defaultAuthProxyUserCreation = false
  73. defaultMaintenanceMode = false
  74. defaultMaintenanceMessage = "Miniflux is currently under maintenance"
  75. defaultMetricsCollector = false
  76. defaultMetricsRefreshInterval = 60
  77. defaultMetricsAllowedNetworks = "127.0.0.1/8"
  78. defaultMetricsUsername = ""
  79. defaultMetricsPassword = ""
  80. defaultWatchdog = true
  81. defaultInvidiousInstance = "yewtu.be"
  82. defaultWebAuthn = false
  83. )
  84. var defaultHTTPClientUserAgent = "Mozilla/5.0 (compatible; Miniflux/" + version.Version + "; +https://miniflux.app)"
  85. // Option contains a key to value map of a single option. It may be used to output debug strings.
  86. type Option struct {
  87. Key string
  88. Value interface{}
  89. }
  90. // Options contains configuration options.
  91. type Options struct {
  92. HTTPS bool
  93. logFile string
  94. logDateTime bool
  95. logFormat string
  96. logLevel string
  97. hsts bool
  98. httpService bool
  99. schedulerService bool
  100. serverTimingHeader bool
  101. baseURL string
  102. rootURL string
  103. basePath string
  104. databaseURL string
  105. databaseMaxConns int
  106. databaseMinConns int
  107. databaseConnectionLifetime int
  108. runMigrations bool
  109. listenAddr string
  110. certFile string
  111. certDomain string
  112. certKeyFile string
  113. cleanupFrequencyHours int
  114. cleanupArchiveReadDays int
  115. cleanupArchiveUnreadDays int
  116. cleanupArchiveBatchSize int
  117. cleanupRemoveSessionsDays int
  118. pollingFrequency int
  119. forceRefreshInterval int
  120. batchSize int
  121. pollingScheduler string
  122. schedulerEntryFrequencyMinInterval int
  123. schedulerEntryFrequencyMaxInterval int
  124. schedulerEntryFrequencyFactor int
  125. schedulerRoundRobinMinInterval int
  126. pollingParsingErrorLimit int
  127. workerPoolSize int
  128. createAdmin bool
  129. adminUsername string
  130. adminPassword string
  131. proxyHTTPClientTimeout int
  132. proxyOption string
  133. proxyMediaTypes []string
  134. proxyUrl string
  135. fetchOdyseeWatchTime bool
  136. fetchYouTubeWatchTime bool
  137. youTubeEmbedUrlOverride string
  138. oauth2UserCreationAllowed bool
  139. oauth2ClientID string
  140. oauth2ClientSecret string
  141. oauth2RedirectURL string
  142. oidcDiscoveryEndpoint string
  143. oauth2Provider string
  144. pocketConsumerKey string
  145. httpClientTimeout int
  146. httpClientMaxBodySize int64
  147. httpClientProxy string
  148. httpClientUserAgent string
  149. httpServerTimeout int
  150. authProxyHeader string
  151. authProxyUserCreation bool
  152. maintenanceMode bool
  153. maintenanceMessage string
  154. metricsCollector bool
  155. metricsRefreshInterval int
  156. metricsAllowedNetworks []string
  157. metricsUsername string
  158. metricsPassword string
  159. watchdog bool
  160. invidiousInstance string
  161. proxyPrivateKey []byte
  162. webAuthn bool
  163. }
  164. // NewOptions returns Options with default values.
  165. func NewOptions() *Options {
  166. return &Options{
  167. HTTPS: defaultHTTPS,
  168. logFile: defaultLogFile,
  169. logDateTime: defaultLogDateTime,
  170. logFormat: defaultLogFormat,
  171. logLevel: defaultLogLevel,
  172. hsts: defaultHSTS,
  173. httpService: defaultHTTPService,
  174. schedulerService: defaultSchedulerService,
  175. serverTimingHeader: defaultTiming,
  176. baseURL: defaultBaseURL,
  177. rootURL: defaultRootURL,
  178. basePath: defaultBasePath,
  179. databaseURL: defaultDatabaseURL,
  180. databaseMaxConns: defaultDatabaseMaxConns,
  181. databaseMinConns: defaultDatabaseMinConns,
  182. databaseConnectionLifetime: defaultDatabaseConnectionLifetime,
  183. runMigrations: defaultRunMigrations,
  184. listenAddr: defaultListenAddr,
  185. certFile: defaultCertFile,
  186. certDomain: defaultCertDomain,
  187. certKeyFile: defaultKeyFile,
  188. cleanupFrequencyHours: defaultCleanupFrequencyHours,
  189. cleanupArchiveReadDays: defaultCleanupArchiveReadDays,
  190. cleanupArchiveUnreadDays: defaultCleanupArchiveUnreadDays,
  191. cleanupArchiveBatchSize: defaultCleanupArchiveBatchSize,
  192. cleanupRemoveSessionsDays: defaultCleanupRemoveSessionsDays,
  193. pollingFrequency: defaultPollingFrequency,
  194. forceRefreshInterval: defaultForceRefreshInterval,
  195. batchSize: defaultBatchSize,
  196. pollingScheduler: defaultPollingScheduler,
  197. schedulerEntryFrequencyMinInterval: defaultSchedulerEntryFrequencyMinInterval,
  198. schedulerEntryFrequencyMaxInterval: defaultSchedulerEntryFrequencyMaxInterval,
  199. schedulerEntryFrequencyFactor: defaultSchedulerEntryFrequencyFactor,
  200. schedulerRoundRobinMinInterval: defaultSchedulerRoundRobinMinInterval,
  201. pollingParsingErrorLimit: defaultPollingParsingErrorLimit,
  202. workerPoolSize: defaultWorkerPoolSize,
  203. createAdmin: defaultCreateAdmin,
  204. proxyHTTPClientTimeout: defaultProxyHTTPClientTimeout,
  205. proxyOption: defaultProxyOption,
  206. proxyMediaTypes: []string{defaultProxyMediaTypes},
  207. proxyUrl: defaultProxyUrl,
  208. fetchOdyseeWatchTime: defaultFetchOdyseeWatchTime,
  209. fetchYouTubeWatchTime: defaultFetchYouTubeWatchTime,
  210. youTubeEmbedUrlOverride: defaultYouTubeEmbedUrlOverride,
  211. oauth2UserCreationAllowed: defaultOAuth2UserCreation,
  212. oauth2ClientID: defaultOAuth2ClientID,
  213. oauth2ClientSecret: defaultOAuth2ClientSecret,
  214. oauth2RedirectURL: defaultOAuth2RedirectURL,
  215. oidcDiscoveryEndpoint: defaultOAuth2OidcDiscoveryEndpoint,
  216. oauth2Provider: defaultOAuth2Provider,
  217. pocketConsumerKey: defaultPocketConsumerKey,
  218. httpClientTimeout: defaultHTTPClientTimeout,
  219. httpClientMaxBodySize: defaultHTTPClientMaxBodySize * 1024 * 1024,
  220. httpClientProxy: defaultHTTPClientProxy,
  221. httpClientUserAgent: defaultHTTPClientUserAgent,
  222. httpServerTimeout: defaultHTTPServerTimeout,
  223. authProxyHeader: defaultAuthProxyHeader,
  224. authProxyUserCreation: defaultAuthProxyUserCreation,
  225. maintenanceMode: defaultMaintenanceMode,
  226. maintenanceMessage: defaultMaintenanceMessage,
  227. metricsCollector: defaultMetricsCollector,
  228. metricsRefreshInterval: defaultMetricsRefreshInterval,
  229. metricsAllowedNetworks: []string{defaultMetricsAllowedNetworks},
  230. metricsUsername: defaultMetricsUsername,
  231. metricsPassword: defaultMetricsPassword,
  232. watchdog: defaultWatchdog,
  233. invidiousInstance: defaultInvidiousInstance,
  234. proxyPrivateKey: crypto.GenerateRandomBytes(16),
  235. webAuthn: defaultWebAuthn,
  236. }
  237. }
  238. func (o *Options) LogFile() string {
  239. return o.logFile
  240. }
  241. // LogDateTime returns true if the date/time should be displayed in log messages.
  242. func (o *Options) LogDateTime() bool {
  243. return o.logDateTime
  244. }
  245. // LogFormat returns the log format.
  246. func (o *Options) LogFormat() string {
  247. return o.logFormat
  248. }
  249. // LogLevel returns the log level.
  250. func (o *Options) LogLevel() string {
  251. return o.logLevel
  252. }
  253. // SetLogLevel sets the log level.
  254. func (o *Options) SetLogLevel(level string) {
  255. o.logLevel = level
  256. }
  257. // HasMaintenanceMode returns true if maintenance mode is enabled.
  258. func (o *Options) HasMaintenanceMode() bool {
  259. return o.maintenanceMode
  260. }
  261. // MaintenanceMessage returns maintenance message.
  262. func (o *Options) MaintenanceMessage() string {
  263. return o.maintenanceMessage
  264. }
  265. // HasServerTimingHeader returns true if server-timing headers enabled.
  266. func (o *Options) HasServerTimingHeader() bool {
  267. return o.serverTimingHeader
  268. }
  269. // BaseURL returns the application base URL with path.
  270. func (o *Options) BaseURL() string {
  271. return o.baseURL
  272. }
  273. // RootURL returns the base URL without path.
  274. func (o *Options) RootURL() string {
  275. return o.rootURL
  276. }
  277. // BasePath returns the application base path according to the base URL.
  278. func (o *Options) BasePath() string {
  279. return o.basePath
  280. }
  281. // IsDefaultDatabaseURL returns true if the default database URL is used.
  282. func (o *Options) IsDefaultDatabaseURL() bool {
  283. return o.databaseURL == defaultDatabaseURL
  284. }
  285. // DatabaseURL returns the database URL.
  286. func (o *Options) DatabaseURL() string {
  287. return o.databaseURL
  288. }
  289. // DatabaseMaxConns returns the maximum number of database connections.
  290. func (o *Options) DatabaseMaxConns() int {
  291. return o.databaseMaxConns
  292. }
  293. // DatabaseMinConns returns the minimum number of database connections.
  294. func (o *Options) DatabaseMinConns() int {
  295. return o.databaseMinConns
  296. }
  297. // DatabaseConnectionLifetime returns the maximum amount of time a connection may be reused.
  298. func (o *Options) DatabaseConnectionLifetime() time.Duration {
  299. return time.Duration(o.databaseConnectionLifetime) * time.Minute
  300. }
  301. // ListenAddr returns the listen address for the HTTP server.
  302. func (o *Options) ListenAddr() string {
  303. return o.listenAddr
  304. }
  305. // CertFile returns the SSL certificate filename if any.
  306. func (o *Options) CertFile() string {
  307. return o.certFile
  308. }
  309. // CertKeyFile returns the private key filename for custom SSL certificate.
  310. func (o *Options) CertKeyFile() string {
  311. return o.certKeyFile
  312. }
  313. // CertDomain returns the domain to use for Let's Encrypt certificate.
  314. func (o *Options) CertDomain() string {
  315. return o.certDomain
  316. }
  317. // CleanupFrequencyHours returns the interval in hours for cleanup jobs.
  318. func (o *Options) CleanupFrequencyHours() int {
  319. return o.cleanupFrequencyHours
  320. }
  321. // CleanupArchiveReadDays returns the number of days after which marking read items as removed.
  322. func (o *Options) CleanupArchiveReadDays() int {
  323. return o.cleanupArchiveReadDays
  324. }
  325. // CleanupArchiveUnreadDays returns the number of days after which marking unread items as removed.
  326. func (o *Options) CleanupArchiveUnreadDays() int {
  327. return o.cleanupArchiveUnreadDays
  328. }
  329. // CleanupArchiveBatchSize returns the number of entries to archive for each interval.
  330. func (o *Options) CleanupArchiveBatchSize() int {
  331. return o.cleanupArchiveBatchSize
  332. }
  333. // CleanupRemoveSessionsDays returns the number of days after which to remove sessions.
  334. func (o *Options) CleanupRemoveSessionsDays() int {
  335. return o.cleanupRemoveSessionsDays
  336. }
  337. // WorkerPoolSize returns the number of background worker.
  338. func (o *Options) WorkerPoolSize() int {
  339. return o.workerPoolSize
  340. }
  341. // PollingFrequency returns the interval to refresh feeds in the background.
  342. func (o *Options) PollingFrequency() int {
  343. return o.pollingFrequency
  344. }
  345. // ForceRefreshInterval returns the force refresh interval
  346. func (o *Options) ForceRefreshInterval() int {
  347. return o.forceRefreshInterval
  348. }
  349. // BatchSize returns the number of feeds to send for background processing.
  350. func (o *Options) BatchSize() int {
  351. return o.batchSize
  352. }
  353. // PollingScheduler returns the scheduler used for polling feeds.
  354. func (o *Options) PollingScheduler() string {
  355. return o.pollingScheduler
  356. }
  357. // SchedulerEntryFrequencyMaxInterval returns the maximum interval in minutes for the entry frequency scheduler.
  358. func (o *Options) SchedulerEntryFrequencyMaxInterval() int {
  359. return o.schedulerEntryFrequencyMaxInterval
  360. }
  361. // SchedulerEntryFrequencyMinInterval returns the minimum interval in minutes for the entry frequency scheduler.
  362. func (o *Options) SchedulerEntryFrequencyMinInterval() int {
  363. return o.schedulerEntryFrequencyMinInterval
  364. }
  365. // SchedulerEntryFrequencyFactor returns the factor for the entry frequency scheduler.
  366. func (o *Options) SchedulerEntryFrequencyFactor() int {
  367. return o.schedulerEntryFrequencyFactor
  368. }
  369. func (o *Options) SchedulerRoundRobinMinInterval() int {
  370. return o.schedulerRoundRobinMinInterval
  371. }
  372. // PollingParsingErrorLimit returns the limit of errors when to stop polling.
  373. func (o *Options) PollingParsingErrorLimit() int {
  374. return o.pollingParsingErrorLimit
  375. }
  376. // IsOAuth2UserCreationAllowed returns true if user creation is allowed for OAuth2 users.
  377. func (o *Options) IsOAuth2UserCreationAllowed() bool {
  378. return o.oauth2UserCreationAllowed
  379. }
  380. // OAuth2ClientID returns the OAuth2 Client ID.
  381. func (o *Options) OAuth2ClientID() string {
  382. return o.oauth2ClientID
  383. }
  384. // OAuth2ClientSecret returns the OAuth2 client secret.
  385. func (o *Options) OAuth2ClientSecret() string {
  386. return o.oauth2ClientSecret
  387. }
  388. // OAuth2RedirectURL returns the OAuth2 redirect URL.
  389. func (o *Options) OAuth2RedirectURL() string {
  390. return o.oauth2RedirectURL
  391. }
  392. // OIDCDiscoveryEndpoint returns the OAuth2 OIDC discovery endpoint.
  393. func (o *Options) OIDCDiscoveryEndpoint() string {
  394. return o.oidcDiscoveryEndpoint
  395. }
  396. // OAuth2Provider returns the name of the OAuth2 provider configured.
  397. func (o *Options) OAuth2Provider() string {
  398. return o.oauth2Provider
  399. }
  400. // HasHSTS returns true if HTTP Strict Transport Security is enabled.
  401. func (o *Options) HasHSTS() bool {
  402. return o.hsts
  403. }
  404. // RunMigrations returns true if the environment variable RUN_MIGRATIONS is not empty.
  405. func (o *Options) RunMigrations() bool {
  406. return o.runMigrations
  407. }
  408. // CreateAdmin returns true if the environment variable CREATE_ADMIN is not empty.
  409. func (o *Options) CreateAdmin() bool {
  410. return o.createAdmin
  411. }
  412. // AdminUsername returns the admin username if defined.
  413. func (o *Options) AdminUsername() string {
  414. return o.adminUsername
  415. }
  416. // AdminPassword returns the admin password if defined.
  417. func (o *Options) AdminPassword() string {
  418. return o.adminPassword
  419. }
  420. // FetchYouTubeWatchTime returns true if the YouTube video duration
  421. // should be fetched and used as a reading time.
  422. func (o *Options) FetchYouTubeWatchTime() bool {
  423. return o.fetchYouTubeWatchTime
  424. }
  425. // YouTubeEmbedUrlOverride returns YouTube URL which will be used for embeds
  426. func (o *Options) YouTubeEmbedUrlOverride() string {
  427. return o.youTubeEmbedUrlOverride
  428. }
  429. // FetchOdyseeWatchTime returns true if the Odysee video duration
  430. // should be fetched and used as a reading time.
  431. func (o *Options) FetchOdyseeWatchTime() bool {
  432. return o.fetchOdyseeWatchTime
  433. }
  434. // ProxyOption returns "none" to never proxy, "http-only" to proxy non-HTTPS, "all" to always proxy.
  435. func (o *Options) ProxyOption() string {
  436. return o.proxyOption
  437. }
  438. // ProxyMediaTypes returns a slice of media types to proxy.
  439. func (o *Options) ProxyMediaTypes() []string {
  440. return o.proxyMediaTypes
  441. }
  442. // ProxyUrl returns a string of a URL to use to proxy image requests
  443. func (o *Options) ProxyUrl() string {
  444. return o.proxyUrl
  445. }
  446. // ProxyHTTPClientTimeout returns the time limit in seconds before the proxy HTTP client cancel the request.
  447. func (o *Options) ProxyHTTPClientTimeout() int {
  448. return o.proxyHTTPClientTimeout
  449. }
  450. // HasHTTPService returns true if the HTTP service is enabled.
  451. func (o *Options) HasHTTPService() bool {
  452. return o.httpService
  453. }
  454. // HasSchedulerService returns true if the scheduler service is enabled.
  455. func (o *Options) HasSchedulerService() bool {
  456. return o.schedulerService
  457. }
  458. // PocketConsumerKey returns the Pocket Consumer Key if configured.
  459. func (o *Options) PocketConsumerKey(defaultValue string) string {
  460. if o.pocketConsumerKey != "" {
  461. return o.pocketConsumerKey
  462. }
  463. return defaultValue
  464. }
  465. // HTTPClientTimeout returns the time limit in seconds before the HTTP client cancel the request.
  466. func (o *Options) HTTPClientTimeout() int {
  467. return o.httpClientTimeout
  468. }
  469. // HTTPClientMaxBodySize returns the number of bytes allowed for the HTTP client to transfer.
  470. func (o *Options) HTTPClientMaxBodySize() int64 {
  471. return o.httpClientMaxBodySize
  472. }
  473. // HTTPClientProxy returns the proxy URL for HTTP client.
  474. func (o *Options) HTTPClientProxy() string {
  475. return o.httpClientProxy
  476. }
  477. // HTTPServerTimeout returns the time limit in seconds before the HTTP server cancel the request.
  478. func (o *Options) HTTPServerTimeout() int {
  479. return o.httpServerTimeout
  480. }
  481. // HasHTTPClientProxyConfigured returns true if the HTTP proxy is configured.
  482. func (o *Options) HasHTTPClientProxyConfigured() bool {
  483. return o.httpClientProxy != ""
  484. }
  485. // AuthProxyHeader returns an HTTP header name that contains username for
  486. // authentication using auth proxy.
  487. func (o *Options) AuthProxyHeader() string {
  488. return o.authProxyHeader
  489. }
  490. // IsAuthProxyUserCreationAllowed returns true if user creation is allowed for
  491. // users authenticated using auth proxy.
  492. func (o *Options) IsAuthProxyUserCreationAllowed() bool {
  493. return o.authProxyUserCreation
  494. }
  495. // HasMetricsCollector returns true if metrics collection is enabled.
  496. func (o *Options) HasMetricsCollector() bool {
  497. return o.metricsCollector
  498. }
  499. // MetricsRefreshInterval returns the refresh interval in seconds.
  500. func (o *Options) MetricsRefreshInterval() int {
  501. return o.metricsRefreshInterval
  502. }
  503. // MetricsAllowedNetworks returns the list of networks allowed to connect to the metrics endpoint.
  504. func (o *Options) MetricsAllowedNetworks() []string {
  505. return o.metricsAllowedNetworks
  506. }
  507. func (o *Options) MetricsUsername() string {
  508. return o.metricsUsername
  509. }
  510. func (o *Options) MetricsPassword() string {
  511. return o.metricsPassword
  512. }
  513. // HTTPClientUserAgent returns the global User-Agent header for miniflux.
  514. func (o *Options) HTTPClientUserAgent() string {
  515. return o.httpClientUserAgent
  516. }
  517. // HasWatchdog returns true if the systemd watchdog is enabled.
  518. func (o *Options) HasWatchdog() bool {
  519. return o.watchdog
  520. }
  521. // InvidiousInstance returns the invidious instance used by miniflux
  522. func (o *Options) InvidiousInstance() string {
  523. return o.invidiousInstance
  524. }
  525. // ProxyPrivateKey returns the private key used by the media proxy
  526. func (o *Options) ProxyPrivateKey() []byte {
  527. return o.proxyPrivateKey
  528. }
  529. // WebAuthn returns true if WebAuthn logins are supported
  530. func (o *Options) WebAuthn() bool {
  531. return o.webAuthn
  532. }
  533. // SortedOptions returns options as a list of key value pairs, sorted by keys.
  534. func (o *Options) SortedOptions(redactSecret bool) []*Option {
  535. var keyValues = map[string]interface{}{
  536. "ADMIN_PASSWORD": redactSecretValue(o.adminPassword, redactSecret),
  537. "ADMIN_USERNAME": o.adminUsername,
  538. "AUTH_PROXY_HEADER": o.authProxyHeader,
  539. "AUTH_PROXY_USER_CREATION": o.authProxyUserCreation,
  540. "BASE_PATH": o.basePath,
  541. "BASE_URL": o.baseURL,
  542. "BATCH_SIZE": o.batchSize,
  543. "CERT_DOMAIN": o.certDomain,
  544. "CERT_FILE": o.certFile,
  545. "CLEANUP_ARCHIVE_BATCH_SIZE": o.cleanupArchiveBatchSize,
  546. "CLEANUP_ARCHIVE_READ_DAYS": o.cleanupArchiveReadDays,
  547. "CLEANUP_ARCHIVE_UNREAD_DAYS": o.cleanupArchiveUnreadDays,
  548. "CLEANUP_FREQUENCY_HOURS": o.cleanupFrequencyHours,
  549. "CLEANUP_REMOVE_SESSIONS_DAYS": o.cleanupRemoveSessionsDays,
  550. "CREATE_ADMIN": o.createAdmin,
  551. "DATABASE_CONNECTION_LIFETIME": o.databaseConnectionLifetime,
  552. "DATABASE_MAX_CONNS": o.databaseMaxConns,
  553. "DATABASE_MIN_CONNS": o.databaseMinConns,
  554. "DATABASE_URL": redactSecretValue(o.databaseURL, redactSecret),
  555. "DISABLE_HSTS": !o.hsts,
  556. "DISABLE_HTTP_SERVICE": !o.httpService,
  557. "DISABLE_SCHEDULER_SERVICE": !o.schedulerService,
  558. "FETCH_YOUTUBE_WATCH_TIME": o.fetchYouTubeWatchTime,
  559. "FETCH_ODYSEE_WATCH_TIME": o.fetchOdyseeWatchTime,
  560. "HTTPS": o.HTTPS,
  561. "HTTP_CLIENT_MAX_BODY_SIZE": o.httpClientMaxBodySize,
  562. "HTTP_CLIENT_PROXY": o.httpClientProxy,
  563. "HTTP_CLIENT_TIMEOUT": o.httpClientTimeout,
  564. "HTTP_CLIENT_USER_AGENT": o.httpClientUserAgent,
  565. "HTTP_SERVER_TIMEOUT": o.httpServerTimeout,
  566. "HTTP_SERVICE": o.httpService,
  567. "INVIDIOUS_INSTANCE": o.invidiousInstance,
  568. "KEY_FILE": o.certKeyFile,
  569. "LISTEN_ADDR": o.listenAddr,
  570. "LOG_FILE": o.logFile,
  571. "LOG_DATE_TIME": o.logDateTime,
  572. "LOG_FORMAT": o.logFormat,
  573. "LOG_LEVEL": o.logLevel,
  574. "MAINTENANCE_MESSAGE": o.maintenanceMessage,
  575. "MAINTENANCE_MODE": o.maintenanceMode,
  576. "METRICS_ALLOWED_NETWORKS": strings.Join(o.metricsAllowedNetworks, ","),
  577. "METRICS_COLLECTOR": o.metricsCollector,
  578. "METRICS_PASSWORD": redactSecretValue(o.metricsPassword, redactSecret),
  579. "METRICS_REFRESH_INTERVAL": o.metricsRefreshInterval,
  580. "METRICS_USERNAME": o.metricsUsername,
  581. "OAUTH2_CLIENT_ID": o.oauth2ClientID,
  582. "OAUTH2_CLIENT_SECRET": redactSecretValue(o.oauth2ClientSecret, redactSecret),
  583. "OAUTH2_OIDC_DISCOVERY_ENDPOINT": o.oidcDiscoveryEndpoint,
  584. "OAUTH2_PROVIDER": o.oauth2Provider,
  585. "OAUTH2_REDIRECT_URL": o.oauth2RedirectURL,
  586. "OAUTH2_USER_CREATION": o.oauth2UserCreationAllowed,
  587. "POCKET_CONSUMER_KEY": redactSecretValue(o.pocketConsumerKey, redactSecret),
  588. "POLLING_FREQUENCY": o.pollingFrequency,
  589. "FORCE_REFRESH_INTERVAL": o.forceRefreshInterval,
  590. "POLLING_PARSING_ERROR_LIMIT": o.pollingParsingErrorLimit,
  591. "POLLING_SCHEDULER": o.pollingScheduler,
  592. "PROXY_HTTP_CLIENT_TIMEOUT": o.proxyHTTPClientTimeout,
  593. "PROXY_MEDIA_TYPES": o.proxyMediaTypes,
  594. "PROXY_OPTION": o.proxyOption,
  595. "PROXY_PRIVATE_KEY": redactSecretValue(string(o.proxyPrivateKey), redactSecret),
  596. "PROXY_URL": o.proxyUrl,
  597. "ROOT_URL": o.rootURL,
  598. "RUN_MIGRATIONS": o.runMigrations,
  599. "SCHEDULER_ENTRY_FREQUENCY_MAX_INTERVAL": o.schedulerEntryFrequencyMaxInterval,
  600. "SCHEDULER_ENTRY_FREQUENCY_MIN_INTERVAL": o.schedulerEntryFrequencyMinInterval,
  601. "SCHEDULER_ENTRY_FREQUENCY_FACTOR": o.schedulerEntryFrequencyFactor,
  602. "SCHEDULER_ROUND_ROBIN_MIN_INTERVAL": o.schedulerRoundRobinMinInterval,
  603. "SCHEDULER_SERVICE": o.schedulerService,
  604. "SERVER_TIMING_HEADER": o.serverTimingHeader,
  605. "WATCHDOG": o.watchdog,
  606. "WORKER_POOL_SIZE": o.workerPoolSize,
  607. "YOUTUBE_EMBED_URL_OVERRIDE": o.youTubeEmbedUrlOverride,
  608. "WEBAUTHN": o.webAuthn,
  609. }
  610. keys := make([]string, 0, len(keyValues))
  611. for key := range keyValues {
  612. keys = append(keys, key)
  613. }
  614. sort.Strings(keys)
  615. var sortedOptions []*Option
  616. for _, key := range keys {
  617. sortedOptions = append(sortedOptions, &Option{Key: key, Value: keyValues[key]})
  618. }
  619. return sortedOptions
  620. }
  621. func (o *Options) String() string {
  622. var builder strings.Builder
  623. for _, option := range o.SortedOptions(false) {
  624. fmt.Fprintf(&builder, "%s=%v\n", option.Key, option.Value)
  625. }
  626. return builder.String()
  627. }
  628. func redactSecretValue(value string, redactSecret bool) string {
  629. if redactSecret && value != "" {
  630. return "<secret>"
  631. }
  632. return value
  633. }