Skip to content

Commit

Permalink
make lint fixes & improvements to code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
ayys committed Mar 15, 2024
1 parent ac0e0c5 commit df0ee74
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 38 deletions.
31 changes: 16 additions & 15 deletions lib/backend-api/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,12 +883,19 @@ pub async fn get_all_dns_records(
pub async fn get_all_domains(
client: &WasmerClient,
vars: types::GetAllDomainsVariables,
) -> Result<types::DnsDomainConnection, anyhow::Error> {
client
) -> Result<Vec<DnsDomain>, anyhow::Error> {
let connection = client
.run_graphql_strict(types::GetAllDomains::build(vars))
.await
.map_err(anyhow::Error::from)
.map(|x| x.get_all_domains)
.context("no domains returned")?;
Ok(connection
.edges
.into_iter()
.flatten()
.filter_map(|x| x.node)
.collect())
}

/// Retrieve a domain by its name.
Expand Down Expand Up @@ -948,19 +955,13 @@ pub async fn upsert_domain_from_zone_file(
delete_missing_records: Some(delete_missing_records),
};
let res = client
.run_graphql_raw(types::UpsertDomainFromZoneFile::build(vars))
.run_graphql_strict(types::UpsertDomainFromZoneFile::build(vars))
.await?;

if let Some(domain) = res
.data
.and_then(|d| d.upsert_domain_from_zone_file)
.map(|d| d.domain)
{
Ok(domain)
} else {
Err(GraphQLApiFailure::from_errors(
"could not sync zone file",
res.errors,
))
}
let domain = res
.upsert_domain_from_zone_file
.context("Upserting domain from zonefile failed")?
.domain;

Ok(domain)
}
2 changes: 1 addition & 1 deletion lib/cli/src/commands/domain/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl AsyncCliCommand for CmdDomainGet {
{
println!("{}", self.fmt.format.render(&domain));
} else {
println!("Domain not found");
anyhow::bail!("Domain not found");
}
Ok(())
}
Expand Down
11 changes: 1 addition & 10 deletions lib/cli/src/commands/domain/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl AsyncCliCommand for CmdDomainList {

async fn run_async(self) -> Result<(), anyhow::Error> {
let client = self.api.client()?;
let domains_connection = wasmer_api::query::get_all_domains(
let domains = wasmer_api::query::get_all_domains(
&client,
GetAllDomainsVariables {
first: None,
Expand All @@ -32,15 +32,6 @@ impl AsyncCliCommand for CmdDomainList {
},
)
.await?;
let domains = domains_connection
.edges
.into_iter()
.map(|edge| {
edge.expect("domain not found")
.node
.expect("domain not found")
})
.collect::<Vec<_>>();
println!("{}", self.fmt.format.render(&domains));
Ok(())
}
Expand Down
1 change: 0 additions & 1 deletion lib/cli/src/commands/domain/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod get;
pub mod list;
pub mod zonefile;

use crate::commands::AsyncCliCommand;

/// Manage DNS records
Expand Down
17 changes: 7 additions & 10 deletions lib/cli/src/commands/domain/zonefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
commands::AsyncCliCommand,
opts::{ApiOpts, ItemFormatOpts},
};
use anyhow::Context;

#[derive(clap::Parser, Debug)]
/// Show a zone file
Expand Down Expand Up @@ -30,12 +31,7 @@ pub struct CmdZoneFileSync {
zone_file_path: String,

/// Do not delete records that are not present in the zone file
#[clap(
short = 'n',
long = "no-delete-missing-records",
required = false,
default_value = "false"
)]
#[clap(short = 'n', long = "no-delete-missing-records")]
no_delete_missing_records: bool,
}

Expand All @@ -50,12 +46,13 @@ impl AsyncCliCommand for CmdZoneFileGet {
{
let zone_file_contents = domain.zone_file;
if let Some(zone_file_path) = self.zone_file_path {
std::fs::write(zone_file_path, zone_file_contents).expect("Unable to write file");
std::fs::write(zone_file_path, zone_file_contents)
.context("Unable to write file")?;
} else {
println!("{}", zone_file_contents);
}
} else {
println!("Domain not found");
anyhow::bail!("Domain not found");
}
Ok(())
}
Expand All @@ -66,8 +63,8 @@ impl AsyncCliCommand for CmdZoneFileSync {
type Output = ();

async fn run_async(self) -> Result<(), anyhow::Error> {
let data = std::fs::read(&self.zone_file_path).expect("Unable to read file");
let zone_file_contents = String::from_utf8(data).expect("Not a valid UTF-8 sequence");
let data = std::fs::read(&self.zone_file_path).context("Unable to read file")?;
let zone_file_contents = String::from_utf8(data).context("Not a valid UTF-8 sequence")?;
let domain = wasmer_api::query::upsert_domain_from_zone_file(
&self.api.client()?,
zone_file_contents,
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl CliRender for DnsDomainWithRecords {
records.iter().flatten().for_each(|record| {
rows.push(vec![
record.record_type().to_string(),
record.name().expect("Expected record name").to_string(),
record.name().unwrap_or("<no name>").to_string(),
record
.ttl()
.expect("expected a TTL value for record")
Expand Down

0 comments on commit df0ee74

Please sign in to comment.