mirror of
https://github.com/sadoyan/aralez.git
synced 2026-10-23 14:11:35 +08:00
Improved error handling, anti unwrap()-ing
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::tls::acme::lookup::lookup_wait;
|
||||
use crate::tls::acme::types::{DnsBackendPlugin, DnsProvider};
|
||||
use crate::utils::tools::Die;
|
||||
use log::info;
|
||||
use reqwest::Client;
|
||||
use serde_json::json;
|
||||
@@ -12,8 +13,8 @@ pub struct CloudflareProvider {
|
||||
|
||||
impl CloudflareProvider {
|
||||
pub fn new() -> Self {
|
||||
let api_token = std::env::var("CLOUDFLARE_API_TOKEN").expect("Environment variable CLOUDFLARE_API_TOKEN is required");
|
||||
let zone_id = std::env::var("CLOUDFLARE_ZONE_ID").expect("Environment variable CLOUDFLARE_ZONE_ID is required");
|
||||
let api_token = std::env::var("CLOUDFLARE_API_TOKEN").die("Environment variable CLOUDFLARE_API_TOKEN is required");
|
||||
let zone_id = std::env::var("CLOUDFLARE_ZONE_ID").die("Environment variable CLOUDFLARE_ZONE_ID is required");
|
||||
|
||||
Self {
|
||||
client: Client::new(),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::tls::acme::lookup::lookup_wait;
|
||||
use crate::tls::acme::types::{DnsBackendPlugin, DnsProvider};
|
||||
use crate::utils::tools::Die;
|
||||
use async_trait::async_trait;
|
||||
use log::info;
|
||||
use serde_json::json;
|
||||
@@ -12,7 +13,7 @@ pub struct DigitalOceanProvider {
|
||||
|
||||
impl DigitalOceanProvider {
|
||||
pub fn new() -> Self {
|
||||
let token = env::var("DIGITALOCEAN_TOKEN").expect("Environment variable DIGITALOCEAN_TOKEN is required");
|
||||
let token = env::var("DIGITALOCEAN_TOKEN").die("Environment variable DIGITALOCEAN_TOKEN is required");
|
||||
|
||||
Self {
|
||||
token,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
use crate::tls::acme::lookup::lookup_wait;
|
||||
use crate::tls::acme::types::{DnsBackendPlugin, DnsProvider};
|
||||
use aws_config::SdkConfig;
|
||||
use crate::utils::tools::Die;
|
||||
use aws_sdk_route53::Client;
|
||||
use aws_sdk_route53::types::{Change, ChangeAction, ChangeBatch, ResourceRecord, ResourceRecordSet, RrType};
|
||||
use log::info;
|
||||
@@ -17,13 +17,20 @@ pub struct Route53Provider {
|
||||
|
||||
impl Route53Provider {
|
||||
pub fn new() -> Self {
|
||||
let hosted_zone_id = std::env::var("AWS_HOSTED_ZONE_ID").expect("Environment variable AWS_HOSTED_ZONE_ID is required");
|
||||
// Load AWS SDK config synchronously using Tokio runtime handle to fit factory construction
|
||||
let config: SdkConfig = if let Ok(handle) = Handle::try_current() {
|
||||
tokio::task::block_in_place(|| handle.block_on(aws_config::load_from_env()))
|
||||
let hosted_zone_id = std::env::var("AWS_HOSTED_ZONE_ID").die("Environment variable AWS_HOSTED_ZONE_ID is required");
|
||||
|
||||
let config = if let Ok(handle) = Handle::try_current() {
|
||||
// If we're inside a tokio runtime, we can block on it directly
|
||||
handle.block_on(aws_config::load_from_env())
|
||||
} else {
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(aws_config::load_from_env())
|
||||
// If we're completely outside tokio, spin up a temporary current-thread runtime
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.die("Failed to create current-thread runtime")
|
||||
.block_on(aws_config::load_from_env())
|
||||
};
|
||||
|
||||
let client = Client::new(&config);
|
||||
Self { client, hosted_zone_id }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user