options.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  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. "maps"
  6. "net"
  7. "net/url"
  8. "slices"
  9. "strings"
  10. "time"
  11. )
  12. type optionPair struct {
  13. Key string
  14. Value string
  15. }
  16. type configValueType int
  17. const (
  18. stringType configValueType = iota
  19. stringListType
  20. boolType
  21. intType
  22. int64Type
  23. urlType
  24. secondType
  25. minuteType
  26. hourType
  27. dayType
  28. secretFileType
  29. bytesType
  30. )
  31. type configValue struct {
  32. parsedStringValue string
  33. parsedBoolValue bool
  34. parsedIntValue int
  35. parsedInt64Value int64
  36. parsedDuration time.Duration
  37. parsedStringList []string
  38. parsedURLValue *url.URL
  39. parsedBytesValue []byte
  40. rawValue string
  41. valueType configValueType
  42. secret bool
  43. targetKey string
  44. validator func(string) error
  45. }
  46. type configOptions struct {
  47. rootURL string
  48. basePath string
  49. youTubeEmbedDomain string
  50. options map[string]*configValue
  51. }
  52. // NewConfigOptions creates a new instance of ConfigOptions with default values.
  53. func NewConfigOptions() *configOptions {
  54. return &configOptions{
  55. rootURL: "http://localhost",
  56. basePath: "",
  57. youTubeEmbedDomain: "www.youtube-nocookie.com",
  58. options: map[string]*configValue{
  59. "ADMIN_PASSWORD": {
  60. parsedStringValue: "",
  61. rawValue: "",
  62. valueType: stringType,
  63. secret: true,
  64. },
  65. "ADMIN_PASSWORD_FILE": {
  66. parsedStringValue: "",
  67. rawValue: "",
  68. valueType: secretFileType,
  69. targetKey: "ADMIN_PASSWORD",
  70. },
  71. "ADMIN_USERNAME": {
  72. parsedStringValue: "",
  73. rawValue: "",
  74. valueType: stringType,
  75. },
  76. "ADMIN_USERNAME_FILE": {
  77. parsedStringValue: "",
  78. rawValue: "",
  79. valueType: secretFileType,
  80. targetKey: "ADMIN_USERNAME",
  81. },
  82. "AUTH_PROXY_HEADER": {
  83. parsedStringValue: "",
  84. rawValue: "",
  85. valueType: stringType,
  86. },
  87. "AUTH_PROXY_USER_CREATION": {
  88. parsedBoolValue: false,
  89. rawValue: "0",
  90. valueType: boolType,
  91. },
  92. "BASE_URL": {
  93. parsedStringValue: "http://localhost",
  94. rawValue: "http://localhost",
  95. valueType: stringType,
  96. },
  97. "BATCH_SIZE": {
  98. parsedIntValue: 100,
  99. rawValue: "100",
  100. valueType: intType,
  101. validator: func(rawValue string) error {
  102. return validateGreaterOrEqualThan(rawValue, 1)
  103. },
  104. },
  105. "CERT_DOMAIN": {
  106. parsedStringValue: "",
  107. rawValue: "",
  108. valueType: stringType,
  109. },
  110. "CERT_FILE": {
  111. parsedStringValue: "",
  112. rawValue: "",
  113. valueType: stringType,
  114. },
  115. "CLEANUP_ARCHIVE_BATCH_SIZE": {
  116. parsedIntValue: 10000,
  117. rawValue: "10000",
  118. valueType: intType,
  119. validator: func(rawValue string) error {
  120. return validateGreaterOrEqualThan(rawValue, 1)
  121. },
  122. },
  123. "CLEANUP_ARCHIVE_READ_DAYS": {
  124. parsedDuration: time.Hour * 24 * 60,
  125. rawValue: "60",
  126. valueType: dayType,
  127. },
  128. "CLEANUP_ARCHIVE_UNREAD_DAYS": {
  129. parsedDuration: time.Hour * 24 * 180,
  130. rawValue: "180",
  131. valueType: dayType,
  132. },
  133. "CLEANUP_FREQUENCY_HOURS": {
  134. parsedDuration: time.Hour * 24,
  135. rawValue: "24",
  136. valueType: hourType,
  137. validator: func(rawValue string) error {
  138. return validateGreaterOrEqualThan(rawValue, 1)
  139. },
  140. },
  141. "CLEANUP_REMOVE_SESSIONS_DAYS": {
  142. parsedDuration: time.Hour * 24 * 30,
  143. rawValue: "30",
  144. valueType: dayType,
  145. },
  146. "CREATE_ADMIN": {
  147. parsedBoolValue: false,
  148. rawValue: "0",
  149. valueType: boolType,
  150. },
  151. "DATABASE_CONNECTION_LIFETIME": {
  152. parsedDuration: time.Minute * 5,
  153. rawValue: "5",
  154. valueType: minuteType,
  155. validator: func(rawValue string) error {
  156. return validateGreaterThan(rawValue, 0)
  157. },
  158. },
  159. "DATABASE_MAX_CONNS": {
  160. parsedIntValue: 20,
  161. rawValue: "20",
  162. valueType: intType,
  163. validator: func(rawValue string) error {
  164. return validateGreaterOrEqualThan(rawValue, 1)
  165. },
  166. },
  167. "DATABASE_MIN_CONNS": {
  168. parsedIntValue: 1,
  169. rawValue: "1",
  170. valueType: intType,
  171. validator: func(rawValue string) error {
  172. return validateGreaterOrEqualThan(rawValue, 0)
  173. },
  174. },
  175. "DATABASE_URL": {
  176. parsedStringValue: "user=postgres password=postgres dbname=miniflux2 sslmode=disable",
  177. rawValue: "user=postgres password=postgres dbname=miniflux2 sslmode=disable",
  178. valueType: stringType,
  179. secret: true,
  180. },
  181. "DATABASE_URL_FILE": {
  182. parsedStringValue: "",
  183. rawValue: "",
  184. valueType: secretFileType,
  185. targetKey: "DATABASE_URL",
  186. },
  187. "DISABLE_API": {
  188. parsedBoolValue: false,
  189. rawValue: "0",
  190. valueType: boolType,
  191. },
  192. "DISABLE_HSTS": {
  193. parsedBoolValue: false,
  194. rawValue: "0",
  195. valueType: boolType,
  196. },
  197. "DISABLE_HTTP_SERVICE": {
  198. parsedBoolValue: false,
  199. rawValue: "0",
  200. valueType: boolType,
  201. },
  202. "DISABLE_LOCAL_AUTH": {
  203. parsedBoolValue: false,
  204. rawValue: "0",
  205. valueType: boolType,
  206. },
  207. "DISABLE_SCHEDULER_SERVICE": {
  208. parsedBoolValue: false,
  209. rawValue: "0",
  210. valueType: boolType,
  211. },
  212. "FETCHER_ALLOW_PRIVATE_NETWORKS": {
  213. parsedBoolValue: false,
  214. rawValue: "0",
  215. valueType: boolType,
  216. },
  217. "FETCH_BILIBILI_WATCH_TIME": {
  218. parsedBoolValue: false,
  219. rawValue: "0",
  220. valueType: boolType,
  221. },
  222. "FETCH_NEBULA_WATCH_TIME": {
  223. parsedBoolValue: false,
  224. rawValue: "0",
  225. valueType: boolType,
  226. },
  227. "FETCH_ODYSEE_WATCH_TIME": {
  228. parsedBoolValue: false,
  229. rawValue: "0",
  230. valueType: boolType,
  231. },
  232. "FETCH_YOUTUBE_WATCH_TIME": {
  233. parsedBoolValue: false,
  234. rawValue: "0",
  235. valueType: boolType,
  236. },
  237. "FORCE_REFRESH_INTERVAL": {
  238. parsedDuration: 30 * time.Minute,
  239. rawValue: "30",
  240. valueType: minuteType,
  241. validator: func(rawValue string) error {
  242. return validateGreaterThan(rawValue, 0)
  243. },
  244. },
  245. "HTTP_CLIENT_MAX_BODY_SIZE": {
  246. parsedInt64Value: 15,
  247. rawValue: "15",
  248. valueType: int64Type,
  249. validator: func(rawValue string) error {
  250. return validateGreaterOrEqualThan(rawValue, 1)
  251. },
  252. },
  253. "HTTP_CLIENT_PROXIES": {
  254. parsedStringList: []string{},
  255. rawValue: "",
  256. valueType: stringListType,
  257. secret: true,
  258. },
  259. "HTTP_CLIENT_PROXY": {
  260. parsedURLValue: nil,
  261. rawValue: "",
  262. valueType: urlType,
  263. secret: true,
  264. },
  265. "HTTP_CLIENT_TIMEOUT": {
  266. parsedDuration: 20 * time.Second,
  267. rawValue: "20",
  268. valueType: secondType,
  269. validator: func(rawValue string) error {
  270. return validateGreaterOrEqualThan(rawValue, 1)
  271. },
  272. },
  273. "HTTP_CLIENT_USER_AGENT": {
  274. parsedStringValue: "",
  275. rawValue: "",
  276. valueType: stringType,
  277. },
  278. "HTTP_SERVER_TIMEOUT": {
  279. parsedDuration: 300 * time.Second,
  280. rawValue: "300",
  281. valueType: secondType,
  282. validator: func(rawValue string) error {
  283. return validateGreaterOrEqualThan(rawValue, 1)
  284. },
  285. },
  286. "HTTPS": {
  287. parsedBoolValue: false,
  288. rawValue: "0",
  289. valueType: boolType,
  290. },
  291. "INTEGRATION_ALLOW_PRIVATE_NETWORKS": {
  292. parsedBoolValue: false,
  293. rawValue: "0",
  294. valueType: boolType,
  295. },
  296. "INVIDIOUS_INSTANCE": {
  297. parsedStringValue: "yewtu.be",
  298. rawValue: "yewtu.be",
  299. valueType: stringType,
  300. },
  301. "KEY_FILE": {
  302. parsedStringValue: "",
  303. rawValue: "",
  304. valueType: stringType,
  305. },
  306. "LISTEN_ADDR": {
  307. parsedStringList: []string{"127.0.0.1:8080"},
  308. rawValue: "127.0.0.1:8080",
  309. valueType: stringListType,
  310. },
  311. "LOG_DATE_TIME": {
  312. parsedBoolValue: false,
  313. rawValue: "0",
  314. valueType: boolType,
  315. },
  316. "LOG_FILE": {
  317. parsedStringValue: "stderr",
  318. rawValue: "stderr",
  319. valueType: stringType,
  320. },
  321. "LOG_FORMAT": {
  322. parsedStringValue: "text",
  323. rawValue: "text",
  324. valueType: stringType,
  325. validator: func(rawValue string) error {
  326. return validateChoices(rawValue, []string{"text", "json"})
  327. },
  328. },
  329. "LOG_LEVEL": {
  330. parsedStringValue: "info",
  331. rawValue: "info",
  332. valueType: stringType,
  333. validator: func(rawValue string) error {
  334. return validateChoices(rawValue, []string{"debug", "info", "warning", "error"})
  335. },
  336. },
  337. "MAINTENANCE_MESSAGE": {
  338. parsedStringValue: "Miniflux is currently under maintenance",
  339. rawValue: "Miniflux is currently under maintenance",
  340. valueType: stringType,
  341. },
  342. "MAINTENANCE_MODE": {
  343. parsedBoolValue: false,
  344. rawValue: "0",
  345. valueType: boolType,
  346. },
  347. "MEDIA_PROXY_CUSTOM_URL": {
  348. rawValue: "",
  349. valueType: urlType,
  350. },
  351. "MEDIA_PROXY_HTTP_CLIENT_TIMEOUT": {
  352. parsedDuration: 120 * time.Second,
  353. rawValue: "120",
  354. valueType: secondType,
  355. validator: func(rawValue string) error {
  356. return validateGreaterOrEqualThan(rawValue, 1)
  357. },
  358. },
  359. "MEDIA_PROXY_MODE": {
  360. parsedStringValue: "http-only",
  361. rawValue: "http-only",
  362. valueType: stringType,
  363. validator: func(rawValue string) error {
  364. return validateChoices(rawValue, []string{"none", "http-only", "all"})
  365. },
  366. },
  367. "MEDIA_PROXY_PRIVATE_KEY": {
  368. valueType: bytesType,
  369. secret: true,
  370. },
  371. "MEDIA_PROXY_RESOURCE_TYPES": {
  372. parsedStringList: []string{"image"},
  373. rawValue: "image",
  374. valueType: stringListType,
  375. validator: func(rawValue string) error {
  376. return validateListChoices(strings.Split(rawValue, ","), []string{"image", "video", "audio"})
  377. },
  378. },
  379. "METRICS_ALLOWED_NETWORKS": {
  380. parsedStringList: []string{"127.0.0.1/8"},
  381. rawValue: "127.0.0.1/8",
  382. valueType: stringListType,
  383. },
  384. "METRICS_COLLECTOR": {
  385. parsedBoolValue: false,
  386. rawValue: "0",
  387. valueType: boolType,
  388. },
  389. "METRICS_PASSWORD": {
  390. parsedStringValue: "",
  391. rawValue: "",
  392. valueType: stringType,
  393. secret: true,
  394. },
  395. "METRICS_PASSWORD_FILE": {
  396. parsedStringValue: "",
  397. rawValue: "",
  398. valueType: secretFileType,
  399. targetKey: "METRICS_PASSWORD",
  400. },
  401. "METRICS_REFRESH_INTERVAL": {
  402. parsedDuration: 60 * time.Second,
  403. rawValue: "60",
  404. valueType: secondType,
  405. validator: func(rawValue string) error {
  406. return validateGreaterOrEqualThan(rawValue, 1)
  407. },
  408. },
  409. "METRICS_USERNAME": {
  410. parsedStringValue: "",
  411. rawValue: "",
  412. valueType: stringType,
  413. },
  414. "METRICS_USERNAME_FILE": {
  415. parsedStringValue: "",
  416. rawValue: "",
  417. valueType: secretFileType,
  418. targetKey: "METRICS_USERNAME",
  419. },
  420. "OAUTH2_CLIENT_ID": {
  421. parsedStringValue: "",
  422. rawValue: "",
  423. valueType: stringType,
  424. secret: true,
  425. },
  426. "OAUTH2_CLIENT_ID_FILE": {
  427. parsedStringValue: "",
  428. rawValue: "",
  429. valueType: secretFileType,
  430. targetKey: "OAUTH2_CLIENT_ID",
  431. },
  432. "OAUTH2_CLIENT_SECRET": {
  433. parsedStringValue: "",
  434. rawValue: "",
  435. valueType: stringType,
  436. secret: true,
  437. },
  438. "OAUTH2_CLIENT_SECRET_FILE": {
  439. parsedStringValue: "",
  440. rawValue: "",
  441. valueType: secretFileType,
  442. targetKey: "OAUTH2_CLIENT_SECRET",
  443. },
  444. "OAUTH2_OIDC_DISCOVERY_ENDPOINT": {
  445. parsedStringValue: "",
  446. rawValue: "",
  447. valueType: stringType,
  448. },
  449. "OAUTH2_OIDC_PROVIDER_NAME": {
  450. parsedStringValue: "OpenID Connect",
  451. rawValue: "OpenID Connect",
  452. valueType: stringType,
  453. },
  454. "OAUTH2_PROVIDER": {
  455. parsedStringValue: "",
  456. rawValue: "",
  457. valueType: stringType,
  458. validator: func(rawValue string) error {
  459. return validateChoices(rawValue, []string{"oidc", "google"})
  460. },
  461. },
  462. "OAUTH2_REDIRECT_URL": {
  463. parsedStringValue: "",
  464. rawValue: "",
  465. valueType: stringType,
  466. },
  467. "OAUTH2_USER_CREATION": {
  468. parsedBoolValue: false,
  469. rawValue: "0",
  470. valueType: boolType,
  471. },
  472. "POLLING_FREQUENCY": {
  473. parsedDuration: 60 * time.Minute,
  474. rawValue: "60",
  475. valueType: minuteType,
  476. validator: func(rawValue string) error {
  477. return validateGreaterOrEqualThan(rawValue, 1)
  478. },
  479. },
  480. "POLLING_LIMIT_PER_HOST": {
  481. parsedIntValue: 0,
  482. rawValue: "0",
  483. valueType: intType,
  484. validator: func(rawValue string) error {
  485. return validateGreaterOrEqualThan(rawValue, 0)
  486. },
  487. },
  488. "POLLING_PARSING_ERROR_LIMIT": {
  489. parsedIntValue: 3,
  490. rawValue: "3",
  491. valueType: intType,
  492. validator: func(rawValue string) error {
  493. return validateGreaterOrEqualThan(rawValue, 0)
  494. },
  495. },
  496. "POLLING_SCHEDULER": {
  497. parsedStringValue: "round_robin",
  498. rawValue: "round_robin",
  499. valueType: stringType,
  500. validator: func(rawValue string) error {
  501. return validateChoices(rawValue, []string{"round_robin", "entry_frequency"})
  502. },
  503. },
  504. "PORT": {
  505. parsedStringValue: "",
  506. rawValue: "",
  507. valueType: stringType,
  508. validator: func(rawValue string) error {
  509. return validateRange(rawValue, 1, 65535)
  510. },
  511. },
  512. "RUN_MIGRATIONS": {
  513. parsedBoolValue: false,
  514. rawValue: "0",
  515. valueType: boolType,
  516. },
  517. "SCHEDULER_ENTRY_FREQUENCY_FACTOR": {
  518. parsedIntValue: 1,
  519. rawValue: "1",
  520. valueType: intType,
  521. },
  522. "SCHEDULER_ENTRY_FREQUENCY_MAX_INTERVAL": {
  523. parsedDuration: 24 * time.Hour,
  524. rawValue: "1440",
  525. valueType: minuteType,
  526. validator: func(rawValue string) error {
  527. return validateGreaterOrEqualThan(rawValue, 1)
  528. },
  529. },
  530. "SCHEDULER_ENTRY_FREQUENCY_MIN_INTERVAL": {
  531. parsedDuration: 5 * time.Minute,
  532. rawValue: "5",
  533. valueType: minuteType,
  534. validator: func(rawValue string) error {
  535. return validateGreaterOrEqualThan(rawValue, 1)
  536. },
  537. },
  538. "SCHEDULER_ROUND_ROBIN_MAX_INTERVAL": {
  539. parsedDuration: 1440 * time.Minute,
  540. rawValue: "1440",
  541. valueType: minuteType,
  542. validator: func(rawValue string) error {
  543. return validateGreaterOrEqualThan(rawValue, 1)
  544. },
  545. },
  546. "SCHEDULER_ROUND_ROBIN_MIN_INTERVAL": {
  547. parsedDuration: 60 * time.Minute,
  548. rawValue: "60",
  549. valueType: minuteType,
  550. validator: func(rawValue string) error {
  551. return validateGreaterOrEqualThan(rawValue, 1)
  552. },
  553. },
  554. "TRUSTED_REVERSE_PROXY_NETWORKS": {
  555. parsedStringList: []string{},
  556. rawValue: "",
  557. valueType: stringListType,
  558. validator: func(rawValue string) error {
  559. for ip := range strings.SplitSeq(rawValue, ",") {
  560. if _, _, err := net.ParseCIDR(ip); err != nil {
  561. return err
  562. }
  563. }
  564. return nil
  565. },
  566. },
  567. "WATCHDOG": {
  568. parsedBoolValue: true,
  569. rawValue: "1",
  570. valueType: boolType,
  571. },
  572. "WEBAUTHN": {
  573. parsedBoolValue: false,
  574. rawValue: "0",
  575. valueType: boolType,
  576. },
  577. "WORKER_POOL_SIZE": {
  578. parsedIntValue: 16,
  579. rawValue: "16",
  580. valueType: intType,
  581. validator: func(rawValue string) error {
  582. return validateGreaterOrEqualThan(rawValue, 1)
  583. },
  584. },
  585. "YOUTUBE_API_KEY": {
  586. parsedStringValue: "",
  587. rawValue: "",
  588. valueType: stringType,
  589. secret: true,
  590. },
  591. "YOUTUBE_EMBED_URL_OVERRIDE": {
  592. parsedStringValue: "https://www.youtube-nocookie.com/embed/",
  593. rawValue: "https://www.youtube-nocookie.com/embed/",
  594. valueType: stringType,
  595. },
  596. },
  597. }
  598. }
  599. func (c *configOptions) AdminPassword() string {
  600. return c.options["ADMIN_PASSWORD"].parsedStringValue
  601. }
  602. func (c *configOptions) AdminUsername() string {
  603. return c.options["ADMIN_USERNAME"].parsedStringValue
  604. }
  605. func (c *configOptions) AuthProxyHeader() string {
  606. return c.options["AUTH_PROXY_HEADER"].parsedStringValue
  607. }
  608. func (c *configOptions) AuthProxyUserCreation() bool {
  609. return c.options["AUTH_PROXY_USER_CREATION"].parsedBoolValue
  610. }
  611. func (c *configOptions) BasePath() string {
  612. return c.basePath
  613. }
  614. func (c *configOptions) BaseURL() string {
  615. return c.options["BASE_URL"].parsedStringValue
  616. }
  617. func (c *configOptions) RootURL() string {
  618. return c.rootURL
  619. }
  620. func (c *configOptions) BatchSize() int {
  621. return c.options["BATCH_SIZE"].parsedIntValue
  622. }
  623. func (c *configOptions) CertDomain() string {
  624. return c.options["CERT_DOMAIN"].parsedStringValue
  625. }
  626. func (c *configOptions) CertFile() string {
  627. return c.options["CERT_FILE"].parsedStringValue
  628. }
  629. func (c *configOptions) CleanupArchiveBatchSize() int {
  630. return c.options["CLEANUP_ARCHIVE_BATCH_SIZE"].parsedIntValue
  631. }
  632. func (c *configOptions) CleanupArchiveReadInterval() time.Duration {
  633. return c.options["CLEANUP_ARCHIVE_READ_DAYS"].parsedDuration
  634. }
  635. func (c *configOptions) CleanupArchiveUnreadInterval() time.Duration {
  636. return c.options["CLEANUP_ARCHIVE_UNREAD_DAYS"].parsedDuration
  637. }
  638. func (c *configOptions) CleanupFrequency() time.Duration {
  639. return c.options["CLEANUP_FREQUENCY_HOURS"].parsedDuration
  640. }
  641. func (c *configOptions) CleanupRemoveSessionsInterval() time.Duration {
  642. return c.options["CLEANUP_REMOVE_SESSIONS_DAYS"].parsedDuration
  643. }
  644. func (c *configOptions) CreateAdmin() bool {
  645. return c.options["CREATE_ADMIN"].parsedBoolValue
  646. }
  647. func (c *configOptions) DatabaseConnectionLifetime() time.Duration {
  648. return c.options["DATABASE_CONNECTION_LIFETIME"].parsedDuration
  649. }
  650. func (c *configOptions) DatabaseMaxConns() int {
  651. return c.options["DATABASE_MAX_CONNS"].parsedIntValue
  652. }
  653. func (c *configOptions) DatabaseMinConns() int {
  654. return c.options["DATABASE_MIN_CONNS"].parsedIntValue
  655. }
  656. func (c *configOptions) DatabaseURL() string {
  657. return c.options["DATABASE_URL"].parsedStringValue
  658. }
  659. func (c *configOptions) DisableHSTS() bool {
  660. return c.options["DISABLE_HSTS"].parsedBoolValue
  661. }
  662. func (c *configOptions) DisableHTTPService() bool {
  663. return c.options["DISABLE_HTTP_SERVICE"].parsedBoolValue
  664. }
  665. func (c *configOptions) DisableLocalAuth() bool {
  666. return c.options["DISABLE_LOCAL_AUTH"].parsedBoolValue
  667. }
  668. func (c *configOptions) DisableSchedulerService() bool {
  669. return c.options["DISABLE_SCHEDULER_SERVICE"].parsedBoolValue
  670. }
  671. func (c *configOptions) FetchBilibiliWatchTime() bool {
  672. return c.options["FETCH_BILIBILI_WATCH_TIME"].parsedBoolValue
  673. }
  674. func (c *configOptions) FetchNebulaWatchTime() bool {
  675. return c.options["FETCH_NEBULA_WATCH_TIME"].parsedBoolValue
  676. }
  677. func (c *configOptions) FetchOdyseeWatchTime() bool {
  678. return c.options["FETCH_ODYSEE_WATCH_TIME"].parsedBoolValue
  679. }
  680. func (c *configOptions) FetchYouTubeWatchTime() bool {
  681. return c.options["FETCH_YOUTUBE_WATCH_TIME"].parsedBoolValue
  682. }
  683. func (c *configOptions) ForceRefreshInterval() time.Duration {
  684. return c.options["FORCE_REFRESH_INTERVAL"].parsedDuration
  685. }
  686. func (c *configOptions) HasHTTPClientProxiesConfigured() bool {
  687. return len(c.options["HTTP_CLIENT_PROXIES"].parsedStringList) > 0
  688. }
  689. func (c *configOptions) HasAPI() bool {
  690. return !c.options["DISABLE_API"].parsedBoolValue
  691. }
  692. func (c *configOptions) HasHTTPService() bool {
  693. return !c.options["DISABLE_HTTP_SERVICE"].parsedBoolValue
  694. }
  695. func (c *configOptions) HasHSTS() bool {
  696. return !c.options["DISABLE_HSTS"].parsedBoolValue
  697. }
  698. func (c *configOptions) HasHTTPClientProxyURLConfigured() bool {
  699. return c.options["HTTP_CLIENT_PROXY"].parsedURLValue != nil
  700. }
  701. func (c *configOptions) HasMaintenanceMode() bool {
  702. return c.options["MAINTENANCE_MODE"].parsedBoolValue
  703. }
  704. func (c *configOptions) HasMetricsCollector() bool {
  705. return c.options["METRICS_COLLECTOR"].parsedBoolValue
  706. }
  707. func (c *configOptions) HasSchedulerService() bool {
  708. return !c.options["DISABLE_SCHEDULER_SERVICE"].parsedBoolValue
  709. }
  710. func (c *configOptions) HasWatchdog() bool {
  711. return c.options["WATCHDOG"].parsedBoolValue
  712. }
  713. func (c *configOptions) HTTPClientMaxBodySize() int64 {
  714. return c.options["HTTP_CLIENT_MAX_BODY_SIZE"].parsedInt64Value * 1024 * 1024
  715. }
  716. func (c *configOptions) HTTPClientProxies() []string {
  717. return c.options["HTTP_CLIENT_PROXIES"].parsedStringList
  718. }
  719. func (c *configOptions) HTTPClientProxyURL() *url.URL {
  720. return c.options["HTTP_CLIENT_PROXY"].parsedURLValue
  721. }
  722. func (c *configOptions) HTTPClientTimeout() time.Duration {
  723. return c.options["HTTP_CLIENT_TIMEOUT"].parsedDuration
  724. }
  725. func (c *configOptions) HTTPClientUserAgent() string {
  726. if c.options["HTTP_CLIENT_USER_AGENT"].parsedStringValue != "" {
  727. return c.options["HTTP_CLIENT_USER_AGENT"].parsedStringValue
  728. }
  729. return defaultHTTPClientUserAgent
  730. }
  731. func (c *configOptions) HTTPServerTimeout() time.Duration {
  732. return c.options["HTTP_SERVER_TIMEOUT"].parsedDuration
  733. }
  734. func (c *configOptions) HTTPS() bool {
  735. return c.options["HTTPS"].parsedBoolValue
  736. }
  737. func (c *configOptions) FetcherAllowPrivateNetworks() bool {
  738. return c.options["FETCHER_ALLOW_PRIVATE_NETWORKS"].parsedBoolValue
  739. }
  740. func (c *configOptions) IntegrationAllowPrivateNetworks() bool {
  741. if c == nil {
  742. return false
  743. }
  744. return c.options["INTEGRATION_ALLOW_PRIVATE_NETWORKS"].parsedBoolValue
  745. }
  746. func (c *configOptions) InvidiousInstance() string {
  747. return c.options["INVIDIOUS_INSTANCE"].parsedStringValue
  748. }
  749. func (c *configOptions) IsAuthProxyUserCreationAllowed() bool {
  750. return c.options["AUTH_PROXY_USER_CREATION"].parsedBoolValue
  751. }
  752. func (c *configOptions) IsDefaultDatabaseURL() bool {
  753. return c.options["DATABASE_URL"].rawValue == "user=postgres password=postgres dbname=miniflux2 sslmode=disable"
  754. }
  755. func (c *configOptions) IsOAuth2UserCreationAllowed() bool {
  756. return c.options["OAUTH2_USER_CREATION"].parsedBoolValue
  757. }
  758. func (c *configOptions) CertKeyFile() string {
  759. return c.options["KEY_FILE"].parsedStringValue
  760. }
  761. func (c *configOptions) ListenAddr() []string {
  762. return c.options["LISTEN_ADDR"].parsedStringList
  763. }
  764. func (c *configOptions) LogFile() string {
  765. return c.options["LOG_FILE"].parsedStringValue
  766. }
  767. func (c *configOptions) LogDateTime() bool {
  768. return c.options["LOG_DATE_TIME"].parsedBoolValue
  769. }
  770. func (c *configOptions) LogFormat() string {
  771. return c.options["LOG_FORMAT"].parsedStringValue
  772. }
  773. func (c *configOptions) LogLevel() string {
  774. return c.options["LOG_LEVEL"].parsedStringValue
  775. }
  776. func (c *configOptions) MaintenanceMessage() string {
  777. return c.options["MAINTENANCE_MESSAGE"].parsedStringValue
  778. }
  779. func (c *configOptions) MaintenanceMode() bool {
  780. return c.options["MAINTENANCE_MODE"].parsedBoolValue
  781. }
  782. func (c *configOptions) MediaCustomProxyURL() *url.URL {
  783. return c.options["MEDIA_PROXY_CUSTOM_URL"].parsedURLValue
  784. }
  785. func (c *configOptions) MediaProxyHTTPClientTimeout() time.Duration {
  786. return c.options["MEDIA_PROXY_HTTP_CLIENT_TIMEOUT"].parsedDuration
  787. }
  788. func (c *configOptions) MediaProxyMode() string {
  789. return c.options["MEDIA_PROXY_MODE"].parsedStringValue
  790. }
  791. func (c *configOptions) MediaProxyPrivateKey() []byte {
  792. return c.options["MEDIA_PROXY_PRIVATE_KEY"].parsedBytesValue
  793. }
  794. func (c *configOptions) MediaProxyResourceTypes() []string {
  795. return c.options["MEDIA_PROXY_RESOURCE_TYPES"].parsedStringList
  796. }
  797. func (c *configOptions) MetricsAllowedNetworks() []string {
  798. return c.options["METRICS_ALLOWED_NETWORKS"].parsedStringList
  799. }
  800. func (c *configOptions) MetricsCollector() bool {
  801. return c.options["METRICS_COLLECTOR"].parsedBoolValue
  802. }
  803. func (c *configOptions) MetricsPassword() string {
  804. return c.options["METRICS_PASSWORD"].parsedStringValue
  805. }
  806. func (c *configOptions) MetricsRefreshInterval() time.Duration {
  807. return c.options["METRICS_REFRESH_INTERVAL"].parsedDuration
  808. }
  809. func (c *configOptions) MetricsUsername() string {
  810. return c.options["METRICS_USERNAME"].parsedStringValue
  811. }
  812. func (c *configOptions) OAuth2ClientID() string {
  813. return c.options["OAUTH2_CLIENT_ID"].parsedStringValue
  814. }
  815. func (c *configOptions) OAuth2ClientSecret() string {
  816. return c.options["OAUTH2_CLIENT_SECRET"].parsedStringValue
  817. }
  818. func (c *configOptions) OAuth2OIDCDiscoveryEndpoint() string {
  819. return c.options["OAUTH2_OIDC_DISCOVERY_ENDPOINT"].parsedStringValue
  820. }
  821. func (c *configOptions) OAuth2OIDCProviderName() string {
  822. return c.options["OAUTH2_OIDC_PROVIDER_NAME"].parsedStringValue
  823. }
  824. func (c *configOptions) OAuth2Provider() string {
  825. return c.options["OAUTH2_PROVIDER"].parsedStringValue
  826. }
  827. func (c *configOptions) OAuth2RedirectURL() string {
  828. return c.options["OAUTH2_REDIRECT_URL"].parsedStringValue
  829. }
  830. func (c *configOptions) OAuth2UserCreation() bool {
  831. return c.options["OAUTH2_USER_CREATION"].parsedBoolValue
  832. }
  833. func (c *configOptions) PollingFrequency() time.Duration {
  834. return c.options["POLLING_FREQUENCY"].parsedDuration
  835. }
  836. func (c *configOptions) PollingLimitPerHost() int {
  837. return c.options["POLLING_LIMIT_PER_HOST"].parsedIntValue
  838. }
  839. func (c *configOptions) PollingParsingErrorLimit() int {
  840. return c.options["POLLING_PARSING_ERROR_LIMIT"].parsedIntValue
  841. }
  842. func (c *configOptions) PollingScheduler() string {
  843. return c.options["POLLING_SCHEDULER"].parsedStringValue
  844. }
  845. func (c *configOptions) Port() string {
  846. return c.options["PORT"].parsedStringValue
  847. }
  848. func (c *configOptions) RunMigrations() bool {
  849. return c.options["RUN_MIGRATIONS"].parsedBoolValue
  850. }
  851. func (c *configOptions) SetLogLevel(level string) {
  852. c.options["LOG_LEVEL"].parsedStringValue = level
  853. c.options["LOG_LEVEL"].rawValue = level
  854. }
  855. func (c *configOptions) SetHTTPSValue(value bool) {
  856. c.options["HTTPS"].parsedBoolValue = value
  857. if value {
  858. c.options["HTTPS"].rawValue = "1"
  859. } else {
  860. c.options["HTTPS"].rawValue = "0"
  861. }
  862. }
  863. func (c *configOptions) SchedulerEntryFrequencyFactor() int {
  864. return c.options["SCHEDULER_ENTRY_FREQUENCY_FACTOR"].parsedIntValue
  865. }
  866. func (c *configOptions) SchedulerEntryFrequencyMaxInterval() time.Duration {
  867. return c.options["SCHEDULER_ENTRY_FREQUENCY_MAX_INTERVAL"].parsedDuration
  868. }
  869. func (c *configOptions) SchedulerEntryFrequencyMinInterval() time.Duration {
  870. return c.options["SCHEDULER_ENTRY_FREQUENCY_MIN_INTERVAL"].parsedDuration
  871. }
  872. func (c *configOptions) SchedulerRoundRobinMaxInterval() time.Duration {
  873. return c.options["SCHEDULER_ROUND_ROBIN_MAX_INTERVAL"].parsedDuration
  874. }
  875. func (c *configOptions) SchedulerRoundRobinMinInterval() time.Duration {
  876. return c.options["SCHEDULER_ROUND_ROBIN_MIN_INTERVAL"].parsedDuration
  877. }
  878. func (c *configOptions) TrustedReverseProxyNetworks() []string {
  879. return c.options["TRUSTED_REVERSE_PROXY_NETWORKS"].parsedStringList
  880. }
  881. func (c *configOptions) Watchdog() bool {
  882. return c.options["WATCHDOG"].parsedBoolValue
  883. }
  884. func (c *configOptions) WebAuthn() bool {
  885. return c.options["WEBAUTHN"].parsedBoolValue
  886. }
  887. func (c *configOptions) WorkerPoolSize() int {
  888. return c.options["WORKER_POOL_SIZE"].parsedIntValue
  889. }
  890. func (c *configOptions) YouTubeAPIKey() string {
  891. return c.options["YOUTUBE_API_KEY"].parsedStringValue
  892. }
  893. func (c *configOptions) YouTubeEmbedUrlOverride() string {
  894. return c.options["YOUTUBE_EMBED_URL_OVERRIDE"].parsedStringValue
  895. }
  896. func (c *configOptions) YouTubeEmbedDomain() string {
  897. return c.youTubeEmbedDomain
  898. }
  899. func (c *configOptions) ConfigMap(redactSecret bool) []*optionPair {
  900. sortedKeys := slices.Sorted(maps.Keys(c.options))
  901. sortedOptions := make([]*optionPair, 0, len(sortedKeys))
  902. for _, key := range sortedKeys {
  903. value := c.options[key]
  904. displayValue := value.rawValue
  905. if displayValue != "" && redactSecret && value.secret {
  906. displayValue = "<redacted>"
  907. }
  908. sortedOptions = append(sortedOptions, &optionPair{Key: key, Value: displayValue})
  909. }
  910. return sortedOptions
  911. }
  912. func (c *configOptions) String() string {
  913. var builder strings.Builder
  914. for _, option := range c.ConfigMap(false) {
  915. builder.WriteString(option.Key)
  916. builder.WriteByte('=')
  917. builder.WriteString(option.Value)
  918. builder.WriteByte('\n')
  919. }
  920. return builder.String()
  921. }