options.go 27 KB

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