taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

config.rs (2758B)


      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::{
     22     config::{CfgErr, Config},
     23     map_config,
     24 };
     25 
     26 pub fn parse_db_cfg(cfg: &Config) -> Result<DbCfg, CfgErr> {
     27     DbCfg::parse(cfg.section("apns-relaydb-postgres"))
     28 }
     29 
     30 /// taler-apns-relay httpd config
     31 pub struct ServeCfg {
     32     pub serve: Serve,
     33 }
     34 
     35 impl ServeCfg {
     36     pub fn parse(cfg: &Config) -> Result<Self, CfgErr> {
     37         let s = cfg.section("apns-relay-httpd");
     38 
     39         let serve = Serve::parse(&s)?;
     40 
     41         Ok(Self { serve })
     42     }
     43 }
     44 
     45 #[derive(Debug, Clone, Copy)]
     46 pub enum ApnsServer {
     47     Production,
     48     Sandbox,
     49 }
     50 
     51 impl ApnsServer {
     52     pub fn host(self) -> &'static str {
     53         match self {
     54             Self::Production => "api.push.apple.com",
     55             Self::Sandbox => "api.sandbox.push.apple.com",
     56         }
     57     }
     58 }
     59 
     60 pub struct ApnsConfig {
     61     pub server: ApnsServer,
     62     pub key_path: String,
     63     pub key_id: CompactString,
     64     pub team_id: CompactString,
     65     pub bundle_id: CompactString,
     66 }
     67 
     68 impl ApnsConfig {
     69     pub fn parse(cfg: &Config) -> Result<Self, CfgErr> {
     70         let sect = cfg.section("apns-relay-worker");
     71         Ok(Self {
     72             server: map_config!(&sect, "APNs server", "server",
     73                 "production" => { ApnsServer::Production },
     74                 "sandbox" => { ApnsServer::Sandbox },
     75             )
     76             .default(ApnsServer::Production)?,
     77             key_path: sect.path("key_file").require()?,
     78             key_id: sect.cstr("key_id").require()?,
     79             team_id: sect.cstr("team_id").require()?,
     80             bundle_id: sect.cstr("bundle_id").require()?,
     81         })
     82     }
     83 }
     84 
     85 /// taler-apns-relay worker config
     86 pub struct WorkerCfg {
     87     pub apns: ApnsConfig,
     88     pub frequency: Duration,
     89 }
     90 
     91 impl WorkerCfg {
     92     pub fn parse(cfg: &Config) -> Result<Self, CfgErr> {
     93         let sect = cfg.section("apns-relay-worker");
     94         Ok(Self {
     95             apns: ApnsConfig::parse(cfg)?,
     96             frequency: sect.duration("frequency").require()?,
     97         })
     98     }
     99 }