taler-rust

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

lib.rs (1675B)


      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 anyhow::bail;
     18 use sqlx::PgPool;
     19 use taler_common::config::Config;
     20 use tracing::info;
     21 
     22 use crate::{
     23     apns::{ApnsError, Client, Reason},
     24     config::ApnsConfig,
     25 };
     26 
     27 pub mod api;
     28 pub mod apns;
     29 pub mod config;
     30 pub mod constants;
     31 pub mod db;
     32 pub mod worker;
     33 pub use crate::constants::CONFIG_SOURCE;
     34 
     35 pub async fn setup(cfg: &Config, pool: &PgPool, reset: bool) -> anyhow::Result<()> {
     36     let apns_cfg = ApnsConfig::parse(cfg)?;
     37 
     38     info!(target: "setup", "Check API access and configuration");
     39     let mut client = Client::new(&apns_cfg)?;
     40     let res = client.send("00").await.expect_err("Should fail");
     41 
     42     if !matches!(
     43         res,
     44         ApnsError::Err {
     45             reason: Reason::BadDeviceToken,
     46             timestamp: None
     47         }
     48     ) {
     49         bail!("{res}")
     50     }
     51 
     52     if reset {
     53         info!(target: "setup", "Clear registration");
     54         db::clear_registration(pool).await?;
     55     }
     56 
     57     info!(target: "setup", "Setup finished");
     58     Ok(())
     59 }