config.rs (2186B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2026 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 use std::time::Duration; 18 19 use compact_str::CompactString; 20 use taler_api::{Serve, config::DbCfg}; 21 use taler_common::config::{Config, ValueErr}; 22 23 pub fn parse_db_cfg(cfg: &Config) -> Result<DbCfg, ValueErr> { 24 DbCfg::parse(cfg.section("apns-relaydb-postgres")) 25 } 26 27 /// taler-apns-relay httpd config 28 pub struct ServeCfg { 29 pub serve: Serve, 30 } 31 32 impl ServeCfg { 33 pub fn parse(cfg: &Config) -> Result<Self, ValueErr> { 34 let sect = cfg.section("apns-relay-httpd"); 35 36 let serve = Serve::parse(sect)?; 37 38 Ok(Self { serve }) 39 } 40 } 41 42 pub struct ApnsConfig { 43 pub key_path: String, 44 pub key_id: CompactString, 45 pub team_id: CompactString, 46 pub bundle_id: CompactString, 47 } 48 49 impl ApnsConfig { 50 pub fn parse(cfg: &Config) -> Result<Self, ValueErr> { 51 let sect = cfg.section("apns-relay-worker"); 52 Ok(Self { 53 key_path: sect.path("key_file").require()?, 54 key_id: sect.cstr("key_id").require()?, 55 team_id: sect.cstr("team_id").require()?, 56 bundle_id: sect.cstr("bundle_id").require()?, 57 }) 58 } 59 } 60 61 /// taler-apns-relay worker config 62 pub struct WorkerCfg { 63 pub apns: ApnsConfig, 64 pub frequency: Duration, 65 } 66 67 impl WorkerCfg { 68 pub fn parse(cfg: &Config) -> Result<Self, ValueErr> { 69 let sect = cfg.section("apns-relay-worker"); 70 Ok(Self { 71 apns: ApnsConfig::parse(cfg)?, 72 frequency: sect.duration("frequency").require()?, 73 }) 74 } 75 }