options.go 27 KB

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