Skip to content

Commit

Permalink
Add subcommand wasmer domain register to register a new domain
Browse files Browse the repository at this point in the history
ayys committed Mar 18, 2024
1 parent df0ee74 commit a8ce010
Showing 4 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/backend-api/schema.graphql
Original file line number Diff line number Diff line change
@@ -3050,8 +3050,8 @@ type RegisterDomainPayload {

input RegisterDomainInput {
name: String!
namespace: String!
importRecords: Boolean = false
namespace: String
importRecords: Boolean = true
clientMutationId: String
}

23 changes: 23 additions & 0 deletions lib/backend-api/src/query.rs
Original file line number Diff line number Diff line change
@@ -865,6 +865,29 @@ pub async fn get_domain_with_records(
Ok(opt)
}

/// Register a new domain
pub async fn register_domain(
client: &WasmerClient,
domain: String,
namespace: Option<String>,
import_records: bool,
) -> Result<types::DnsDomain, anyhow::Error> {
let vars = types::RegisterDomainVars {
name: domain,
namespace,
import_records: Some(import_records),
};
let opt = client
.run_graphql_strict(types::RegisterDomain::build(vars))
.await
.map_err(anyhow::Error::from)?
.register_domain
.context("Domain registration failed")?
.domain
.context("Domain registration failed, no associatede domain found.")?;
Ok(opt)
}

/// Retrieve all DNS records.
///
/// NOTE: this is a privileged operation that requires extra permissions.
20 changes: 20 additions & 0 deletions lib/backend-api/src/types.rs
Original file line number Diff line number Diff line change
@@ -329,6 +329,26 @@ mod queries {
pub get_deploy_app_version: Option<DeployAppVersion>,
}

#[derive(cynic::QueryFragment, Debug)]
pub struct RegisterDomainPayload {
pub success: bool,
pub domain: Option<DnsDomain>,
}

#[derive(cynic::QueryVariables, Debug)]
pub struct RegisterDomainVars {
pub name: String,
pub namespace: Option<String>,
pub import_records: Option<bool>,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Mutation", variables = "RegisterDomainVars")]
pub struct RegisterDomain {
#[arguments(input: {name: $name, importRecords: $import_records, namespace: $namespace})]
pub register_domain: Option<RegisterDomainPayload>,
}

#[derive(cynic::QueryVariables, Debug)]
pub struct UpsertDomainFromZoneFileVars {
pub zone_file: String,
5 changes: 5 additions & 0 deletions lib/cli/src/commands/domain/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod get;
pub mod list;
pub mod register;
pub mod zonefile;
use crate::commands::AsyncCliCommand;

@@ -17,6 +18,9 @@ pub enum CmdDomain {

/// Sync local zone file with remotex
SyncZoneFile(self::zonefile::CmdZoneFileSync),

/// Register new domain
Register(self::register::CmdDomainRegister),
}

#[async_trait::async_trait]
@@ -29,6 +33,7 @@ impl AsyncCliCommand for CmdDomain {
CmdDomain::Get(cmd) => cmd.run_async().await,
CmdDomain::GetZoneFile(cmd) => cmd.run_async().await,
CmdDomain::SyncZoneFile(cmd) => cmd.run_async().await,
CmdDomain::Register(cmd) => cmd.run_async().await,
}
}
}

0 comments on commit a8ce010

Please sign in to comment.