options.go 28 KB

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