lib.rs (1676B)
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 34 pub async fn setup(cfg: &Config, pool: &PgPool, reset: bool) -> anyhow::Result<()> { 35 let apns_cfg = ApnsConfig::parse(cfg)?; 36 37 info!(target: "setup", "Check API access and configuration"); 38 let mut client = Client::new(&apns_cfg)?; 39 let res = client 40 .send("test_device_token") 41 .await 42 .expect_err("Should fail"); 43 44 if !matches!( 45 res, 46 ApnsError::Err { 47 reason: Reason::BadDeviceToken, 48 timestamp: None 49 } 50 ) { 51 bail!("{res}") 52 } 53 54 if reset { 55 info!(target: "setup", "Clear registration"); 56 db::clear_registration(pool).await?; 57 } 58 59 info!(target: "setup", "Setup finished"); 60 Ok(()) 61 }