options.go 28 KB

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