mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 21:28:21 +00:00
feat(backend-api): Add DnsRecord types and queries
This commit is contained in:
@@ -816,6 +816,72 @@ pub async fn get_app_logs_paginated(
|
||||
})
|
||||
}
|
||||
|
||||
/// Retrieve a domain by its name.
|
||||
///
|
||||
/// Specify with_records to also retrieve all records for the domain.
|
||||
pub async fn get_domain(
|
||||
client: &WasmerClient,
|
||||
domain: String,
|
||||
) -> Result<Option<types::DnsDomainWithRecords>, anyhow::Error> {
|
||||
let vars = types::GetDomainVars { domain };
|
||||
|
||||
let opt = client
|
||||
.run_graphql(types::GetDomainWithRecords::build(vars))
|
||||
.await
|
||||
.map_err(anyhow::Error::from)?
|
||||
.get_domain;
|
||||
Ok(opt)
|
||||
}
|
||||
|
||||
/// Retrieve all DNS records.
|
||||
///
|
||||
/// NOTE: this is a privileged operation that requires extra permissions.
|
||||
pub async fn get_all_dns_records(
|
||||
client: &WasmerClient,
|
||||
vars: types::GetAllDnsRecordsVariables,
|
||||
) -> Result<types::DnsRecordConnection, anyhow::Error> {
|
||||
client
|
||||
.run_graphql_strict(types::GetAllDnsRecords::build(vars))
|
||||
.await
|
||||
.map_err(anyhow::Error::from)
|
||||
.map(|x| x.get_all_dnsrecords)
|
||||
}
|
||||
|
||||
/// Retrieve a domain by its name.
|
||||
///
|
||||
/// Specify with_records to also retrieve all records for the domain.
|
||||
pub fn get_all_dns_records_stream(
|
||||
client: &WasmerClient,
|
||||
vars: types::GetAllDnsRecordsVariables,
|
||||
) -> impl futures::Stream<Item = Result<Vec<types::DnsRecord>, anyhow::Error>> + '_ {
|
||||
futures::stream::try_unfold(
|
||||
Some(vars),
|
||||
move |vars: Option<types::GetAllDnsRecordsVariables>| async move {
|
||||
let vars = match vars {
|
||||
Some(vars) => vars,
|
||||
None => return Ok(None),
|
||||
};
|
||||
|
||||
let page = get_all_dns_records(client, vars.clone()).await?;
|
||||
|
||||
let end_cursor = page.page_info.end_cursor;
|
||||
|
||||
let items = page
|
||||
.edges
|
||||
.into_iter()
|
||||
.filter_map(|x| x.and_then(|x| x.node))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let new_vars = end_cursor.map(|c| types::GetAllDnsRecordsVariables {
|
||||
after: Some(c),
|
||||
..vars
|
||||
});
|
||||
|
||||
Ok(Some((items, new_vars)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Convert a [`OffsetDateTime`] to a unix timestamp that the WAPM backend
|
||||
/// understands.
|
||||
fn unix_timestamp(ts: OffsetDateTime) -> f64 {
|
||||
|
||||
Reference in New Issue
Block a user