lib.rs (1717B)
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 41 .send("test_device_token") 42 .await 43 .expect_err("Should fail"); 44 45 if !matches!( 46 res, 47 ApnsError::Err { 48 reason: Reason::BadDeviceToken, 49 timestamp: None 50 } 51 ) { 52 bail!("{res}") 53 } 54 55 if reset { 56 info!(target: "setup", "Clear registration"); 57 db::clear_registration(pool).await?; 58 } 59 60 info!(target: "setup", "Setup finished"); 61 Ok(()) 62 }