options.go 27 KB

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