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_HSTS": {
  188. ParsedBoolValue: false,
  189. RawValue: "0",
  190. ValueType: boolType,
  191. },
  192. "DISABLE_HTTP_SERVICE": {
  193. ParsedBoolValue: false,
  194. RawValue: "0",
  195. ValueType: boolType,
  196. },
  197. "DISABLE_LOCAL_AUTH": {
  198. ParsedBoolValue: false,
  199. RawValue: "0",
  200. ValueType: boolType,
  201. },
  202. "DISABLE_SCHEDULER_SERVICE": {
  203. ParsedBoolValue: false,
  204. RawValue: "0",
  205. ValueType: boolType,
  206. },
  207. "FETCH_BILIBILI_WATCH_TIME": {
  208. ParsedBoolValue: false,
  209. RawValue: "0",
  210. ValueType: boolType,
  211. },
  212. "FETCH_NEBULA_WATCH_TIME": {
  213. ParsedBoolValue: false,
  214. RawValue: "0",
  215. ValueType: boolType,
  216. },
  217. "FETCH_ODYSEE_WATCH_TIME": {
  218. ParsedBoolValue: false,
  219. RawValue: "0",
  220. ValueType: boolType,
  221. },
  222. "FETCH_YOUTUBE_WATCH_TIME": {
  223. ParsedBoolValue: false,
  224. RawValue: "0",
  225. ValueType: boolType,
  226. },
  227. "FILTER_ENTRY_MAX_AGE_DAYS": {
  228. ParsedIntValue: 0,
  229. RawValue: "0",
  230. ValueType: intType,
  231. Validator: func(rawValue string) error {
  232. return validateGreaterOrEqualThan(rawValue, 0)
  233. },
  234. },
  235. "FORCE_REFRESH_INTERVAL": {
  236. ParsedDuration: 30 * time.Minute,
  237. RawValue: "30",
  238. ValueType: minuteType,
  239. Validator: func(rawValue string) error {
  240. return validateGreaterThan(rawValue, 0)
  241. },
  242. },
  243. "HTTP_CLIENT_MAX_BODY_SIZE": {
  244. ParsedInt64Value: 15,
  245. RawValue: "15",
  246. ValueType: int64Type,
  247. Validator: func(rawValue string) error {
  248. return validateGreaterOrEqualThan(rawValue, 1)
  249. },
  250. },
  251. "HTTP_CLIENT_PROXIES": {
  252. ParsedStringList: []string{},
  253. RawValue: "",
  254. ValueType: stringListType,
  255. Secret: true,
  256. },
  257. "HTTP_CLIENT_PROXY": {
  258. ParsedURLValue: nil,
  259. RawValue: "",
  260. ValueType: urlType,
  261. Secret: true,
  262. },
  263. "HTTP_CLIENT_TIMEOUT": {
  264. ParsedDuration: 20 * time.Second,
  265. RawValue: "20",
  266. ValueType: secondType,
  267. Validator: func(rawValue string) error {
  268. return validateGreaterOrEqualThan(rawValue, 1)
  269. },
  270. },
  271. "HTTP_CLIENT_USER_AGENT": {
  272. ParsedStringValue: "",
  273. RawValue: "",
  274. ValueType: stringType,
  275. },
  276. "HTTP_SERVER_TIMEOUT": {
  277. ParsedDuration: 300 * time.Second,
  278. RawValue: "300",
  279. ValueType: secondType,
  280. Validator: func(rawValue string) error {
  281. return validateGreaterOrEqualThan(rawValue, 1)
  282. },
  283. },
  284. "HTTPS": {
  285. ParsedBoolValue: false,
  286. RawValue: "0",
  287. ValueType: boolType,
  288. },
  289. "INVIDIOUS_INSTANCE": {
  290. ParsedStringValue: "yewtu.be",
  291. RawValue: "yewtu.be",
  292. ValueType: stringType,
  293. },
  294. "KEY_FILE": {
  295. ParsedStringValue: "",
  296. RawValue: "",
  297. ValueType: stringType,
  298. },
  299. "LISTEN_ADDR": {
  300. ParsedStringList: []string{"127.0.0.1:8080"},
  301. RawValue: "127.0.0.1:8080",
  302. ValueType: stringListType,
  303. },
  304. "LOG_DATE_TIME": {
  305. ParsedBoolValue: false,
  306. RawValue: "0",
  307. ValueType: boolType,
  308. },
  309. "LOG_FILE": {
  310. ParsedStringValue: "stderr",
  311. RawValue: "stderr",
  312. ValueType: stringType,
  313. },
  314. "LOG_FORMAT": {
  315. ParsedStringValue: "text",
  316. RawValue: "text",
  317. ValueType: stringType,
  318. Validator: func(rawValue string) error {
  319. return validateChoices(rawValue, []string{"text", "json"})
  320. },
  321. },
  322. "LOG_LEVEL": {
  323. ParsedStringValue: "info",
  324. RawValue: "info",
  325. ValueType: stringType,
  326. Validator: func(rawValue string) error {
  327. return validateChoices(rawValue, []string{"debug", "info", "warning", "error"})
  328. },
  329. },
  330. "MAINTENANCE_MESSAGE": {
  331. ParsedStringValue: "Miniflux is currently under maintenance",
  332. RawValue: "Miniflux is currently under maintenance",
  333. ValueType: stringType,
  334. },
  335. "MAINTENANCE_MODE": {
  336. ParsedBoolValue: false,
  337. RawValue: "0",
  338. ValueType: boolType,
  339. },
  340. "MEDIA_PROXY_CUSTOM_URL": {
  341. RawValue: "",
  342. ValueType: urlType,
  343. },
  344. "MEDIA_PROXY_HTTP_CLIENT_TIMEOUT": {
  345. ParsedDuration: 120 * time.Second,
  346. RawValue: "120",
  347. ValueType: secondType,
  348. Validator: func(rawValue string) error {
  349. return validateGreaterOrEqualThan(rawValue, 1)
  350. },
  351. },
  352. "MEDIA_PROXY_MODE": {
  353. ParsedStringValue: "http-only",
  354. RawValue: "http-only",
  355. ValueType: stringType,
  356. Validator: func(rawValue string) error {
  357. return validateChoices(rawValue, []string{"none", "http-only", "all"})
  358. },
  359. },
  360. "MEDIA_PROXY_PRIVATE_KEY": {
  361. ValueType: bytesType,
  362. Secret: true,
  363. },
  364. "MEDIA_PROXY_RESOURCE_TYPES": {
  365. ParsedStringList: []string{"image"},
  366. RawValue: "image",
  367. ValueType: stringListType,
  368. Validator: func(rawValue string) error {
  369. return validateListChoices(strings.Split(rawValue, ","), []string{"image", "video", "audio"})
  370. },
  371. },
  372. "METRICS_ALLOWED_NETWORKS": {
  373. ParsedStringList: []string{"127.0.0.1/8"},
  374. RawValue: "127.0.0.1/8",
  375. ValueType: stringListType,
  376. },
  377. "METRICS_COLLECTOR": {
  378. ParsedBoolValue: false,
  379. RawValue: "0",
  380. ValueType: boolType,
  381. },
  382. "METRICS_PASSWORD": {
  383. ParsedStringValue: "",
  384. RawValue: "",
  385. ValueType: stringType,
  386. Secret: true,
  387. },
  388. "METRICS_PASSWORD_FILE": {
  389. ParsedStringValue: "",
  390. RawValue: "",
  391. ValueType: secretFileType,
  392. TargetKey: "METRICS_PASSWORD",
  393. },
  394. "METRICS_REFRESH_INTERVAL": {
  395. ParsedDuration: 60 * time.Second,
  396. RawValue: "60",
  397. ValueType: secondType,
  398. Validator: func(rawValue string) error {
  399. return validateGreaterOrEqualThan(rawValue, 1)
  400. },
  401. },
  402. "METRICS_USERNAME": {
  403. ParsedStringValue: "",
  404. RawValue: "",
  405. ValueType: stringType,
  406. },
  407. "METRICS_USERNAME_FILE": {
  408. ParsedStringValue: "",
  409. RawValue: "",
  410. ValueType: secretFileType,
  411. TargetKey: "METRICS_USERNAME",
  412. },
  413. "OAUTH2_CLIENT_ID": {
  414. ParsedStringValue: "",
  415. RawValue: "",
  416. ValueType: stringType,
  417. Secret: true,
  418. },
  419. "OAUTH2_CLIENT_ID_FILE": {
  420. ParsedStringValue: "",
  421. RawValue: "",
  422. ValueType: secretFileType,
  423. TargetKey: "OAUTH2_CLIENT_ID",
  424. },
  425. "OAUTH2_CLIENT_SECRET": {
  426. ParsedStringValue: "",
  427. RawValue: "",
  428. ValueType: stringType,
  429. Secret: true,
  430. },
  431. "OAUTH2_CLIENT_SECRET_FILE": {
  432. ParsedStringValue: "",
  433. RawValue: "",
  434. ValueType: secretFileType,
  435. TargetKey: "OAUTH2_CLIENT_SECRET",
  436. },
  437. "OAUTH2_OIDC_DISCOVERY_ENDPOINT": {
  438. ParsedStringValue: "",
  439. RawValue: "",
  440. ValueType: stringType,
  441. },
  442. "OAUTH2_OIDC_PROVIDER_NAME": {
  443. ParsedStringValue: "OpenID Connect",
  444. RawValue: "OpenID Connect",
  445. ValueType: stringType,
  446. },
  447. "OAUTH2_PROVIDER": {
  448. ParsedStringValue: "",
  449. RawValue: "",
  450. ValueType: stringType,
  451. Validator: func(rawValue string) error {
  452. return validateChoices(rawValue, []string{"oidc", "google"})
  453. },
  454. },
  455. "OAUTH2_REDIRECT_URL": {
  456. ParsedStringValue: "",
  457. RawValue: "",
  458. ValueType: stringType,
  459. },
  460. "OAUTH2_USER_CREATION": {
  461. ParsedBoolValue: false,
  462. RawValue: "0",
  463. ValueType: boolType,
  464. },
  465. "POLLING_FREQUENCY": {
  466. ParsedDuration: 60 * time.Minute,
  467. RawValue: "60",
  468. ValueType: minuteType,
  469. Validator: func(rawValue string) error {
  470. return validateGreaterOrEqualThan(rawValue, 1)
  471. },
  472. },
  473. "POLLING_LIMIT_PER_HOST": {
  474. ParsedIntValue: 0,
  475. RawValue: "0",
  476. ValueType: intType,
  477. Validator: func(rawValue string) error {
  478. return validateGreaterOrEqualThan(rawValue, 0)
  479. },
  480. },
  481. "POLLING_PARSING_ERROR_LIMIT": {
  482. ParsedIntValue: 3,
  483. RawValue: "3",
  484. ValueType: intType,
  485. Validator: func(rawValue string) error {
  486. return validateGreaterOrEqualThan(rawValue, 0)
  487. },
  488. },
  489. "POLLING_SCHEDULER": {
  490. ParsedStringValue: "round_robin",
  491. RawValue: "round_robin",
  492. ValueType: stringType,
  493. Validator: func(rawValue string) error {
  494. return validateChoices(rawValue, []string{"round_robin", "entry_frequency"})
  495. },
  496. },
  497. "PORT": {
  498. ParsedStringValue: "",
  499. RawValue: "",
  500. ValueType: stringType,
  501. Validator: func(rawValue string) error {
  502. return validateRange(rawValue, 1, 65535)
  503. },
  504. },
  505. "RUN_MIGRATIONS": {
  506. ParsedBoolValue: false,
  507. RawValue: "0",
  508. ValueType: boolType,
  509. },
  510. "SCHEDULER_ENTRY_FREQUENCY_FACTOR": {
  511. ParsedIntValue: 1,
  512. RawValue: "1",
  513. ValueType: intType,
  514. },
  515. "SCHEDULER_ENTRY_FREQUENCY_MAX_INTERVAL": {
  516. ParsedDuration: 24 * time.Hour,
  517. RawValue: "1440",
  518. ValueType: minuteType,
  519. Validator: func(rawValue string) error {
  520. return validateGreaterOrEqualThan(rawValue, 1)
  521. },
  522. },
  523. "SCHEDULER_ENTRY_FREQUENCY_MIN_INTERVAL": {
  524. ParsedDuration: 5 * time.Minute,
  525. RawValue: "5",
  526. ValueType: minuteType,
  527. Validator: func(rawValue string) error {
  528. return validateGreaterOrEqualThan(rawValue, 1)
  529. },
  530. },
  531. "SCHEDULER_ROUND_ROBIN_MAX_INTERVAL": {
  532. ParsedDuration: 1440 * time.Minute,
  533. RawValue: "1440",
  534. ValueType: minuteType,
  535. Validator: func(rawValue string) error {
  536. return validateGreaterOrEqualThan(rawValue, 1)
  537. },
  538. },
  539. "SCHEDULER_ROUND_ROBIN_MIN_INTERVAL": {
  540. ParsedDuration: 60 * time.Minute,
  541. RawValue: "60",
  542. ValueType: minuteType,
  543. Validator: func(rawValue string) error {
  544. return validateGreaterOrEqualThan(rawValue, 1)
  545. },
  546. },
  547. "WATCHDOG": {
  548. ParsedBoolValue: true,
  549. RawValue: "1",
  550. ValueType: boolType,
  551. },
  552. "WEBAUTHN": {
  553. ParsedBoolValue: false,
  554. RawValue: "0",
  555. ValueType: boolType,
  556. },
  557. "WEB_BOT_AUTH": {
  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) HasHTTPService() bool {
  678. return !c.options["DISABLE_HTTP_SERVICE"].ParsedBoolValue
  679. }
  680. func (c *configOptions) HasHSTS() bool {
  681. return !c.options["DISABLE_HSTS"].ParsedBoolValue
  682. }
  683. func (c *configOptions) HasHTTPClientProxyURLConfigured() bool {
  684. return c.options["HTTP_CLIENT_PROXY"].ParsedURLValue != nil
  685. }
  686. func (c *configOptions) HasMaintenanceMode() bool {
  687. return c.options["MAINTENANCE_MODE"].ParsedBoolValue
  688. }
  689. func (c *configOptions) HasMetricsCollector() bool {
  690. return c.options["METRICS_COLLECTOR"].ParsedBoolValue
  691. }
  692. func (c *configOptions) HasSchedulerService() bool {
  693. return !c.options["DISABLE_SCHEDULER_SERVICE"].ParsedBoolValue
  694. }
  695. func (c *configOptions) HasWatchdog() bool {
  696. return c.options["WATCHDOG"].ParsedBoolValue
  697. }
  698. func (c *configOptions) HTTPClientMaxBodySize() int64 {
  699. return c.options["HTTP_CLIENT_MAX_BODY_SIZE"].ParsedInt64Value * 1024 * 1024
  700. }
  701. func (c *configOptions) HTTPClientProxies() []string {
  702. return c.options["HTTP_CLIENT_PROXIES"].ParsedStringList
  703. }
  704. func (c *configOptions) HTTPClientProxyURL() *url.URL {
  705. return c.options["HTTP_CLIENT_PROXY"].ParsedURLValue
  706. }
  707. func (c *configOptions) HTTPClientTimeout() time.Duration {
  708. return c.options["HTTP_CLIENT_TIMEOUT"].ParsedDuration
  709. }
  710. func (c *configOptions) HTTPClientUserAgent() string {
  711. if c.options["HTTP_CLIENT_USER_AGENT"].ParsedStringValue != "" {
  712. return c.options["HTTP_CLIENT_USER_AGENT"].ParsedStringValue
  713. }
  714. return defaultHTTPClientUserAgent
  715. }
  716. func (c *configOptions) HTTPServerTimeout() time.Duration {
  717. return c.options["HTTP_SERVER_TIMEOUT"].ParsedDuration
  718. }
  719. func (c *configOptions) HTTPS() bool {
  720. return c.options["HTTPS"].ParsedBoolValue
  721. }
  722. func (c *configOptions) InvidiousInstance() string {
  723. return c.options["INVIDIOUS_INSTANCE"].ParsedStringValue
  724. }
  725. func (c *configOptions) IsAuthProxyUserCreationAllowed() bool {
  726. return c.options["AUTH_PROXY_USER_CREATION"].ParsedBoolValue
  727. }
  728. func (c *configOptions) IsDefaultDatabaseURL() bool {
  729. return c.options["DATABASE_URL"].RawValue == "user=postgres password=postgres dbname=miniflux2 sslmode=disable"
  730. }
  731. func (c *configOptions) IsOAuth2UserCreationAllowed() bool {
  732. return c.options["OAUTH2_USER_CREATION"].ParsedBoolValue
  733. }
  734. func (c *configOptions) CertKeyFile() string {
  735. return c.options["KEY_FILE"].ParsedStringValue
  736. }
  737. func (c *configOptions) ListenAddr() []string {
  738. return c.options["LISTEN_ADDR"].ParsedStringList
  739. }
  740. func (c *configOptions) LogFile() string {
  741. return c.options["LOG_FILE"].ParsedStringValue
  742. }
  743. func (c *configOptions) LogDateTime() bool {
  744. return c.options["LOG_DATE_TIME"].ParsedBoolValue
  745. }
  746. func (c *configOptions) LogFormat() string {
  747. return c.options["LOG_FORMAT"].ParsedStringValue
  748. }
  749. func (c *configOptions) LogLevel() string {
  750. return c.options["LOG_LEVEL"].ParsedStringValue
  751. }
  752. func (c *configOptions) MaintenanceMessage() string {
  753. return c.options["MAINTENANCE_MESSAGE"].ParsedStringValue
  754. }
  755. func (c *configOptions) MaintenanceMode() bool {
  756. return c.options["MAINTENANCE_MODE"].ParsedBoolValue
  757. }
  758. func (c *configOptions) MediaCustomProxyURL() *url.URL {
  759. return c.options["MEDIA_PROXY_CUSTOM_URL"].ParsedURLValue
  760. }
  761. func (c *configOptions) MediaProxyHTTPClientTimeout() time.Duration {
  762. return c.options["MEDIA_PROXY_HTTP_CLIENT_TIMEOUT"].ParsedDuration
  763. }
  764. func (c *configOptions) MediaProxyMode() string {
  765. return c.options["MEDIA_PROXY_MODE"].ParsedStringValue
  766. }
  767. func (c *configOptions) MediaProxyPrivateKey() []byte {
  768. return c.options["MEDIA_PROXY_PRIVATE_KEY"].ParsedBytesValue
  769. }
  770. func (c *configOptions) MediaProxyResourceTypes() []string {
  771. return c.options["MEDIA_PROXY_RESOURCE_TYPES"].ParsedStringList
  772. }
  773. func (c *configOptions) MetricsAllowedNetworks() []string {
  774. return c.options["METRICS_ALLOWED_NETWORKS"].ParsedStringList
  775. }
  776. func (c *configOptions) MetricsCollector() bool {
  777. return c.options["METRICS_COLLECTOR"].ParsedBoolValue
  778. }
  779. func (c *configOptions) MetricsPassword() string {
  780. return c.options["METRICS_PASSWORD"].ParsedStringValue
  781. }
  782. func (c *configOptions) MetricsRefreshInterval() time.Duration {
  783. return c.options["METRICS_REFRESH_INTERVAL"].ParsedDuration
  784. }
  785. func (c *configOptions) MetricsUsername() string {
  786. return c.options["METRICS_USERNAME"].ParsedStringValue
  787. }
  788. func (c *configOptions) OAuth2ClientID() string {
  789. return c.options["OAUTH2_CLIENT_ID"].ParsedStringValue
  790. }
  791. func (c *configOptions) OAuth2ClientSecret() string {
  792. return c.options["OAUTH2_CLIENT_SECRET"].ParsedStringValue
  793. }
  794. func (c *configOptions) OAuth2OIDCDiscoveryEndpoint() string {
  795. return c.options["OAUTH2_OIDC_DISCOVERY_ENDPOINT"].ParsedStringValue
  796. }
  797. func (c *configOptions) OAuth2OIDCProviderName() string {
  798. return c.options["OAUTH2_OIDC_PROVIDER_NAME"].ParsedStringValue
  799. }
  800. func (c *configOptions) OAuth2Provider() string {
  801. return c.options["OAUTH2_PROVIDER"].ParsedStringValue
  802. }
  803. func (c *configOptions) OAuth2RedirectURL() string {
  804. return c.options["OAUTH2_REDIRECT_URL"].ParsedStringValue
  805. }
  806. func (c *configOptions) OAuth2UserCreation() bool {
  807. return c.options["OAUTH2_USER_CREATION"].ParsedBoolValue
  808. }
  809. func (c *configOptions) PollingFrequency() time.Duration {
  810. return c.options["POLLING_FREQUENCY"].ParsedDuration
  811. }
  812. func (c *configOptions) PollingLimitPerHost() int {
  813. return c.options["POLLING_LIMIT_PER_HOST"].ParsedIntValue
  814. }
  815. func (c *configOptions) PollingParsingErrorLimit() int {
  816. return c.options["POLLING_PARSING_ERROR_LIMIT"].ParsedIntValue
  817. }
  818. func (c *configOptions) PollingScheduler() string {
  819. return c.options["POLLING_SCHEDULER"].ParsedStringValue
  820. }
  821. func (c *configOptions) Port() string {
  822. return c.options["PORT"].ParsedStringValue
  823. }
  824. func (c *configOptions) RunMigrations() bool {
  825. return c.options["RUN_MIGRATIONS"].ParsedBoolValue
  826. }
  827. func (c *configOptions) SetLogLevel(level string) {
  828. c.options["LOG_LEVEL"].ParsedStringValue = level
  829. c.options["LOG_LEVEL"].RawValue = level
  830. }
  831. func (c *configOptions) SetHTTPSValue(value bool) {
  832. c.options["HTTPS"].ParsedBoolValue = value
  833. if value {
  834. c.options["HTTPS"].RawValue = "1"
  835. } else {
  836. c.options["HTTPS"].RawValue = "0"
  837. }
  838. }
  839. func (c *configOptions) SchedulerEntryFrequencyFactor() int {
  840. return c.options["SCHEDULER_ENTRY_FREQUENCY_FACTOR"].ParsedIntValue
  841. }
  842. func (c *configOptions) SchedulerEntryFrequencyMaxInterval() time.Duration {
  843. return c.options["SCHEDULER_ENTRY_FREQUENCY_MAX_INTERVAL"].ParsedDuration
  844. }
  845. func (c *configOptions) SchedulerEntryFrequencyMinInterval() time.Duration {
  846. return c.options["SCHEDULER_ENTRY_FREQUENCY_MIN_INTERVAL"].ParsedDuration
  847. }
  848. func (c *configOptions) SchedulerRoundRobinMaxInterval() time.Duration {
  849. return c.options["SCHEDULER_ROUND_ROBIN_MAX_INTERVAL"].ParsedDuration
  850. }
  851. func (c *configOptions) SchedulerRoundRobinMinInterval() time.Duration {
  852. return c.options["SCHEDULER_ROUND_ROBIN_MIN_INTERVAL"].ParsedDuration
  853. }
  854. func (c *configOptions) Watchdog() bool {
  855. return c.options["WATCHDOG"].ParsedBoolValue
  856. }
  857. func (c *configOptions) WebAuthn() bool {
  858. return c.options["WEBAUTHN"].ParsedBoolValue
  859. }
  860. func (c *configOptions) WebBotAuth() bool {
  861. return c.options["WEB_BOT_AUTH"].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. }